![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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/set.h@23:2e73c391bb12, 2017-01-08 (annotated)
- Committer:
- hux
- Date:
- Sun Jan 08 23:15:53 2017 +0000
- Revision:
- 23:2e73c391bb12
A cute tiny piece of code implementing an Iot NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 23:2e73c391bb12 | 1 | // set.h - set data from a characteristics |
hux | 23:2e73c391bb12 | 2 | // |
hux | 23:2e73c391bb12 | 3 | // Synopsis: |
hux | 23:2e73c391bb12 | 4 | // |
hux | 23:2e73c391bb12 | 5 | // Set data from a 'characteristic' based on 'data' variable |
hux | 23:2e73c391bb12 | 6 | // |
hux | 23:2e73c391bb12 | 7 | // set(characteristic,data) |
hux | 23:2e73c391bb12 | 8 | // |
hux | 23:2e73c391bb12 | 9 | // The 'set' function (overloaded function family) is implemented for all |
hux | 23:2e73c391bb12 | 10 | // types defined in "bricks/types.h". |
hux | 23:2e73c391bb12 | 11 | // |
hux | 23:2e73c391bb12 | 12 | // See also: CHARACTERISTIC, GET |
hux | 23:2e73c391bb12 | 13 | // |
hux | 23:2e73c391bb12 | 14 | #ifndef _SET_H_ |
hux | 23:2e73c391bb12 | 15 | #define _SET_H_ |
hux | 23:2e73c391bb12 | 16 | |
hux | 23:2e73c391bb12 | 17 | #include "ble/BLE.h" |
hux | 23:2e73c391bb12 | 18 | #include "ble/Gap.h" |
hux | 23:2e73c391bb12 | 19 | #include "ble/GattServer.h" |
hux | 23:2e73c391bb12 | 20 | #include "bricks/o.h" |
hux | 23:2e73c391bb12 | 21 | #include "bricks/types.h" |
hux | 23:2e73c391bb12 | 22 | #include "bricks/characteristic.h" |
hux | 23:2e73c391bb12 | 23 | |
hux | 23:2e73c391bb12 | 24 | inline void set(O&o, Characteristic<Bool> &chr, const Bool &data) |
hux | 23:2e73c391bb12 | 25 | { |
hux | 23:2e73c391bb12 | 26 | uint16_t size = sizeof(Bool)/sizeof(uint8_t); |
hux | 23:2e73c391bb12 | 27 | o.gattServer().write(chr.getValueHandle(), (uint8_t*)&data,size); |
hux | 23:2e73c391bb12 | 28 | } |
hux | 23:2e73c391bb12 | 29 | |
hux | 23:2e73c391bb12 | 30 | inline void set(O&o, Characteristic<ObjectId> &chr, const ObjectId &data) |
hux | 23:2e73c391bb12 | 31 | { |
hux | 23:2e73c391bb12 | 32 | uint16_t size = sizeof(ObjectId)/sizeof(uint8_t); |
hux | 23:2e73c391bb12 | 33 | o.gattServer().write(chr.getValueHandle(), (uint8_t*)&data,size); |
hux | 23:2e73c391bb12 | 34 | } |
hux | 23:2e73c391bb12 | 35 | |
hux | 23:2e73c391bb12 | 36 | #endif // _SET_H_ |