The London Hackspace bandwidth meter

Dependencies:   LPD8806 MODSERIAL mbed picojson

See:

Revision:
8:add24f73747b
Parent:
7:68a26efc1d02
--- a/main.cpp	Sun Oct 21 09:49:41 2012 +0000
+++ b/main.cpp	Sun Oct 21 11:27:45 2012 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "ctype.h"
 
+#include "MODSERIAL.h"
 #include "LPD8806.h"
 #include "vfd.h"
 
@@ -10,7 +11,7 @@
 DigitalOut led4(LED4);
 
 /* talk to the world */
-Serial pc(USBTX, USBRX);
+MODSERIAL pc(USBTX, USBRX);
 
 LPD8806 strip = LPD8806(32);
 
@@ -121,7 +122,7 @@
 
 int main() {
     
-    setbuf(stdout, NULL);
+//    setbuf(stdout, NULL);
 
     pc.printf("Hello!\r\n");
 
@@ -223,7 +224,7 @@
                         case Emf:
                             emf_blue();
                             changed = true;
-                            printf("emf_blue\r\n");
+                            pc.printf("emf_blue\r\n");
                             break;
                         case VfdReset:
                             vfd_reset();
@@ -245,16 +246,14 @@
                             break;
                         case SetStrip:
                             bufpos = 0;
-                            printf("SetStrip: %s\r\n", buf);
                             // buf[0] == t or b for strip
                             // next 48 chars == HHH rgb * 16
-                            int p, endp, r, g, b, poff=16;
-                            p = 0; endp = p + 16;
+                            int p, r, g, b, poff=0;
                             if (buf[0] == 'b') {
                                 poff = 16;
                             }
 
-                            for (;p < endp ; p ++) {
+                            for (p = 0;p < 16 ; p ++) {
                                 r = hex_char_to_int(buf[(p * 3) + 1]);
                                 g = hex_char_to_int(buf[(p * 3) + 2]);
                                 b = hex_char_to_int(buf[(p * 3) + 3]);
@@ -264,7 +263,7 @@
 
                             break;
                         default:
-                            printf("no command given\r\n");
+                            pc.printf("no command given\r\n");
                     }
                     state = Looking;
                     cmd = None;
@@ -274,7 +273,7 @@
                         tmp = (got - 48);
                         num = (num * 10) + tmp;
                     } else {
-                        printf("expected a number, got %c\r\n", got);
+                        pc.printf("expected a number, got %c\r\n", got);
                     }
                 } else if (state == String) {
                     if (bufpos < 127) {
@@ -282,7 +281,7 @@
                         bufpos++;
                         buf[bufpos] = '\0';
                     } else {
-                        printf("buffer full\r\n!");
+                        pc.printf("buffer full\r\n!");
                         // XXX state == None here?
                     }
                 }
@@ -290,7 +289,7 @@
         }
         if (changed)
         {
-            printf("changed\r\n");
+            pc.printf("changed\r\n");
             led1 = led1 ? 0 : 1;
             strip.show();
             changed = false;