Nikolas Goldin original creater of this. Added some of my own notes and also a few additional commands

Dependencies:   btbee m3pi_ng mbed

Fork of configure_btbee by Nikolas Goldin

Revision:
1:af0aa8d6e586
Parent:
0:e674a8b2b330
Child:
2:d0adbf94c4c0
diff -r e674a8b2b330 -r af0aa8d6e586 main.cpp
--- a/main.cpp	Thu May 16 12:13:17 2013 +0000
+++ b/main.cpp	Thu May 16 14:16:04 2013 +0000
@@ -1,78 +1,60 @@
 #include "mbed.h"
 #include "m3pi_ng.h"
-
+#include "btbee.h"
 
 m3pi m3pi;
+btbee btbee;
 
 DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)};
 DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)};
-DigitalIn m3pi_pb(p21);
-Timer t1;
-Serial btbee(p28, p27); // tx rx
-DigitalOut btbee_reset(p26);  // 0 resets the device
 
-int main (){
-    // initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////////
-    m3pi.locate(0,1);
-    btbee_reset=1;  // else it keeps resetting
+int main ()
+{
+// initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////////
     for (int i = 0; i <4; i++) {
         mbed_led[i] = 0;
     }
     for (int i = 0; i <8; i++) {
-        m3pi_led[i]=0;
+        m3pi_led[i] = 0;
     }
-    m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case
-    btbee.baud(38400);  // this is BtBee default for AT commands
-    //btbee.baud(9600);  // this is BtBee default for regular commands
-    //btbee.format();  // the default should be fine
-    // end initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////    
-
+    btbee.at_baud();
+// end initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////
+    m3pi.locate(0,1);
     m3pi.printf("ATSWITCH");
     m3pi.locate(0,0);
     m3pi.printf("RIGHT???");
-
     wait(0.1);
-    
     m3pi_led[0]=1;
 
-    //btbee.printf("at\r\n"); // test command, returns "OK\r\n"
-    //btbee.printf("at+uart=9600,0,0\r\n"); //default values, returns "OK\r\n"
-    //btbee.printf("at+uart=115200,0,0\r\n"); //changing the baud rate, returns "OK\r\n" 
+//btbee.printf("at\r\n"); // test command, returns "OK\r\n"
+//btbee.printf("at+uart=9600,0,0\r\n"); //default values, returns "OK\r\n"
+//btbee.printf("at+uart=115200,0,0\r\n"); //changing the baud rate, returns "OK\r\n"
     btbee.printf("at+uart?\r\n"); //asking for the set parameters, replies "+UART:baud,stop,parity\r\n"
 
     m3pi_led[1]=1;
 
-    char l1[30]; //array for the reply
- 
-    while (!btbee.readable()){  //wait for it
-    mbed_led[0]=!mbed_led[0];
-    wait(0.1);
+    while (!btbee.readable()) { //wait for reply
+        mbed_led[0]=!mbed_led[0];
+        wait(0.1);
     }
-    
-    /*
-    // abandoned. scanf is notorious and using getchar is recommended. i love c. 
-    int num;
-    num = btbee.scanf("%s/n",l1);
-    m3pi.printf("%i",num);
-    */
+
+    char reply_array[30];
+    int reply_length=0;
     
-    int pos = 0;
-    while (btbee.readable()){
-    l1[pos]=btbee.getc();
-    pos++;
-    }
     m3pi_led[2]=1;
-    
-    m3pi.cls();
+    btbee.read_all(reply_array, 30, &reply_length);
+    m3pi_led[3]=1;
+
     m3pi.locate(0,0);
-    if (pos<9){
-    m3pi.print(l1,pos);
+    m3pi.cls();
+    if (reply_length<9) {
+        m3pi.print(reply_array, reply_length);
+    } else {
+        m3pi.print(reply_array, 8);
+        m3pi.locate(0,1);
+        m3pi.print(reply_array+8, reply_length-8);
     }
-    else{
-    m3pi.print(l1,8);
-    m3pi.locate(0,1);
-    m3pi.print(l1+8,pos-8);
-    }
-    m3pi_led[3]=1;
-}
+    m3pi_led[4]=1;
 
+}//main
+