a simple observer of advertisements.
Dependencies: mbed BLE_API nRF51822
Revision 7:88f50499af9a, committed 2016-01-12
- Comitter:
- andresag
- Date:
- Tue Jan 12 11:00:02 2016 +0000
- Parent:
- 6:9c1dee28ffe2
- Commit message:
- Update example to latest BLE API.
Changed in this revision
diff -r 9c1dee28ffe2 -r 88f50499af9a BLE_API.lib --- a/BLE_API.lib Tue Sep 29 12:03:32 2015 +0000 +++ b/BLE_API.lib Tue Jan 12 11:00:02 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
diff -r 9c1dee28ffe2 -r 88f50499af9a main.cpp --- a/main.cpp Tue Sep 29 12:03:32 2015 +0000 +++ b/main.cpp Tue Jan 12 11:00:02 2016 +0000 @@ -15,10 +15,10 @@ */ #include "mbed.h" -#include "BLE.h" +#include "ble/BLE.h" -BLE ble; -DigitalOut led1(LED1); +DigitalOut led1(LED1, 1); +Ticker ticker; void periodicCallback(void) { @@ -38,16 +38,43 @@ #endif /* DUMP_ADV_DATA */ } +/** + * 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; + } + + ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */); + ble.gap().startScan(advertisementCallback); +} + int main(void) { - led1 = 1; - Ticker ticker; ticker.attach(periodicCallback, 1); - ble.init(); - - ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */); - ble.gap().startScan(advertisementCallback); + BLE &ble = BLE::Instance(); + ble.init(bleInitComplete); while (true) { ble.waitForEvent();
diff -r 9c1dee28ffe2 -r 88f50499af9a mbed.bld --- a/mbed.bld Tue Sep 29 12:03:32 2015 +0000 +++ b/mbed.bld Tue Jan 12 11:00:02 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
diff -r 9c1dee28ffe2 -r 88f50499af9a nRF51822.lib --- a/nRF51822.lib Tue Sep 29 12:03:32 2015 +0000 +++ b/nRF51822.lib Tue Jan 12 11:00:02 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#088f5738bf18 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#3cc0718d98d0