![](/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
bricks/set.h@27:32267cee7cb8, 2017-01-14 (annotated)
- Committer:
- hux
- Date:
- Sat Jan 14 08:43:14 2017 +0000
- Revision:
- 27:32267cee7cb8
- Parent:
- 26:fd06c8b57d16
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 | 23:677689000369 | 1 | // set.h - set data from a characteristics |
hux | 23:677689000369 | 2 | // |
hux | 23:677689000369 | 3 | // Synopsis: |
hux | 23:677689000369 | 4 | // |
hux | 23:677689000369 | 5 | // Set data from a 'characteristic' based on 'data' variable |
hux | 23:677689000369 | 6 | // |
hux | 23:677689000369 | 7 | // set(characteristic,data) |
hux | 23:677689000369 | 8 | // |
hux | 23:677689000369 | 9 | // The 'set' function (overloaded function family) is implemented for all |
hux | 23:677689000369 | 10 | // types defined in "bricks/types.h". |
hux | 23:677689000369 | 11 | // |
hux | 23:677689000369 | 12 | // See also: CHARACTERISTIC, GET |
hux | 23:677689000369 | 13 | // |
hux | 23:677689000369 | 14 | #ifndef _SET_H_ |
hux | 23:677689000369 | 15 | #define _SET_H_ |
hux | 23:677689000369 | 16 | |
hux | 23:677689000369 | 17 | #include "ble/BLE.h" |
hux | 23:677689000369 | 18 | #include "ble/Gap.h" |
hux | 23:677689000369 | 19 | #include "ble/GattServer.h" |
hux | 27:32267cee7cb8 | 20 | #include "bricks/o.h" |
hux | 23:677689000369 | 21 | #include "bricks/types.h" |
hux | 23:677689000369 | 22 | #include "bricks/characteristic.h" |
hux | 23:677689000369 | 23 | |
hux | 27:32267cee7cb8 | 24 | inline void set(O&o, Characteristic<Bool> &chr, const Bool &data) |
hux | 23:677689000369 | 25 | { |
hux | 26:fd06c8b57d16 | 26 | uint16_t size = sizeof(Bool)/sizeof(uint8_t); |
hux | 27:32267cee7cb8 | 27 | o.gattServer().write(chr.getValueHandle(), (uint8_t*)&data,size); |
hux | 27:32267cee7cb8 | 28 | } |
hux | 27:32267cee7cb8 | 29 | |
hux | 27:32267cee7cb8 | 30 | inline void set(O&o, Characteristic<ObjectId> &chr, const ObjectId &data) |
hux | 27:32267cee7cb8 | 31 | { |
hux | 27:32267cee7cb8 | 32 | uint16_t size = sizeof(ObjectId)/sizeof(uint8_t); |
hux | 27:32267cee7cb8 | 33 | o.gattServer().write(chr.getValueHandle(), (uint8_t*)&data,size); |
hux | 23:677689000369 | 34 | } |
hux | 23:677689000369 | 35 | |
hux | 27:32267cee7cb8 | 36 | // we provide also some SET methods for GattCharacteristics. However the use |
hux | 27:32267cee7cb8 | 37 | // of these methods are more dangerous, because a GattCharacteristics can be |
hux | 27:32267cee7cb8 | 38 | // of any type and the compiler cannot help us to check !!! |
hux | 27:32267cee7cb8 | 39 | |
hux | 27:32267cee7cb8 | 40 | inline void set(O&o,GattCharacteristic &chr,Bool data) |
hux | 23:677689000369 | 41 | { |
hux | 27:32267cee7cb8 | 42 | uint16_t size = sizeof(Bool)/sizeof(uint8_t); |
hux | 27:32267cee7cb8 | 43 | o.gattServer().write(chr.getValueHandle(), (uint8_t*)&data,size); |
hux | 23:677689000369 | 44 | } |
hux | 23:677689000369 | 45 | |
hux | 23:677689000369 | 46 | #endif // _SET_H_ |