A very simple advertisement scanner to go along with TemperatureBeacon.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_TemperatureObserver by xiao sun

Files at this revision

API Documentation at this revision

Comitter:
andresag
Date:
Tue Jan 12 10:20:26 2016 +0000
Parent:
10:f6876fd29768
Commit message:
Update example to latest BLE API.

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
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
--- a/BLE_API.lib	Tue Sep 29 12:08:57 2015 +0000
+++ b/BLE_API.lib	Tue Jan 12 10:20:26 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#d494ad3e87bd
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#bfc5b9b6ecf5
--- a/main.cpp	Tue Sep 29 12:08:57 2015 +0000
+++ b/main.cpp	Tue Jan 12 10:20:26 2016 +0000
@@ -19,8 +19,8 @@
 #include "ble/BLE.h"
 #include "TMP_nrf51/TMP_nrf51.h"
 
-BLE        ble;
 DigitalOut alivenessLED(LED1, 1);
+Ticker     ticker;
 
 void periodicCallback(void)
 {
@@ -64,14 +64,44 @@
     }
 }
 
+/**
+ * This function is called when the ble initialization process has failed
+ */
+void onBleInitError(BLE &ble, ble_error_t error)
+{
+    /* Initialization error handling should go here */
+}
+
+/**
+ * Callback triggered when the ble initialization process has finished
+ */
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    BLE&        ble   = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        /* In case of error, forward the error handling to onBleInitError */
+        onBleInitError(ble, error);
+        return;
+    }
+
+    /* Ensure that it is the default instance of BLE */
+    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+        return;
+    }
+
+    /* Setup and start scanning */
+    ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
+    ble.gap().startScan(advertisementCallback);
+}
+
 int main(void)
 {
-    Ticker ticker;
-    ticker.attach(periodicCallback, 1);
+    ticker.attach(periodicCallback, 1);  /* trigger sensor polling every 2 seconds */
 
-    ble.init();
-    ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
-    ble.gap().startScan(advertisementCallback);
+    BLE &ble = BLE::Instance();
+    ble.init(bleInitComplete);
 
     while (true) {
         ble.waitForEvent();
--- a/mbed.bld	Tue Sep 29 12:08:57 2015 +0000
+++ b/mbed.bld	Tue Jan 12 10:20:26 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
--- a/nRF51822.lib	Tue Sep 29 12:08:57 2015 +0000
+++ b/nRF51822.lib	Tue Jan 12 10:20:26 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#088f5738bf18
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#3cc0718d98d0