![](/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
main.cpp
- Committer:
- hux
- Date:
- 2017-01-08
- Revision:
- 23:2e73c391bb12
- Parent:
- 22:d467526abc4a
- Child:
- 25:339931243be4
File content as of revision 23:2e73c391bb12:
// N06_NAND: demonstration of 'NAND' GATT service // Program has been tested on nRF51822-DK #include "bricks/bricks.h" Service tiny(0xA000,"Tiny"); // Tiny Service Characteristic<Digital> chrInput1(tiny, 0xA001, "w", "Input1"); Characteristic<Digital> chrInput2(tiny, 0xA002, "w", "Input2"); Characteristic<Digital> chrOutput(tiny, 0xA003, "n", "Output"); void cbWritten(O&o) // data written callback { Digital in1, in2, out; // need some local variables if (updated(o,chrInput1) || updated(o,chrInput2)) // changed inputs? { get(o,chrInput1,in1); // get value of Input1 characteristics get(o,chrInput2,in2); // get value of Input2 characteristics out = !(in1 && in2); // perform NAND (Not AND) operation set(o,chrOutput,out); // store result to Output characteristics } } void cbDisconnect(O&o) // disconnection callback { advertise(o); // resume advertising on disconnection } void cbSetup(O&o) // setup calback (after BLE init) { onDisconnect(o,cbDisconnect); // setup disconnection callback onWritten(o,cbWritten); // setup data written callback device(o,"NAND Gate"); // setup device name name(o,"N04#1.0 NAND"); // add name to device enroll(o,tiny); // enroll (register) TINY service advertise(o,"C:ng",100); // start advertising @ 100 msec interval } int main(void) { O o; // Oh-ohh - our Blob (BLuetooth OBject) init(o,cbSetup); // init BLE base layer, always do first for(;;) sleep(o); // low power waiting for BLE events }