Permalink
Browse files

cleanups, bigger buffer, start de-serializing the blink rules.

  • Loading branch information...
1 parent bb982f6 commit 7eb2341058dd2068ed3a0f43ecdbd10276effeff @eastein committed Nov 5, 2011
Showing with 9 additions and 15 deletions.
  1. +9 −13 arduino/chatlight/chatlight.pde
  2. +0 −2 serial_controller.py
@@ -41,7 +41,7 @@ bool pwm_state[USEPINS];
Blinker pwm;
-#define BUF_SIZE 32
+#define BUF_SIZE 64
#define MSG_SIZE 9
class CommandReceiver
@@ -75,7 +75,8 @@ public:
and then 1 byte that represents every preceding byte xor'd together
*/
- if (used >= MSG_SIZE + 3)
+ // keep going until there definitely isn't enough data to read.
+ while (used >= MSG_SIZE + 3)
{
bool ok = true;
@@ -91,15 +92,6 @@ public:
ok = ok && (buf[MSG_SIZE + 2] == xord);
- /*
- if (ok)
- {
- delay(500);
- consumed(used);
- return;
- }
- */
-
uint8_t ln;
uint16_t _pwm_on;
uint16_t _pwm_off;
@@ -117,16 +109,20 @@ public:
*((char*)(&_pwm_off) + 1) = buf[5];
*((char*)(&_pwm_off)) = buf[6];
+ *((char*)(&_blink_on) + 1) = buf[7];
+ *((char*)(&_blink_on)) = buf[8];
+ *((char*)(&_blink_off) + 1) = buf[9];
+ *((char*)(&_blink_off)) = buf[10];
+
pwm.pwm_on[ln] = _pwm_on;
pwm.pwm_off[ln] = _pwm_off;
consumed(MSG_SIZE + 3);
}
else
{
+ // throw away a byte to re-align
consumed(1);
- if (used == 0)
- delay(2200);
}
}
}
View
@@ -10,8 +10,6 @@ def wrap(s) :
xord ^= ord(msg[i + 1])
msg += chr(xord)
- print repr(msg)
-
return msg
def light_control_code(light, pwm_on, pwm_off, blink_on, blink_off) :

0 comments on commit 7eb2341

Please sign in to comment.