The London Hackspace bandwidth meter

Dependencies:   LPD8806 MODSERIAL mbed picojson

See:

Files at this revision

API Documentation at this revision

Comitter:
Jasper
Date:
Sun Oct 21 11:27:45 2012 +0000
Parent:
7:68a26efc1d02
Commit message:
use MODSERIAL, fix the strip stuff

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Sun Oct 21 11:27:45 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODSERIAL/#5c45c21f36b7
--- 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;