Masterman / Mbed 2 deprecated mbed_3pi_bluefruit

Dependencies:   m3piExpandedCommandSet mbed

Revision:
2:a73f6db7efef
Parent:
1:5fc064b4c942
Child:
3:add27c286be9
diff -r 5fc064b4c942 -r a73f6db7efef main.cpp
--- a/main.cpp	Sun May 27 22:06:26 2018 +0000
+++ b/main.cpp	Sun May 27 23:57:30 2018 +0000
@@ -3,7 +3,7 @@
 
 m3pi m3pi;
 
-Serial dev(p28,p27);
+RawSerial dev(p28,p27);
 DigitalOut led1(LED1);
 
 // default serial buffer length is 8 bytes
@@ -20,6 +20,14 @@
  * Wheel speeds are unsigned integers in the range of 0 (stop) to 255.
  */
 void process_cmd() {
+    /////////////////
+    m3pi.cls();
+    m3pi.locate(0,0);
+    // print the buffer contents as ASCII on the first line
+    m3pi.printf(str_buf);
+    m3pi.locate(0, 1);
+    ///////////////
+    
     char cmd = (char)rx_buf[0];
     int right = (int)rx_buf[1];
     int left = (int)rx_buf[2];
@@ -38,10 +46,7 @@
         } case 'b': {
             // return battery level as 8-character string repr of float
             sprintf(battery, "%f", m3pi.battery());
-            int len = strlen(battery);
-            for (int i = 0; i < len; i++) {
-                dev.putc(battery[i]);
-            }
+            dev.puts(battery);
             break;
         } case 's': {
             m3pi.stop();
@@ -70,8 +75,12 @@
     int i = 0;
     for (i=0; i < BUFF_LENGTH; i++) {
         // let buffer empty if it's not ready to be read yet
-        if (!dev.readable()) {
-            wait(0.1f);
+        int count = 0;
+        while (count <= 10) {
+            if (dev.readable())
+                break;
+            wait(0.01f);
+            count++;
         }
         
         // if still nothing to read after waiting, must have received
@@ -85,19 +94,6 @@
         str_buf[i] = (char)b;
     }
     
-    m3pi.cls();
-    m3pi.locate(0,0);
-    
-    // print the buffer contents as ASCII on the first line
-    m3pi.print(str_buf, i);
-    
-    m3pi.locate(0, 1);
-    
-    /*
-    // print the buffer length on the second line
-    sprintf(str, "%d", i);
-    m3pi.printf(str);
-    */
     process_cmd();
 }