Skip to content

Commit

Permalink
Fixed one issue - Processing was overrunning the Arduino's serial buf…
Browse files Browse the repository at this point in the history
…fers.

Right now it divides the input into 32-byte chunks and this seems to
alleviate the issue.
  • Loading branch information
Chris Hodapp authored and Chris Hodapp committed Sep 17, 2011
1 parent d2c2f55 commit 461a888
Showing 1 changed file with 24 additions and 9 deletions.
Expand Up @@ -89,9 +89,13 @@ void draw() {
// offset is in [0, lim-1]
int maskX = mirrorMask ? lim - x - 1 : x;
maskX = (maskX + offset) % lim;
int val = 255 * textMask[y][maskX];

byte mask1 = textMask[y][maskX];
int r = 255 * mask1;
int g = 255 * mask1;
int b = 90 * mask1;
//int val = 100;
display.pixels[linear] = color(val);
display.pixels[linear] = color(r, g, b);
}
}
display.updatePixels();
Expand All @@ -102,16 +106,16 @@ void draw() {
//tryClear();
//testFrame();
while (serialPort.available() > 0) {
delay(50);
delay(10);
byte[] msg = serialPort.readBytes();
System.out.printf("Incoming before a command? %s\n", new String(msg));
System.out.printf("flushing buffer...\n");
}
pushFrame(display);
delay(200);
delay(100);
//print("Test");
while (serialPort.available() > 0) {
delay(50);
delay(10);
byte[] msg = serialPort.readBytes();
System.out.printf("Incoming: %s\n", new String(msg));
System.out.printf("flushing buffer...\n");
Expand Down Expand Up @@ -172,11 +176,22 @@ void pushFrame(PImage img) {
}
}
try {
serialPort.output.write(cmd);
System.out.printf("Outgoing (%d bytes), hex: ", cmd.length);
for(int i = 0; i < cmd.length; ++i) {
System.out.printf("%x", cmd[i]);
int chunkSize = 32;
int offset = 0;
while (offset < cmd.length) {
int remaining = cmd.length - offset;
byte tmp[] = new byte[min(chunkSize, remaining)];
for(int i = 0; i < chunkSize && i < remaining; ++i) {
tmp[i] = cmd[offset + i];
}
serialPort.output.write(tmp);
System.out.printf("Outgoing (%d bytes), hex: ", tmp.length);
for(int i = 0; i < tmp.length; ++i) {
System.out.printf("%x", tmp[i]);
}
offset += chunkSize;
}

System.out.printf("\nASCII: %s", new String(cmd));
System.out.printf("\n");
} catch(IOException e) {
Expand Down

0 comments on commit 461a888

Please sign in to comment.