Skip to content

Commit

Permalink
Weird serial fixes. UI cleanup. Graphing defaults on "on".
Browse files Browse the repository at this point in the history
  • Loading branch information
kitschpatrol committed Jan 18, 2014
1 parent a1e4f7c commit b3b347e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
29 changes: 22 additions & 7 deletions BrainGrapher.pde
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ void setup() {

// Set up serial connection
println("Find your Arduino in the list below, note its [index]:\n");
println(Serial.list());
serial = new Serial(this, Serial.list()[0], 9600);

for (int i = 0; i < Serial.list().length; i++) {
println("[" + i + "] " + Serial.list()[i]);
}

// Put the index found above here:
serial = new Serial(this, Serial.list()[5], 9600);
serial.bufferUntil(10);

// Set up the ControlP5 knobs and dials
Expand Down Expand Up @@ -78,7 +83,7 @@ void setup() {
graph = new Graph(0, 0, width, height / 2);

// Set yup the connection light
connectionLight = new ConnectionLight(width - 98, 10, 20);
connectionLight = new ConnectionLight(width - 105, 10, 20);
}

void draw() {
Expand Down Expand Up @@ -110,25 +115,35 @@ void draw() {
void serialEvent(Serial p) {
// Split incoming packet on commas
// See https://github.com/kitschpatrol/Arduino-Brain-Library/blob/master/README for information on the CSV packet format
String[] incomingValues = split(p.readString(), ',');

String incomingString = p.readString().trim();
print("Received string over serial: ");
println(incomingString);

String[] incomingValues = split(incomingString, ',');

// Verify that the packet looks legit
if (incomingValues.length > 1) {
packetCount++;

// Wait till the third packet or so to start recording to avoid initialization garbage.
if (packetCount > 3) {

for (int i = 0; i < incomingValues.length; i++) {
int newValue = Integer.parseInt(incomingValues[i].trim());
String stringValue = incomingValues[i].trim();

int newValue = Integer.parseInt(stringValue);

// Zero the EEG power values if we don't have a signal.
// Can be useful to leave them in for development.
if ((Integer.parseInt(incomingValues[0]) == 200) && (i > 2)) newValue = 0;
if ((Integer.parseInt(incomingValues[0]) == 200) && (i > 2)) {
newValue = 0;
}

channels[i].addDataPoint(newValue);
}
}
}
}
}


Expand Down
12 changes: 6 additions & 6 deletions Monitor.pde
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class Monitor {
backgroundColor = color(255);

// Create GUI
showGraph = controlP5.addCheckBox("showGraph" + sourceChannel.name, x + 6, y + 18);
showGraph = controlP5.addCheckBox("showGraph" + sourceChannel.name, x + 16, y + 32);
showGraph.addItem("GRAPH" + sourceChannel.name, 0);
showGraph.activate(0);
showGraph.activate(1);
showGraph.setColorForeground(sourceChannel.drawColor);
showGraph.setColorActive(color(0));
showGraph.setColorBackground(color(180));
showGraph.setColorActive(color(180));
showGraph.setColorBackground(color(0));

toggle = showGraph.getItem(0);
toggle.setLabel("GRAPH");

label = new Textlabel(controlP5, sourceChannel.name.toUpperCase(), x + 2, y + 5);
label = new Textlabel(controlP5, sourceChannel.name.toUpperCase(), x + 12, y + 15);
label.setColorValue(0);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ class Monitor {

// Draw the checkbox matte
noStroke();
fill(255, 150);
fill(240, 150);
rect(10, 10, w - 20, 40);

popMatrix();
Expand Down

0 comments on commit b3b347e

Please sign in to comment.