SimpleBLE example for mbed OS 5

Dependents:   SimpleBLE-Example-mbedos5

Fork of SimpleBLE by mbed-x

Revision:
5:9b33cae085cc
Parent:
4:0c99ff9d2373
Child:
6:15ec6cd75928
--- a/SimpleBLE.h	Fri Aug 19 11:47:47 2016 +0200
+++ b/SimpleBLE.h	Mon Oct 10 12:12:21 2016 +0200
@@ -18,7 +18,8 @@
 #include <sstream>
 #include <vector>
 #include <map>
-#include "mbed_events.h"
+#include <mbed-events/events.h>
+#include <mbed.h>
 #include "ble/BLE.h"
 
 #define def_fn(T, postfix) \
@@ -172,12 +173,8 @@
     void start(EventQueue* aEventQueue) {
         eventQueue = aEventQueue;
 
+        ble->onEventsToProcess(BLE::OnEventsToProcessCallback_t(this, &SimpleBLE::scheduleBleEventsProcessing));
         ble->init(this, &SimpleBLE::bleInitComplete);
-        ble->onEventsToProcess(BLE::OnEventsToProcessCallback_t(this, &SimpleBLE::scheduleBleEventsProcessing));
-
-        /* SpinWait for initialization to complete. This is necessary because the
-         * BLE object is used in the main loop below. */
-        while (ble->hasInitialized()  == false) { /* spin loop */ }
     }
 
     void onDisconnection(Gap::DisconnectionEventCallback_t callback) {
@@ -298,7 +295,8 @@
     }
 
     void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
-        eventQueue->call(Callback<void()>(ble, &BLE::processEvents));
+        BLE &ble = BLE::Instance();
+        eventQueue->post(Callback<void()>(&ble, &BLE::processEvents));
     }
 
     // === START READONLY ===