A cute tiny piece of code implementing an IoT NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service. The code has been tested on a Nordic nRF51822-DK.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate_IDB0XA1 by
bricks/blinker.h@26:dce30a5341bb, 2018-05-19 (annotated)
- Committer:
- hux
- Date:
- Sat May 19 14:10:17 2018 +0000
- Revision:
- 26:dce30a5341bb
- Parent:
- 25:339931243be4
Published
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 25:339931243be4 | 1 | // blinker.h - blinking sequences for LED1 |
hux | 25:339931243be4 | 2 | #ifndef _BLINKER_H_ |
hux | 25:339931243be4 | 3 | #define _BLINKER_H_ |
hux | 25:339931243be4 | 4 | |
hux | 25:339931243be4 | 5 | #include <mbed.h> |
hux | 25:339931243be4 | 6 | |
hux | 25:339931243be4 | 7 | # define BLINKER_SEQUENCE_IDLE "x " |
hux | 25:339931243be4 | 8 | # define BLINKER_SEQUENCE_ADVERTISE "x xxx " |
hux | 25:339931243be4 | 9 | # define BLINKER_SEQUENCE_CONNECTED " xxx " |
hux | 25:339931243be4 | 10 | # define BLINKER_SEQUENCE_ACTION "x x x x x " |
hux | 25:339931243be4 | 11 | # define BLINKER_SEQUENCE_ERROR "x x x x xxx " |
hux | 25:339931243be4 | 12 | # define BLINKER_SEQUENCE_TRANSITION "x x x " |
hux | 25:339931243be4 | 13 | |
hux | 25:339931243be4 | 14 | class Blinker |
hux | 25:339931243be4 | 15 | { |
hux | 25:339931243be4 | 16 | public: // construction |
hux | 25:339931243be4 | 17 | Blinker() {} // nothing to do |
hux | 25:339931243be4 | 18 | |
hux | 25:339931243be4 | 19 | public: |
hux | 25:339931243be4 | 20 | void morse(const char *pattern, double periode = 0.2); |
hux | 25:339931243be4 | 21 | void blink(const char *pattern, const char* next, double interval = 0.2); |
hux | 25:339931243be4 | 22 | void blink(const char *pattern, double periode = 0.2); |
hux | 25:339931243be4 | 23 | |
hux | 25:339931243be4 | 24 | void idle(const char *action = BLINKER_SEQUENCE_IDLE) |
hux | 25:339931243be4 | 25 | { |
hux | 25:339931243be4 | 26 | blink(action,BLINKER_SEQUENCE_IDLE); |
hux | 25:339931243be4 | 27 | } |
hux | 25:339931243be4 | 28 | |
hux | 25:339931243be4 | 29 | void advertise(const char *action = BLINKER_SEQUENCE_ADVERTISE) |
hux | 25:339931243be4 | 30 | { |
hux | 25:339931243be4 | 31 | blink(action,BLINKER_SEQUENCE_ADVERTISE); |
hux | 25:339931243be4 | 32 | } |
hux | 25:339931243be4 | 33 | |
hux | 25:339931243be4 | 34 | void connected(const char *action = BLINKER_SEQUENCE_ACTION) |
hux | 25:339931243be4 | 35 | { |
hux | 25:339931243be4 | 36 | blink(action, BLINKER_SEQUENCE_CONNECTED); |
hux | 25:339931243be4 | 37 | } |
hux | 25:339931243be4 | 38 | |
hux | 25:339931243be4 | 39 | void action() // 'action' blink sequence |
hux | 25:339931243be4 | 40 | { |
hux | 25:339931243be4 | 41 | blink(BLINKER_SEQUENCE_ACTION, BLINKER_SEQUENCE_IDLE); |
hux | 25:339931243be4 | 42 | } |
hux | 25:339931243be4 | 43 | |
hux | 25:339931243be4 | 44 | void error(const char *action = BLINKER_SEQUENCE_ERROR) |
hux | 25:339931243be4 | 45 | { |
hux | 25:339931243be4 | 46 | blink(action,BLINKER_SEQUENCE_ERROR); |
hux | 25:339931243be4 | 47 | } |
hux | 25:339931243be4 | 48 | |
hux | 25:339931243be4 | 49 | void blink() // stop blinking |
hux | 25:339931243be4 | 50 | { |
hux | 25:339931243be4 | 51 | blink(""); // empty blinking pattern |
hux | 25:339931243be4 | 52 | } |
hux | 25:339931243be4 | 53 | }; |
hux | 25:339931243be4 | 54 | |
hux | 25:339931243be4 | 55 | #endif // _BLINKER_H_ |