-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.cpp
70 lines (51 loc) · 1.29 KB
/
host.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#if defined TEENSYDUINO || defined ARDUINO_AVR_NANO
#include "defines.h"
#include "host.h"
void host::reset() {
memset(buffer, 0, sizeof(buffer));
offset = 0;
}
void host::frame(pixelArray **strip, WII **wii) {
while (Serial.available()) {
//COMPLETELY RESET IF WE OVERFLOW THE BUFFER
if (offset >= sizeof(buffer)) return reset();
buffer[offset] = Serial.read();
//FLOOD WITH ZEROS TO RESET BUFFER
switch (buffer[offset]) {
case '\0':
case '\r':
case '\n':
case ';':
Serial.print(F("Command: "));
if (offset) {
int side=0, start=0, end=0, red=0, green=0, blue=0;
sscanf(
(char*)buffer,
"%d,%d,%d=%d,%d,%d",
&side, &start, &end,
&red, &green, &blue
);
start = min(max(start, 0), 299);
end = min(max(start, end), 299);
color_t color = color_t(red, green, blue);
Serial.print(side);
Serial.print(F(", "));
Serial.print(start);
Serial.print(F(", "));
Serial.print(end);
Serial.print(F(" = "));
Serial.print((uint32_t)color);
Serial.print(F("\n"));
for (int i=start; i<=end; i++) {
strip[side]->setPixelColor(i, color);
}
} else {
Serial.print(F("[NONE]\n"));
}
reset();
continue;
}
offset++;
}
}
#endif //TEENSYDUINO || ARDUINO_AVR_NANO