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
Parent:
22:d467526abc4a
Child:
24:0f08f68579bd
Already nice & easy level. Still bugs!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 22:d467526abc4a 1 // blob.cpp - 'BLOBs' are BLuetooth OBjects
hux 22:d467526abc4a 2 #ifndef _BLOB_H_
hux 22:d467526abc4a 3 #define _BLOB_H_
hux 22:d467526abc4a 4
hux 22:d467526abc4a 5 #include "ble/BLE.h"
hux 22:d467526abc4a 6 #include "ble/Gap.h"
hux 23:677689000369 7 #include "bricks/service.h"
hux 22:d467526abc4a 8
hux 22:d467526abc4a 9 #define ICCC BLE::InitializationCompleteCallbackContext // pure short hand
hux 22:d467526abc4a 10 #define GDCP Gap::DisconnectionCallbackParams_t // pure short hand
hux 22:d467526abc4a 11 #define GCCP Gap::ConnectionCallbackParams_t // pure short hand
hux 22:d467526abc4a 12 #define GWCP GattWriteCallbackParams // pure short hand
hux 22:d467526abc4a 13
hux 23:677689000369 14 #define GattListLength(list) (sizeof(list) / sizeof(GattCharacteristic *))
hux 23:677689000369 15
hux 22:d467526abc4a 16 typedef uint8_t byte;
hux 22:d467526abc4a 17 typedef const char *cptr;
hux 23:677689000369 18 typedef uint8_t Buffer[10];
hux 22:d467526abc4a 19
hux 22:d467526abc4a 20 class Blob
hux 22:d467526abc4a 21 {
hux 22:d467526abc4a 22 public:
hux 22:d467526abc4a 23 BLE *pble; // to access THE ble object
hux 22:d467526abc4a 24 const ICCC *pComplete; // params to ICCC context
hux 22:d467526abc4a 25 const GCCP *pConnect; // params to GCCP context
hux 22:d467526abc4a 26 const GDCP *pDisconnect; // params to GDPC context
hux 22:d467526abc4a 27 const GWCP *pWritten; // params to GWCP context
hux 22:d467526abc4a 28
hux 22:d467526abc4a 29 public:
hux 22:d467526abc4a 30 Blob(); // standard constructor
hux 22:d467526abc4a 31 void init(void (*)(Blob&),void (*)(Blob&)); // initialize BLE system
hux 22:d467526abc4a 32 void init(void (*)(Blob&)); // initialize BLE system
hux 22:d467526abc4a 33 void sleep(void); // low power wait
hux 22:d467526abc4a 34
hux 22:d467526abc4a 35 public: // some short hands (inline)
hux 22:d467526abc4a 36 GattServer& gatt() { return pble->gattServer(); }
hux 22:d467526abc4a 37
hux 22:d467526abc4a 38 public: // setup GAP advertising
hux 22:d467526abc4a 39 void device(const char *name); // set device name characteristic
hux 22:d467526abc4a 40
hux 22:d467526abc4a 41 // adding custom service
hux 22:d467526abc4a 42
hux 23:677689000369 43 void config(Service &svc); // configure custom service
hux 23:677689000369 44 void config(GattService &svc); // configure custom service
hux 22:d467526abc4a 45
hux 22:d467526abc4a 46 // advertising flags
hux 22:d467526abc4a 47
hux 22:d467526abc4a 48 void mode(const char *p); // Set advertising type and flags
hux 22:d467526abc4a 49 void data(const uint8_t*, size_t); // advertising data
hux 22:d467526abc4a 50 void data(const char *str); // advertising data
hux 22:d467526abc4a 51 void name(const char *str); // add name to device
hux 22:d467526abc4a 52 void start(void); // start advertising
hux 22:d467526abc4a 53 void start(int msec); // start advertising (msec: periode)
hux 22:d467526abc4a 54 void advertise(cptr pmod,int ms=100);// advertise
hux 22:d467526abc4a 55
hux 23:677689000369 56 void copy(GattCharacteristic &dst);
hux 23:677689000369 57 void get(GattCharacteristic &chr, Buffer &data);
hux 23:677689000369 58
hux 22:d467526abc4a 59 void onConnect(void (*fptr)(Blob&)); // setup disconnect callback
hux 22:d467526abc4a 60 void onDisconnect(void (*fptr)(Blob&));// setup disconnect callback
hux 22:d467526abc4a 61 void onWritten(void (*fptr)(Blob&)); // setup data written callback
hux 22:d467526abc4a 62 };
hux 22:d467526abc4a 63
hux 22:d467526abc4a 64
hux 22:d467526abc4a 65
hux 22:d467526abc4a 66 #endif // _BLOB_H_