BLE_periferal

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
sink
Date:
Tue Aug 06 03:27:08 2019 +0000
Commit message:
BLE;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f152b8894d8f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 06 03:27:08 2019 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "string"
+Ticker timer;
+
+RawSerial BT(p13, p14, 115200);
+RawSerial pc(USBTX,USBRX,115200);
+bool Connected = 0;
+bool mldp_online = 0;
+string recv_str = "";
+
+void BT_recv(){
+    char bt_c = BT.getc();
+    if(bt_c == 'd') {
+        Connected = 1;
+        recv_str += bt_c;
+        }
+    if (Connected && bt_c == 'P') recv_str = "";
+    else recv_str += bt_c;
+}
+
+void set(){
+    wait(1.0);
+    BT.printf("+\r");
+    wait(0.5);
+    BT.printf("SF,1\r");
+    wait(0.5);
+    BT.printf("SR,32000000\r");
+    wait(0.5);
+    BT.printf("R,1\r");
+    wait(4.0);
+    BT.printf("A\r");
+}
+
+void timer_warikomi(){
+    static int time_co = 0; 
+    if(Connected && !mldp_online && time_co > 25) {
+        BT.printf("I\r");
+        mldp_online = 1;
+        pc.printf(recv_str.c_str());
+        pc.printf("MLDP_ONLINE\n");
+        recv_str = "";
+    }
+    else if (Connected && mldp_online){
+            BT.printf("Slave_on\n");
+            pc.printf(recv_str.c_str());
+            recv_str = "";
+    }
+    else {
+        pc.printf(recv_str.c_str());
+        time_co++;
+    }
+}
+
+int main() {
+    BT.attach(&BT_recv,RawSerial::RxIrq);
+    
+    set();
+    
+    timer.attach(&timer_warikomi,0.02);
+    while(1) {
+    }
+}
diff -r 000000000000 -r f152b8894d8f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 06 03:27:08 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file