A nice BLE demo program which allows remote switch of an LED via GATT interface.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Button by
bricks/sleep.h@12:0d0ca44397dd, 2017-10-21 (annotated)
- Committer:
- hux
- Date:
- Sat Oct 21 19:55:47 2017 +0000
- Revision:
- 12:0d0ca44397dd
A nice BLE demo program which allows to switch a LED via BLE GATT interface.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 12:0d0ca44397dd | 1 | // sleep.h - sleep for some time |
hux | 12:0d0ca44397dd | 2 | // |
hux | 12:0d0ca44397dd | 3 | // Synopsis: |
hux | 12:0d0ca44397dd | 4 | // |
hux | 12:0d0ca44397dd | 5 | // void sleep(Blob &o) // low energy sleep for some mili seconds |
hux | 12:0d0ca44397dd | 6 | // void sleep(Blob &o, int ms) // low enery sleep, handle BLE events |
hux | 12:0d0ca44397dd | 7 | // |
hux | 12:0d0ca44397dd | 8 | // Arguments: |
hux | 12:0d0ca44397dd | 9 | // |
hux | 12:0d0ca44397dd | 10 | // o: Blob object (to avoid name clashes) |
hux | 12:0d0ca44397dd | 11 | // msec: sleeping interval in miliseconds |
hux | 12:0d0ca44397dd | 12 | // |
hux | 12:0d0ca44397dd | 13 | // Description: |
hux | 12:0d0ca44397dd | 14 | // |
hux | 12:0d0ca44397dd | 15 | // |
hux | 12:0d0ca44397dd | 16 | // Example 1: main function body to setup BLE functionality |
hux | 12:0d0ca44397dd | 17 | // |
hux | 12:0d0ca44397dd | 18 | // main(void) |
hux | 12:0d0ca44397dd | 19 | // { |
hux | 12:0d0ca44397dd | 20 | // Blob o; // our Blob object |
hux | 12:0d0ca44397dd | 21 | // init(o,onSetup,onError); // init BLE base layer, always do first |
hux | 12:0d0ca44397dd | 22 | // |
hux | 12:0d0ca44397dd | 23 | // while (true) // Infinite loop waiting for BLE events |
hux | 12:0d0ca44397dd | 24 | // sleep(o); // low power waiting for BLE events |
hux | 12:0d0ca44397dd | 25 | // } |
hux | 12:0d0ca44397dd | 26 | // |
hux | 12:0d0ca44397dd | 27 | // Example 2: Turn LED on for 2 seconds miliseconds |
hux | 12:0d0ca44397dd | 28 | // |
hux | 12:0d0ca44397dd | 29 | // led = 1; // turn LED on |
hux | 12:0d0ca44397dd | 30 | // sleep(o,2000); // wait 2000 miliseconds (in LE mode) |
hux | 12:0d0ca44397dd | 31 | // led = 0; // turn LED off |
hux | 12:0d0ca44397dd | 32 | // |
hux | 12:0d0ca44397dd | 33 | // See also: BLOB, INIT |
hux | 12:0d0ca44397dd | 34 | // |
hux | 12:0d0ca44397dd | 35 | #ifndef _SLEEP_H_ |
hux | 12:0d0ca44397dd | 36 | #define _SLEEP_H_ |
hux | 12:0d0ca44397dd | 37 | |
hux | 12:0d0ca44397dd | 38 | #include "bricks/blob.h" |
hux | 12:0d0ca44397dd | 39 | |
hux | 12:0d0ca44397dd | 40 | inline void sleep(Blob &o) // low power waiting for BLE events |
hux | 12:0d0ca44397dd | 41 | { |
hux | 12:0d0ca44397dd | 42 | o.waitForEvent(); // low power waiting for BLE events |
hux | 12:0d0ca44397dd | 43 | } |
hux | 12:0d0ca44397dd | 44 | |
hux | 12:0d0ca44397dd | 45 | inline void sleep(Blob &o, int ms) // low power waiting for BLE events |
hux | 12:0d0ca44397dd | 46 | { |
hux | 12:0d0ca44397dd | 47 | wait_ms(ms); // low power waiting for some miliseconds |
hux | 12:0d0ca44397dd | 48 | } |
hux | 12:0d0ca44397dd | 49 | |
hux | 12:0d0ca44397dd | 50 | #endif // _SLEEP_H_ |