Small Demo demonstrating BLE Advertising
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: main.cpp
- Revision:
- 28:114eaad388c1
- Parent:
- 27:09ec26511db8
- Child:
- 29:8eb46b976f0f
--- a/main.cpp Sun Dec 11 19:18:02 2016 +0000 +++ b/main.cpp Sun Jan 08 23:13:25 2017 +0000 @@ -1,8 +1,7 @@ -// T04_Advertising: Tutorial for demonstration of simple advertising -// Program has been tested on NUCLEO-L76RG +// N05_Advertising: Tutorial for demonstration of simple advertising +// Program has been tested on nRF51822-DK -#include <mbed.h> -#include "bricks.h" +#include "bricks/bricks.h" // Add a device name for human readability @@ -18,43 +17,41 @@ // Some Callbacks //============================================================================== - void onDisconnect(Blob &blob) // Disconnection Callback + void cbDisconnect(O&o) // disconnection callback { - blob.start(); // start advertising - blink(ADVERTISE); // indicate advertising + advertise(o); // start advertising + blinkAdvertise(o); // indicate advertising } - void onError(Blob &blob) // Error Reporting Callback + void cbError(O&o) // Error Reporting Callback { - (void) blob; // Avoid compiler warnings - blink(FAULT); // indicate advertising + blinkError(o); // indicate an error } - void onSetup(Blob &blob) // Immediately After Initializing BLE + void cbSetup(O&o) // setup calback (after BLE init) { - blob.device(DEVICE_NAME); // setup device name - blob.data(AdvData,sizeof(AdvData)); - blob.name("T05 Advertise"); // add name to device + device(o,DEVICE_NAME); // setup device name + name(o,"N05#1.0 Advertise"); // add name to device + data(o,AdvData,sizeof(AdvData)); // advertising user data - blob.onDisconnect(onDisconnect); // setup disconnection callback + onDisconnect(o,cbDisconnect); // setup disconnection callback - blob.mode("C:ng"); // no BR/EDR, general discoverable (UDSN) - blob.start(100); // start advertising @ 100 msec interval - blink(ADVERTISE); + payload(o,"C:ng"); // no BR/EDR, general discoverable (UDSN) + advertise(o,100); // start advertising @ 100 msec interval + blinkAdvertise(o); // indicate advertising mode } int main(void) { - blink(IDLE); // idle blinking - everything is OK! + O o; // Our Blob (BLuetooth OBject) + verbose(o); // verbose talking (all levels) + blinkIdle(o); // idle blinking - everything is OK! - Blob blob; - blob.init(onSetup,onError); // init BLE base layer, always do first + init(o,cbSetup,cbError); // init BLE base layer, always do first - while (true) // Infinite loop waiting for BLE events */ - { - blob.sleep(); // low power waiting for BLE events - } + while (true) // Infinite loop waiting for BLE events + sleep(o); // low power waiting for BLE events }