BLE Observer example for nucleo platform

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Revision:
3:37a2f13b746d
Parent:
2:b34944e028f9
Child:
4:2aefa62bdce5
--- a/main.cpp	Fri Nov 11 13:31:05 2016 +0000
+++ b/main.cpp	Fri Nov 11 21:37:44 2016 +0000
@@ -102,6 +102,13 @@
     //ble.gap().startAdvertising();
 
 }
+
+void bleScanInitComplete(BLE::InitializationCompleteCallbackContext *context) {
+            
+            ble_Scan.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1);
+            
+}
+ 
  
 int main(void)
 {
@@ -112,44 +119,44 @@
      BLE &ble = BLE::Instance();
      BLE &ble_Scan = BLE::Instance();
  
-    ble.init(bleInitComplete);
+    //ble.init(bleInitComplete);
     //ble_Scan.init();
 
-    //ble.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1);
-    //ble.gap().startScan(advertisementCallback);
+    //ble_Scan.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1);
+    //ble_Scan.gap().startScan(advertisementCallback);
+    //ble.gap().startAdvertising();
 
 int stato = 0; 
 
      /* Infinite loop waiting for BLE events */
      while (true) {   
      switch (stato) {
-        case(0):
-               //BLE &ble = BLE::Instance();
-               printf("Advertising stato 0\r\n");
-               ble.gap().stopScan();
-               //ble.init(bleInitComplete);
-               ble.gap().startAdvertising();
-               wait(10);
-               //ble.gap().stopAdvertising();
-               //wait(1);
-               stato = 1;
-               break;
-        case(1): 
+      case(0):
+             //BLE &ble = BLE::Instance();
+           printf("Advertising stato 0\r\n");
+           //ble.gap().stopScan();
+           ble.init(bleInitComplete);
+           ble.gap().startAdvertising();
+           wait(10);
+           ble.gap().stopAdvertising();
+           wait(1);
+           stato = 1;
+           break;
+     case(1): 
              //BLE &ble_Scan = BLE::Instance();
-             //ble_Scan.init();
-               printf("Scan stato 1\r\n");
-               ble.gap().stopAdvertising();
-               ble_Scan.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1);
-               ble_Scan.gap().startScan(advertisementCallback);
-               wait(1);
-               ble_Scan.gap().stopScan();
-               //wait(1);
-               stato = 0;
-               break;
-               }
+           ble_Scan.init(bleScanInitComplete);
+           printf("Scan stato 1\r\n");
+           //ble.gap().stopAdvertising();
+           //ble_Scan.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1);
+           ble_Scan.gap().startScan(advertisementCallback);
+           wait(5);
+           //ble_Scan.gap().stopScan();
+          stato = 0;
+          break;
+          }
         
         /* Save power while waiting for callback events */
        ble.waitForEvent();
-
+        ble_Scan.waitForEvent();
        }
 }