Aegle / Mbed 2 deprecated Nucleo_BC127_DEBUG

Dependencies:   mbed

Revision:
1:9468a44a1815
Parent:
0:7df0c8b20953
Child:
2:38b75c9771fc
--- a/main.cpp	Sat Apr 25 21:45:42 2015 +0000
+++ b/main.cpp	Sun Apr 26 22:49:31 2015 +0000
@@ -35,29 +35,26 @@
 Serial pc(SERIAL_TX, SERIAL_RX);//pc(USBTX,USBRX); //tx,rx 
 
 // consider using "RawSerial" instead of "Serial" if/when transmitting char's
-//DigitalOut bt_pair(BC_VREGEN);
+DigitalOut bt_pair(PA_7);
 DigitalOut bt_reset(PA_9);
 DigitalOut rts(PA_8); //Bug, nets are swapped on the 5.02
 DigitalIn cts(PB_10); //Bug, nets are swapped on the 5.02
 Timer timeout;
 char responseBuff[4];
 char responseOk[4] = {'\r','\n','K','O'};
+bool BC127_confirm = false;
+
 
 bool bluetooth_command(string command){
-    bluetooth.printf("%s\r",command);
+    BC127_confirm=false;
     timeout.reset();
     timeout.start();
-    while(timeout.read_us()<2000){
-        if(bluetooth.readable()){
-         /*   for(int z=2;z>0;z--){
-                responseBuff[z+1]=responseBuff[z];
-            }
-            responseBuff[1]=responseBuff[0];
-            responseBuff[0]=bluetooth.getc();
-        }
-        if(memcmp(&command[0],&responseOk[0],4) == 0){
+    bluetooth.printf("%s\r",command);
+    while(timeout.read_ms()<2000){
+        if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
+            pc.printf("%dms/r",timeout.read_ms());
             timeout.stop();
-            return true;*/
+            return true;
         }    
     }
     timeout.stop();
@@ -76,9 +73,13 @@
     wait(0.5);
     bt_reset = 1;
     wait(0.5);
+    bt_pair =1;
+    wait(0.5);
+    bt_pair =0;
+    wait(0.5);
     bluetooth.baud(9600);
     wait(.1);
-    bluetooth.printf("SET NAME=ARC502RB\r");
+    /*bluetooth.printf("SET NAME=ARC502RB\r");
     wait(1.2);
     bluetooth.printf("SET NAME_SHORT=ARC5\r");
     wait(1.2);
@@ -91,7 +92,7 @@
     bluetooth.printf("WRITE\r");
     wait(1.2);
     bluetooth.printf("RESET\r");
-    wait(1);
+    wait(1);*/
     //bluetooth.set_flow_control(Serial::RTSCTS,rts,cts);
     //wait(.5);
     //bluetooth.printf("SET BAUD=115200\r");
@@ -103,22 +104,35 @@
 }
 void readResponse(){
     stm_led=!stm_led;
+    for(int z=2;z>0;z--){
+        responseBuff[z+1]=responseBuff[z];
+    }
+    responseBuff[1]=responseBuff[0];
+    responseBuff[0]=bluetooth.getc();
+    pc.putc(responseBuff[0]);
+    if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
+        pc.printf("YA/r/r");
+        BC127_confirm=true;
+    }    
 }
 int main() {
-    bool debug=true;
-    stm_led=1;
     bluetoothInitializer();
     bluetooth.attach(&readResponse);
-    
+    wait(5);
+    pc.printf("Starting\r");
+    bool debug=true;
+    stm_led=1;
     wait(1);
+    pc.printf("Atempting to send command\r");
     debug&=bluetooth_command("SET ENABLE_SPP=OFF");
+    //bluetooth.printf("SET ENABLE_SPP=OFF\r");
+    wait(2);
     //debug&=bluetooth_command("WRITE");
     //debug&=bluetooth_command("RESET");
-    if(debug){
-        ledBlink(2,100);
-    }else{
-        stm_led=0;
-    }
+    pc.printf("Finished sending command\r");
     while(1) {
+        if(debug){
+        stm_led=!stm_led;
+        }
     }
 }
\ No newline at end of file