aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_halfcab.c16
-rw-r--r--src/esp/halfcab/halfcab.ino53
2 files changed, 32 insertions, 37 deletions
diff --git a/src/c_halfcab.c b/src/c_halfcab.c
index c6a7e81..68cd7d6 100644
--- a/src/c_halfcab.c
+++ b/src/c_halfcab.c
@@ -143,20 +143,16 @@ main
}
if (argc < 4) {
com[0] = 0xfe;
+ com[1] = 0x00;
+ com[2] = 0xaa;
+ com[3] = 0xaa;
i = 0;
while (i < NUM_LEDS * 3) {
- leds[i + 0] = 0x00;
- leds[i + 1] = 0xff;
- leds[i + 2] = 0x00;
- leds[i + 3] = 0xff;
- leds[i + 4] = 0x00;
- leds[i + 5] = 0x00;
-/* memset(leds + i, *com + 1, 3 * sizeof(unsigned char)); */
- i += 6;
+ memcpy(leds + i, com + 1, 3 * sizeof(unsigned char));
+ i += 3;
}
write(fd, &com, 1 * sizeof(unsigned char));
- (void)leds;
-/* write(fd, &leds, (NUM_LEDS * 3) * sizeof(unsigned char)); */
+ write(fd, &leds, (NUM_LEDS * 3) * sizeof(unsigned char));
} else {
com[0] = 0xff;
i = 1;
diff --git a/src/esp/halfcab/halfcab.ino b/src/esp/halfcab/halfcab.ino
index 58621db..f99393e 100644
--- a/src/esp/halfcab/halfcab.ino
+++ b/src/esp/halfcab/halfcab.ino
@@ -55,6 +55,15 @@
CRGB leds[NUM_LEDS];
+byte
+read_byte()
+{
+ while (Serial.available() <= 0) {
+ /* empty */
+ }
+ return (Serial.read());
+}
+
void
fill(CRGB color)
{
@@ -106,29 +115,20 @@ plain(void)
fill(color);
}
-// void
-// dynamic(void)
-// {
-// uint8_t i;
-//
-// i = 0;
-// while (i < NUM_LEDS) {
-// while (Serial.available() <= 0) {
-// /* empty */
-// }
-// leds[i].r = Serial.read();
-// while (Serial.available() <= 0) {
-// /* empty */
-// }
-// leds[i].g = Serial.read();
-// while (Serial.available() <= 0) {
-// /* empty */
-// }
-// leds[i].b = Serial.read();
-// i++;
-// }
-// FastLED.show();
-// }
+void
+dynamic(void)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < NUM_LEDS) {
+ leds[i].r = read_byte();
+ leds[i].g = read_byte();
+ leds[i].b = read_byte();
+ i++;
+ }
+ FastLED.show();
+}
void
setup(void)
@@ -147,13 +147,12 @@ loop(void)
uint8_t com;
com = 0;
- while (Serial.available() <= 0) {
- /* empty */
- }
- com = Serial.read();
+ com = read_byte();
if (com == 0xff) {
plain();
return;
+ } else if (com == 0xfe) {
+ dynamic();
} else {
fill(BLUE);
}