Bluetooth Connected TOF Sensor

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Fri Jan 06 15:28:18 2017 +0000
Revision:
23:677689000369
Already nice & easy level. Still bugs!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 23:677689000369 1 // collection.h - used to setup a collection of characteristics in order to
hux 23:677689000369 2 // setup a service.
hux 23:677689000369 3 //
hux 23:677689000369 4 // Description:
hux 23:677689000369 5 // Collections are used to setup a service comprising a collection of
hux 23:677689000369 6 // characteristics. The setup sequence starts with declaring a collection
hux 23:677689000369 7 // (this constructs an empty collection) while passing the collection in-
hux 23:677689000369 8 // stance repeatedly to a constructor of a characteristic, which auto-adds
hux 23:677689000369 9 // the new constructed characteristics to the collection. Finally, when the
hux 23:677689000369 10 // collection instance is passed to a service constructor, the service con-
hux 23:677689000369 11 // structor is able to access all characteristics which have been collected
hux 23:677689000369 12 // previously.
hux 23:677689000369 13 //
hux 23:677689000369 14 // Example 1: A protocol might be declared as a class as follows
hux 23:677689000369 15 //
hux 23:677689000369 16 // Collection col; // collection used during setup
hux 23:677689000369 17 //
hux 23:677689000369 18 // Characteristic<ObjectId> id(col,0x2AC3,"rw","ID");
hux 23:677689000369 19 // Characteristic<ObjectName> name(col,0x2ABE,"rw","Name");
hux 23:677689000369 20 // Characteristic<Digital> presence(col,0x2A56,"r","Presence");
hux 23:677689000369 21 //
hux 23:677689000369 22 // Service presenceDetection(col,0xA001); // instantiate service
hux 23:677689000369 23 //
hux 23:677689000369 24 // onSetup(Blob &blue)
hux 23:677689000369 25 // {
hux 23:677689000369 26 // blue.service(presenceDetection); // add service
hux 23:677689000369 27 // }
hux 23:677689000369 28 //
hux 23:677689000369 29 // Example 2: service definition by means of a service definition class
hux 23:677689000369 30 //
hux 23:677689000369 31 // class PresenceDetector
hux 23:677689000369 32 // {
hux 23:677689000369 33 // public:
hux 23:677689000369 34 // Collection col; // collection used during setup
hux 23:677689000369 35 //
hux 23:677689000369 36 // Characteristic<ObjectId> id; // ID of presence detector
hux 23:677689000369 37 // Characteristic<ObjectName> name; // name of presence detector
hux 23:677689000369 38 // Characteristic<Digital> presence; // digital presence value
hux 23:677689000369 39 // Characteristic<DateTime> timestamp; // last detection change's time
hux 23:677689000369 40 // Characteristic<ObjectName> layout; // name of model railway layout
hux 23:677689000369 41 //
hux 23:677689000369 42 // Service presenceDetection; // the service
hux 23:677689000369 43 //
hux 23:677689000369 44 // public:
hux 23:677689000369 45 // PresenceDetector(Blob &blue, cost UUID uuid) :
hux 23:677689000369 46 // list; // init service list
hux 23:677689000369 47 // id(list,0x2AC3,"rw","ID"), // instantiate characteristic
hux 23:677689000369 48 // name(list,0x2ABE,"rw","Name"), // instantiate characteristic
hux 23:677689000369 49 // presence(list,0x2A56,"r","Presence"),// instantiate characteristic
hux 23:677689000369 50 // timestamp(list,0x2A08,"r","Timestamp"),// instantiate characteristic
hux 23:677689000369 51 // layout(list,0x2ABE,"rw","Layout"), // instantiate characteristic
hux 23:677689000369 52 // presenceDetection(list,uuid) // instantiate service
hux 23:677689000369 53 // {
hux 23:677689000369 54 // blue.service(presenceDetection); // add service
hux 23:677689000369 55 // }
hux 23:677689000369 56 // };
hux 23:677689000369 57 //
hux 23:677689000369 58 #ifndef _COLLECTION_H_
hux 23:677689000369 59 #define _COLLECTION_H_
hux 23:677689000369 60
hux 23:677689000369 61 #include "ble/BLE.h"
hux 23:677689000369 62 #include "ble/Gap.h"
hux 23:677689000369 63
hux 23:677689000369 64 class Collection
hux 23:677689000369 65 {
hux 23:677689000369 66 private:
hux 23:677689000369 67 typedef GattCharacteristic *GattCharPtr;
hux 23:677689000369 68
hux 23:677689000369 69 public:
hux 23:677689000369 70 GattCharacteristic **plist;
hux 23:677689000369 71 int count;
hux 23:677689000369 72
hux 23:677689000369 73 Collection() // construct empty collection
hux 23:677689000369 74 {
hux 23:677689000369 75 plist = 0; count = 0; // init properties
hux 23:677689000369 76 }
hux 23:677689000369 77
hux 23:677689000369 78 void add(GattCharPtr p)
hux 23:677689000369 79 {
hux 23:677689000369 80 GattCharPtr *pnew = new GattCharPtr[count+1];
hux 23:677689000369 81 pnew[count] = p; // add new characteristic
hux 23:677689000369 82
hux 23:677689000369 83 if (count > 0)
hux 23:677689000369 84 { for (int i=0; i < count; i++)
hux 23:677689000369 85 pnew[i] = plist[i];
hux 23:677689000369 86 delete plist;
hux 23:677689000369 87 }
hux 23:677689000369 88 plist = pnew; // update list pointer
hux 23:677689000369 89 count++;
hux 23:677689000369 90 }
hux 23:677689000369 91 };
hux 23:677689000369 92
hux 23:677689000369 93 #endif // _COLLECTION_H_