Bluetooth Connected TOF Sensor
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/sleep.h@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
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 | // sleep.h - sleep for some time |
hux | 27:32267cee7cb8 | 2 | // |
hux | 27:32267cee7cb8 | 3 | // Synopsis: |
hux | 27:32267cee7cb8 | 4 | // |
hux | 27:32267cee7cb8 | 5 | // void sleep(Blob &o) // low energy sleep for some mili seconds |
hux | 27:32267cee7cb8 | 6 | // void sleep(Blob &o, int ms) // low enery sleep, handle BLE events |
hux | 27:32267cee7cb8 | 7 | // |
hux | 27:32267cee7cb8 | 8 | // Arguments: |
hux | 27:32267cee7cb8 | 9 | // |
hux | 27:32267cee7cb8 | 10 | // o: Blob object (to avoid name clashes) |
hux | 27:32267cee7cb8 | 11 | // msec: sleeping interval in miliseconds |
hux | 27:32267cee7cb8 | 12 | // |
hux | 27:32267cee7cb8 | 13 | // Description: |
hux | 27:32267cee7cb8 | 14 | // |
hux | 27:32267cee7cb8 | 15 | // |
hux | 27:32267cee7cb8 | 16 | // Example 1: main function body to setup BLE functionality |
hux | 27:32267cee7cb8 | 17 | // |
hux | 27:32267cee7cb8 | 18 | // main(void) |
hux | 27:32267cee7cb8 | 19 | // { |
hux | 27:32267cee7cb8 | 20 | // Blob o; // our Blob object |
hux | 27:32267cee7cb8 | 21 | // init(o,onSetup,onError); // init BLE base layer, always do first |
hux | 27:32267cee7cb8 | 22 | // |
hux | 27:32267cee7cb8 | 23 | // while (true) // Infinite loop waiting for BLE events |
hux | 27:32267cee7cb8 | 24 | // sleep(o); // low power waiting for BLE events |
hux | 27:32267cee7cb8 | 25 | // } |
hux | 27:32267cee7cb8 | 26 | // |
hux | 27:32267cee7cb8 | 27 | // Example 2: Turn LED on for 2 seconds miliseconds |
hux | 27:32267cee7cb8 | 28 | // |
hux | 27:32267cee7cb8 | 29 | // led = 1; // turn LED on |
hux | 27:32267cee7cb8 | 30 | // sleep(o,2000); // wait 2000 miliseconds (in LE mode) |
hux | 27:32267cee7cb8 | 31 | // led = 0; // turn LED off |
hux | 27:32267cee7cb8 | 32 | // |
hux | 27:32267cee7cb8 | 33 | // See also: BLOB, INIT |
hux | 27:32267cee7cb8 | 34 | // |
hux | 27:32267cee7cb8 | 35 | #ifndef _SLEEP_H_ |
hux | 27:32267cee7cb8 | 36 | #define _SLEEP_H_ |
hux | 27:32267cee7cb8 | 37 | |
hux | 27:32267cee7cb8 | 38 | #include "bricks/blob.h" |
hux | 27:32267cee7cb8 | 39 | |
hux | 27:32267cee7cb8 | 40 | inline void sleep(Blob &o) // low power waiting for BLE events |
hux | 27:32267cee7cb8 | 41 | { |
hux | 27:32267cee7cb8 | 42 | o.waitForEvent(); // low power waiting for BLE events |
hux | 27:32267cee7cb8 | 43 | } |
hux | 27:32267cee7cb8 | 44 | |
hux | 27:32267cee7cb8 | 45 | inline void sleep(Blob &o, int ms) // low power waiting for BLE events |
hux | 27:32267cee7cb8 | 46 | { |
hux | 27:32267cee7cb8 | 47 | wait_ms(ms); // low power waiting for some miliseconds |
hux | 27:32267cee7cb8 | 48 | } |
hux | 27:32267cee7cb8 | 49 | |
hux | 27:32267cee7cb8 | 50 | #endif // _SLEEP_H_ |