![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A blue button is always a nice toy ...
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
- Parent:
- 26:fd06c8b57d16
- Child:
- 28:307f58df778a
Setup a GATT Detector Service. There is some bug in the GATT setup, resulting in different behavior between Nordic nRF51822-DK and NUCLEO-L476RG, but with the workaround it works also for the NUCLEO board. (using Bricks V1A)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 27:32267cee7cb8 | 1 | // S07_Detection - Easy GATT setup using bricks for DETECTION services |
hux | 24:0f08f68579bd | 2 | |
hux | 26:fd06c8b57d16 | 3 | #include "bricks/bricks.h" |
hux | 27:32267cee7cb8 | 4 | #include "detection.h" |
hux | 24:0f08f68579bd | 5 | |
hux | 22:d467526abc4a | 6 | //============================================================================== |
hux | 24:0f08f68579bd | 7 | // Callbacks |
hux | 22:d467526abc4a | 8 | //============================================================================== |
screamer | 0:eb7f02ad28a7 | 9 | |
hux | 27:32267cee7cb8 | 10 | void cbError(O&o) // Error Reporting Callback |
hux | 23:677689000369 | 11 | { |
hux | 27:32267cee7cb8 | 12 | blinkError(o); // 'error' blink sequence |
hux | 24:0f08f68579bd | 13 | } |
apalmieri | 13:227a0149b677 | 14 | |
hux | 27:32267cee7cb8 | 15 | void cbConnect(O&o) // Connection Callback |
hux | 22:d467526abc4a | 16 | { |
hux | 27:32267cee7cb8 | 17 | blinkConnected(o); // 'error' blink sequence |
hux | 22:d467526abc4a | 18 | } |
apalmieri | 13:227a0149b677 | 19 | |
hux | 27:32267cee7cb8 | 20 | void cbDisconnect(O&o) // Disconnection Callback |
hux | 22:d467526abc4a | 21 | { |
hux | 27:32267cee7cb8 | 22 | advertise(o); // start advertising on client disconnect |
hux | 27:32267cee7cb8 | 23 | blinkAdvertise(o); // 'advertise' blink sequence |
hux | 22:d467526abc4a | 24 | } |
hux | 22:d467526abc4a | 25 | |
hux | 27:32267cee7cb8 | 26 | void cbSetup(O&o) // Immediately After Initializing BLE |
hux | 24:0f08f68579bd | 27 | { |
hux | 27:32267cee7cb8 | 28 | services(o); // enroll all services & setup callbacks |
hux | 24:0f08f68579bd | 29 | |
hux | 27:32267cee7cb8 | 30 | onConnect(o,cbConnect); // setup connection callback |
hux | 27:32267cee7cb8 | 31 | onDisconnect(o,cbDisconnect); // setup disconnection callback |
hux | 24:0f08f68579bd | 32 | |
hux | 27:32267cee7cb8 | 33 | device(o,"S07 Detector #3.47"); // setup device name |
hux | 27:32267cee7cb8 | 34 | name(o,"Detector"); // setup advertising name |
hux | 27:32267cee7cb8 | 35 | data(o,"My Layout"); // setup advertising data |
hux | 24:0f08f68579bd | 36 | |
hux | 27:32267cee7cb8 | 37 | advertise(o,"C:ng",100); // start advertising @ 100 msec interval |
hux | 27:32267cee7cb8 | 38 | blinkAdvertise(o); // 'advertise' blink sequence |
hux | 22:d467526abc4a | 39 | } |
hux | 24:0f08f68579bd | 40 | |
hux | 22:d467526abc4a | 41 | //============================================================================== |
hux | 22:d467526abc4a | 42 | // Main Program |
hux | 22:d467526abc4a | 43 | //============================================================================== |
hux | 22:d467526abc4a | 44 | |
hux | 22:d467526abc4a | 45 | int main(void) |
hux | 22:d467526abc4a | 46 | { |
hux | 27:32267cee7cb8 | 47 | O o; // declare a blob (BLE OBject) |
hux | 27:32267cee7cb8 | 48 | verbose(o); // enable all trace messages |
hux | 27:32267cee7cb8 | 49 | blinkIdle(o); // idle blinking - just started! |
apalmieri | 13:227a0149b677 | 50 | |
hux | 27:32267cee7cb8 | 51 | init(o,cbSetup,cbError); // init BLE base layer, always do first |
hux | 22:d467526abc4a | 52 | |
hux | 22:d467526abc4a | 53 | while (true) // Infinite loop waiting for BLE events |
hux | 27:32267cee7cb8 | 54 | sleep(o); // low power waiting for BLE events |
hux | 24:0f08f68579bd | 55 | } |