TOF based Presence Detector
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: main.cpp
- Revision:
- 24:0f08f68579bd
- Parent:
- 23:677689000369
- Child:
- 25:231d3f382583
--- a/main.cpp Fri Jan 06 15:28:18 2017 +0000 +++ b/main.cpp Fri Jan 06 20:49:58 2017 +0000 @@ -1,109 +1,97 @@ -#include <mbed.h> -#include "ble/BLE.h" +// T07N_Easy_GATT - Easy GATT setup using bricks + #include "bricks.h" - Serial out(USBTX, USBRX); // serial port to PC terminal - //============================================================================== -// Custom Service Definition +// Custom Service Setup //============================================================================== -// occupation service +// Detection Service - Collection detection; - Characteristic<Digital> presence (detection,0xA011, "rn", "Presence"); - Characteristic<DateTime> timestamp(detection,0xA012, "r", "Timestamp"); - Characteristic<Digital> test (detection,0xA013, "w", "Test"); + Service detection(0xA010,"Detection"); // Detection Service - Service service1(detection,0xA010); // our occupation service + Characteristic<Digital> chrPresence(detection,0xA011, "rn", "Presence"); + Characteristic<DateTime> chrTimestamp(detection,0xA012, "r", "Timestamp"); -// address service +// Address Service + + Service address(0xA020,"Adress"); // Address Service - Collection address; - Characteristic<Digital> id (address, 0xA021, "ran", "ID"); - Characteristic<Digital> name (address, 0xA022, "ran", "Name"); - Characteristic<Digital> layout (address, 0xA023, "ran", "Layout"); + Characteristic<Digital> chrId(address, 0xA021, "ran", "ID"); + Characteristic<Digital> chrName(address, 0xA022, "ran", "Name"); + Characteristic<Digital> chrLayout(address, 0xA023, "ran", "Layout"); + +// Debug Service + + Service debug(0xA030,"Debug"); // Debug Service + + Characteristic<Digital> chrTest (debug,0xA031, "w", "Test"); - Service service2(address,0xA020); // our occupation service - - +// Configure all supported services + + void services(Blob &o) // configure all supported services + { + address.config(o); // configure Address Service + detection.config(o); // configure Detection Service + debug.config(o); // configure Debug Service + } + //============================================================================== -// Some Callbacks +// Callbacks //============================================================================== - void print(Blob &blue, GattCharacteristic &chr, const char *name) - { - Buffer data; uint8_t *p = data; - blue.get(chr,data); - - out.printf("%s: %02x-%02x-%02x-%02x-%02x-",name,(int)(p[0]),(int)(p[1]),(int)(p[2]),(int)(p[3]),(int)(p[4])); - out.printf("%02x-%02x-%02x-%02x-%02x\r\n",(int)(p[5]),(int)(p[6]),(int)(p[7]),(int)(p[8]),(int)(p[9])); - } - - - void onWritten(Blob &o) // Handle writes to writeCharacteristic + void onError(Blob &o) // Error Reporting Callback { - const GattWriteCallbackParams *p = o.pWritten; - - // Check to see what characteristic was written, by handle - - if(p->handle == test.getValueHandle()) - { Digital value; - - get(o,test,value); - set(o,presence,value); - - print(o,test,"test"); - blink("x x x xxx xxx xxx x ",CONNECTED); - } - } - + (void) o; // Avoid compiler warnings + blink(FAULT); // indicate advertising + } void onConnect(Blob &blue) // Connection Callback { blink("x x x ",CONNECTED); // indicate advertising } - void onDisconnect(Blob &blue) // Disconnection Callback { blue.start(); // start advertising on client disconnect blink(ADVERTISE); // indicate advertising } - - void onError(Blob &blue) // Error Reporting Callback - { - (void) blue; // Avoid compiler warnings - blink(FAULT); // indicate advertising - } - - - void onSetup(Blob &blue) // Immediately After Initializing BLE + void onWritten(Blob &o) // Handle writes to writeCharacteristic { - blue.config(service1); // configure custom service 1 - blue.config(service1); // configure custom service 2 - - blue.name("T07N#8 Easy GATT"); // setup advertising name - blue.device("nRF51-DK"); // setup device name - blue.data("ABCDEF"); // setup advertising data + if (updated(o,chrTest)) // has chrTest been updated? + { Digital value; + + get(o,chrTest,value); // get value of chrTest + set(o,chrPresence,value); // and store this value to chrPresence + + print(o,chrTest,"test"); + blink("x x x xxx xxx xxx x ",CONNECTED); + } + } - blue.onConnect(onConnect); // setup connection callback - blue.onDisconnect(onDisconnect); // setup disconnection callback - blue.onWritten(onWritten); // setup data written callback - - blue.advertise("C:ng",100); // start advertising @ 100 msec interval + void onSetup(Blob &o) // Immediately After Initializing BLE + { + services(o); // config all services + + o.onConnect(onConnect); // setup connection callback + o.onDisconnect(onDisconnect); // setup disconnection callback + o.onWritten(onWritten); // setup data written callback + + device(o,"nRF51-DK"); // setup device name + data(o,"ABCDEF"); // setup advertising data + name(o,"T07N#1.0 Easy GATT"); // setup advertising name + + peripheral(o,"C:ng",100); // start advertising @ 100 msec interval blink(ADVERTISE); // show that board is advertising } - + //============================================================================== // Main Program //============================================================================== int main(void) { - out.printf(" hello\r\n"); - verbose(10); // print all verbose messages blink(IDLE); // idle blinking - just started! @@ -112,5 +100,4 @@ while (true) // Infinite loop waiting for BLE events blue.sleep(); // low power waiting for BLE events - } - + } \ No newline at end of file