Commits

Alex Hixon committed 273976f

Back to 0-180 range, since that's what the Servo library expects.

Comments (0)

Files changed (2)

controller/controller.pde

 */
 void read(unsigned int *data, int block)
 {
-    char vals[2];
-    int i = 0;
-    int temp = 0;
-    
+    int t = 0;
     if (block) {
-        // FIXME: add timeout
-        while (TRUE) {
-          if (Serial.available() > 0) {
-            vals[i] = Serial.read();
-            i++;
-            
-            if (i == 2) {
-              break;
-            }
-          }
-        }
+        while ((t = Serial.read()) == -1) { ;; }
     } else {
-        vals[0] = Serial.read();
-        vals[1] = Serial.read();
+        t = Serial.read();
     }
     
+    // since *data is unsigned, make sure no negatives
+    if (t < 0) {
+        t = 0;
+    }
     
-    *data = (vals[1] << 8) + vals[0];
-    Serial.println (*data);
+    *data = t;
 }
 
 // send response via serial
         if args is None:
             self.device.write (chr(msg))
         else:
-            a = struct.pack('<cH', chr(msg), args)
+            if args < 0 or args > 180:
+                raise ValueError, "argument must be between 0 and 180."
+            
+            a = struct.pack('<BB', msg, args)
             print "Writing:", a, "; length=", len(a)
             print "===="
             i = 0