Datacollection on microbit with bluetooth uart transfer

Dependencies:   BLE_API mbed

Files at this revision

API Documentation at this revision

Comitter:
aziobro
Date:
Mon Feb 19 23:29:39 2018 +0000
Commit message:
First Test

Changed in this revision

BLE_API.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
microbit-dal.lib Show annotated file Show diff for this revision Revisions of this file
microbit.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 91cacb081de7 BLE_API.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API.lib	Mon Feb 19 23:29:39 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
diff -r 000000000000 -r 91cacb081de7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 19 23:29:39 2018 +0000
@@ -0,0 +1,97 @@
+#include "MicroBit.h"
+#include "MicroBitSamples.h"
+#include "MicroBitUARTService.h"
+MicroBit uBit;
+MicroBitUARTService *uart;
+
+int connected = 0;
+
+void onConnected(MicroBitEvent e)
+{
+    uBit.display.scroll("C");
+
+    connected = 1;
+
+    // my client will send ASCII strings terminated with the colon character
+    ManagedString eom(":");
+
+    while (connected == 1) {
+        ManagedString msg = uart->readUntil(eom);
+        uBit.display.scroll(msg);
+    }
+
+}
+
+void onDisconnected(MicroBitEvent e)
+{
+    uBit.display.scroll("D");
+    connected = 0;
+}
+
+void onButtonA(MicroBitEvent e)
+{
+    if (connected == 0) {
+        uBit.display.scroll("NC");
+        return;
+    }
+    uart->send("YES");
+    uBit.display.scroll("YES");
+}
+
+void onButtonB(MicroBitEvent e)
+{
+    if (connected == 0) {
+        uBit.display.scroll("NC");
+        return;
+    }
+    uart->send("NO");
+    uBit.display.scroll("NO");
+}
+
+void onButtonAB(MicroBitEvent e)
+{
+    if (connected == 0) {
+        uBit.display.scroll("NC");
+        return;
+    }
+    uart->send("GOT IT!!");
+    uBit.display.scroll("GOT IT!!");
+}
+
+/*
+Recommend disabling the DFU and Event services in MicroBitConfig.h since they are not needed here:
+
+#ifndef MICROBIT_BLE_DFU_SERVICE
+#define MICROBIT_BLE_DFU_SERVICE                0
+#endif
+
+#ifndef MICROBIT_BLE_EVENT_SERVICE
+#define MICROBIT_BLE_EVENT_SERVICE              0
+#endif
+*/
+
+int main()
+{
+    // Initialise the micro:bit runtime.
+    uBit.init();
+
+    // listen for Bluetooth connection state changes
+    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
+    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
+
+    // listen for user button interactions
+    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
+    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
+    uBit.messageBus.listen(MICROBIT_ID_BUTTON_AB, MICROBIT_BUTTON_EVT_CLICK, onButtonAB);
+
+
+    // Note GATT table size increased from default in MicroBitConfig.h
+    // #define MICROBIT_SD_GATT_TABLE_SIZE             0x500
+    uart = new MicroBitUARTService(*uBit.ble, 32, 32); 
+    uBit.display.scroll("AVM");
+
+    // If main exits, there may still be other fibers running or registered event handlers etc.
+    // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
+    // sit in the idle task forever, in a power efficient sleep.
+    release_fiber();
+}
\ No newline at end of file
diff -r 000000000000 -r 91cacb081de7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 19 23:29:39 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file
diff -r 000000000000 -r 91cacb081de7 microbit-dal.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/microbit-dal.lib	Mon Feb 19 23:29:39 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/lancaster-university/microbit-dal/#2cff906f019944ae15d532157c1301c940f67862
diff -r 000000000000 -r 91cacb081de7 microbit.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/microbit.lib	Mon Feb 19 23:29:39 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/lancaster-university/microbit/#f4e7e01c1d594a547c326e1567848e69de32d01c