A blue button is always a nice toy ...
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp@25:231d3f382583, 2017-01-06 (annotated)
- Committer:
- hux
- Date:
- Fri Jan 06 21:36:47 2017 +0000
- Revision:
- 25:231d3f382583
- Parent:
- 24:0f08f68579bd
- Child:
- 26:fd06c8b57d16
T07N_Easy_GATT, release 1.1 - all services & required callbacks for handling the services are moved to easy.cpp. Works well - no bug known!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 24:0f08f68579bd | 1 | // T07N_Easy_GATT - Easy GATT setup using bricks |
hux | 24:0f08f68579bd | 2 | |
hux | 22:d467526abc4a | 3 | #include "bricks.h" |
hux | 25:231d3f382583 | 4 | #include "easy.h" |
hux | 24:0f08f68579bd | 5 | |
hux | 22:d467526abc4a | 6 | //============================================================================== |
hux | 24:0f08f68579bd | 7 | // Callbacks |
hux | 22:d467526abc4a | 8 | //============================================================================== |
screamer | 0:eb7f02ad28a7 | 9 | |
hux | 24:0f08f68579bd | 10 | void onError(Blob &o) // Error Reporting Callback |
hux | 23:677689000369 | 11 | { |
hux | 24:0f08f68579bd | 12 | (void) o; // Avoid compiler warnings |
hux | 24:0f08f68579bd | 13 | blink(FAULT); // indicate advertising |
hux | 24:0f08f68579bd | 14 | } |
apalmieri | 13:227a0149b677 | 15 | |
hux | 22:d467526abc4a | 16 | void onConnect(Blob &blue) // Connection Callback |
hux | 22:d467526abc4a | 17 | { |
hux | 23:677689000369 | 18 | blink("x x x ",CONNECTED); // indicate advertising |
hux | 22:d467526abc4a | 19 | } |
apalmieri | 13:227a0149b677 | 20 | |
hux | 22:d467526abc4a | 21 | void onDisconnect(Blob &blue) // Disconnection Callback |
hux | 22:d467526abc4a | 22 | { |
hux | 22:d467526abc4a | 23 | blue.start(); // start advertising on client disconnect |
hux | 22:d467526abc4a | 24 | blink(ADVERTISE); // indicate advertising |
hux | 22:d467526abc4a | 25 | } |
hux | 22:d467526abc4a | 26 | |
hux | 24:0f08f68579bd | 27 | void onSetup(Blob &o) // Immediately After Initializing BLE |
hux | 24:0f08f68579bd | 28 | { |
hux | 25:231d3f382583 | 29 | easy(o); // enroll EASY services & setup callbacks |
hux | 24:0f08f68579bd | 30 | |
hux | 24:0f08f68579bd | 31 | o.onConnect(onConnect); // setup connection callback |
hux | 24:0f08f68579bd | 32 | o.onDisconnect(onDisconnect); // setup disconnection callback |
hux | 24:0f08f68579bd | 33 | |
hux | 24:0f08f68579bd | 34 | device(o,"nRF51-DK"); // setup device name |
hux | 24:0f08f68579bd | 35 | data(o,"ABCDEF"); // setup advertising data |
hux | 25:231d3f382583 | 36 | name(o,"T07N#1.1 Easy GATT"); // setup advertising name |
hux | 24:0f08f68579bd | 37 | |
hux | 24:0f08f68579bd | 38 | peripheral(o,"C:ng",100); // start advertising @ 100 msec interval |
hux | 22:d467526abc4a | 39 | blink(ADVERTISE); // show that board is advertising |
hux | 22:d467526abc4a | 40 | } |
hux | 24:0f08f68579bd | 41 | |
hux | 22:d467526abc4a | 42 | //============================================================================== |
hux | 22:d467526abc4a | 43 | // Main Program |
hux | 22:d467526abc4a | 44 | //============================================================================== |
hux | 22:d467526abc4a | 45 | |
hux | 22:d467526abc4a | 46 | int main(void) |
hux | 22:d467526abc4a | 47 | { |
hux | 25:231d3f382583 | 48 | verbose(); // print all verbose messages |
hux | 22:d467526abc4a | 49 | blink(IDLE); // idle blinking - just started! |
apalmieri | 13:227a0149b677 | 50 | |
hux | 23:677689000369 | 51 | Blob blue; // declare a blob (BLE OBject) |
hux | 22:d467526abc4a | 52 | blue.init(onSetup,onError); // init BLE base layer, always do first |
hux | 22:d467526abc4a | 53 | |
hux | 22:d467526abc4a | 54 | while (true) // Infinite loop waiting for BLE events |
hux | 22:d467526abc4a | 55 | blue.sleep(); // low power waiting for BLE events |
hux | 24:0f08f68579bd | 56 | } |