![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TOF based Presence Detector
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
tedious.cpp@29:eceecbe28088, 2018-08-20 (annotated)
- Committer:
- hux
- Date:
- Mon Aug 20 16:43:10 2018 +0000
- Revision:
- 29:eceecbe28088
- Parent:
- 27:32267cee7cb8
made in Shanghai
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 27:32267cee7cb8 | 1 | // tedious.cpp - tedious setup and handling of DETECTION services |
hux | 27:32267cee7cb8 | 2 | |
hux | 27:32267cee7cb8 | 3 | #include "detection.h" |
hux | 27:32267cee7cb8 | 4 | |
hux | 27:32267cee7cb8 | 5 | // declare a CharacteristicDataInitializer which can be used to initialize |
hux | 27:32267cee7cb8 | 6 | // all our characteristics |
hux | 27:32267cee7cb8 | 7 | |
hux | 27:32267cee7cb8 | 8 | static CharacteristicInitializer ini; |
hux | 27:32267cee7cb8 | 9 | |
hux | 27:32267cee7cb8 | 10 | // Detection Service |
hux | 27:32267cee7cb8 | 11 | // |
hux | 27:32267cee7cb8 | 12 | // Service detection(0xA010,"Detection"); // Detection Service |
hux | 27:32267cee7cb8 | 13 | // Characteristic<Bool> chrPresence(detection,0xA011, "n", "Presence"); |
hux | 27:32267cee7cb8 | 14 | |
hux | 27:32267cee7cb8 | 15 | UserDescriptor(namePresense,attPresence,dscPresence,"Presence") |
hux | 27:32267cee7cb8 | 16 | static ReadOnlyGattCharacteristic<Bool> chrPresence(0xA011,ini.pBool(),0,dscPresence,1); |
hux | 27:32267cee7cb8 | 17 | |
hux | 27:32267cee7cb8 | 18 | static GattCharacteristic *detectionList[] = {&chrPresence}; |
hux | 27:32267cee7cb8 | 19 | static GattService detection(0xA010, detectionList, GattListLength(detectionList)); |
hux | 27:32267cee7cb8 | 20 | |
hux | 27:32267cee7cb8 | 21 | // Address Service |
hux | 27:32267cee7cb8 | 22 | // |
hux | 27:32267cee7cb8 | 23 | // Service address(0xA020,"Address"); |
hux | 27:32267cee7cb8 | 24 | // Characteristic<ObjectId> chrId (address, 0xA021, "na", "ID"); |
hux | 27:32267cee7cb8 | 25 | // Characteristic<ObjectName> chrName (address, 0xA022, "na", "Name"); |
hux | 27:32267cee7cb8 | 26 | // Characteristic<Bool> chrLayout (address, 0xA023, "na", "Layout"); |
hux | 27:32267cee7cb8 | 27 | |
hux | 27:32267cee7cb8 | 28 | UserDescriptor(nameId,attId,dscId,"ID") |
hux | 27:32267cee7cb8 | 29 | static WriteOnlyGattCharacteristic<ObjectId> chrId(0xA021,ini.pObjectId(),0,dscId,1); |
hux | 27:32267cee7cb8 | 30 | |
hux | 27:32267cee7cb8 | 31 | UserDescriptor(nameName,attName,dscName,"Name") |
hux | 27:32267cee7cb8 | 32 | static ReadOnlyGattCharacteristic<ObjectName> chrName(0xA022,ini.pObjectName(),0,dscName,1); |
hux | 27:32267cee7cb8 | 33 | |
hux | 27:32267cee7cb8 | 34 | UserDescriptor(nameLayout,attLayout,dscLayout,"Layout") |
hux | 27:32267cee7cb8 | 35 | static ReadOnlyGattCharacteristic<ObjectName> chrLayout(0xA023,ini.pObjectName(),0,dscLayout,1); |
hux | 27:32267cee7cb8 | 36 | |
hux | 27:32267cee7cb8 | 37 | static GattCharacteristic *addressList[] = {&chrId,&chrName,&chrLayout}; |
hux | 27:32267cee7cb8 | 38 | static GattService address(0xA020, addressList, GattListLength(addressList)); |
hux | 27:32267cee7cb8 | 39 | |
hux | 27:32267cee7cb8 | 40 | // Debug Service |
hux | 27:32267cee7cb8 | 41 | // |
hux | 27:32267cee7cb8 | 42 | // Service debug(0xA030,"Debug"); |
hux | 27:32267cee7cb8 | 43 | // Characteristic<Bool> chrTest (debug, 0xA031, "w", "Test"); |
hux | 27:32267cee7cb8 | 44 | // Characteristic<DateTime> chrTimestamp (debug, 0xA032, "r", "Timestamp"); |
hux | 27:32267cee7cb8 | 45 | |
hux | 27:32267cee7cb8 | 46 | UserDescriptor(nameTest,attTest,dscTest,"Test") |
hux | 27:32267cee7cb8 | 47 | static WriteOnlyGattCharacteristic<Bool> chrTest(0xA031,ini.pBool(),0,dscTest,1); |
hux | 27:32267cee7cb8 | 48 | |
hux | 27:32267cee7cb8 | 49 | UserDescriptor(nameTimeStamp,attTimeStamp,dscTimeStamp,"TimeStamp") |
hux | 27:32267cee7cb8 | 50 | static ReadOnlyGattCharacteristic<DateTime> chrTimeStamp(0xA032,ini.pDateTime(),0,dscTimeStamp,1); |
hux | 27:32267cee7cb8 | 51 | |
hux | 27:32267cee7cb8 | 52 | static GattCharacteristic *debugList[] = {&chrTest,&chrTimeStamp}; |
hux | 27:32267cee7cb8 | 53 | static GattService debug(0xA030, debugList, GattListLength(debugList)); |
hux | 27:32267cee7cb8 | 54 | |
hux | 27:32267cee7cb8 | 55 | |
hux | 27:32267cee7cb8 | 56 | //============================================================================== |
hux | 27:32267cee7cb8 | 57 | // Update Callback |
hux | 27:32267cee7cb8 | 58 | //============================================================================== |
hux | 27:32267cee7cb8 | 59 | |
hux | 27:32267cee7cb8 | 60 | static void cbWritten(Blob &o) // handle updates |
hux | 27:32267cee7cb8 | 61 | { |
hux | 27:32267cee7cb8 | 62 | Bool value; |
hux | 27:32267cee7cb8 | 63 | |
hux | 27:32267cee7cb8 | 64 | if (updated(o,chrTest)) // has chrTest been updated? |
hux | 27:32267cee7cb8 | 65 | { |
hux | 27:32267cee7cb8 | 66 | get(o,chrTest,value); // get value of chrTest |
hux | 27:32267cee7cb8 | 67 | set(o,chrPresence,value); // and store this value to chrPresence |
hux | 27:32267cee7cb8 | 68 | |
hux | 27:32267cee7cb8 | 69 | print(o,value,"test"); |
hux | 27:32267cee7cb8 | 70 | if (value == 0) |
hux | 27:32267cee7cb8 | 71 | blinkConnected(o,"x x "); |
hux | 27:32267cee7cb8 | 72 | else if (value == 1) |
hux | 27:32267cee7cb8 | 73 | blinkConnected(o,"xxx xxx "); |
hux | 27:32267cee7cb8 | 74 | else |
hux | 27:32267cee7cb8 | 75 | blinkConnected(o,"x xxx x xxx "); |
hux | 27:32267cee7cb8 | 76 | } |
hux | 27:32267cee7cb8 | 77 | else if (updated(o,chrPresence)) // has chrPresence been updated? |
hux | 27:32267cee7cb8 | 78 | { |
hux | 27:32267cee7cb8 | 79 | get(o,chrPresence,value); |
hux | 27:32267cee7cb8 | 80 | print(o,value,"test"); |
hux | 27:32267cee7cb8 | 81 | } |
hux | 27:32267cee7cb8 | 82 | } |
hux | 27:32267cee7cb8 | 83 | |
hux | 27:32267cee7cb8 | 84 | //============================================================================== |
hux | 27:32267cee7cb8 | 85 | // Register Services and Callbacks |
hux | 27:32267cee7cb8 | 86 | //============================================================================== |
hux | 27:32267cee7cb8 | 87 | |
hux | 27:32267cee7cb8 | 88 | void tediousServices(Blob &o) // enroll all services & characteristics |
hux | 27:32267cee7cb8 | 89 | { |
hux | 27:32267cee7cb8 | 90 | enroll(o,detection,0xA010); |
hux | 27:32267cee7cb8 | 91 | enroll(o,address,0xA020); |
hux | 27:32267cee7cb8 | 92 | enroll(o,debug,0xA030); |
hux | 27:32267cee7cb8 | 93 | |
hux | 27:32267cee7cb8 | 94 | onWritten(o,cbWritten); // setup 'data written' callback |
hux | 27:32267cee7cb8 | 95 | } |
hux | 27:32267cee7cb8 | 96 | |
hux | 27:32267cee7cb8 | 97 | //eof |