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 20:49:58 2017 +0000
Revision:
24:0f08f68579bd
Parent:
23:677689000369
Child:
26:fd06c8b57d16
Version 1.0 - now satisfying behavior. No known 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 22:d467526abc4a 7
hux 22:d467526abc4a 8 #define ICCC BLE::InitializationCompleteCallbackContext // pure short hand
hux 22:d467526abc4a 9 #define GDCP Gap::DisconnectionCallbackParams_t // pure short hand
hux 22:d467526abc4a 10 #define GCCP Gap::ConnectionCallbackParams_t // pure short hand
hux 22:d467526abc4a 11 #define GWCP GattWriteCallbackParams // pure short hand
hux 22:d467526abc4a 12
hux 23:677689000369 13 #define GattListLength(list) (sizeof(list) / sizeof(GattCharacteristic *))
hux 23:677689000369 14
hux 22:d467526abc4a 15 typedef uint8_t byte;
hux 22:d467526abc4a 16 typedef const char *cptr;
hux 23:677689000369 17 typedef uint8_t Buffer[10];
hux 22:d467526abc4a 18
hux 22:d467526abc4a 19 class Blob
hux 22:d467526abc4a 20 {
hux 22:d467526abc4a 21 public:
hux 22:d467526abc4a 22 BLE *pble; // to access THE ble object
hux 22:d467526abc4a 23 const ICCC *pComplete; // params to ICCC context
hux 22:d467526abc4a 24 const GCCP *pConnect; // params to GCCP context
hux 22:d467526abc4a 25 const GDCP *pDisconnect; // params to GDPC context
hux 22:d467526abc4a 26 const GWCP *pWritten; // params to GWCP context
hux 22:d467526abc4a 27
hux 22:d467526abc4a 28 public:
hux 22:d467526abc4a 29 Blob(); // standard constructor
hux 22:d467526abc4a 30 void init(void (*)(Blob&),void (*)(Blob&)); // initialize BLE system
hux 22:d467526abc4a 31 void init(void (*)(Blob&)); // initialize BLE system
hux 22:d467526abc4a 32 void sleep(void); // low power wait
hux 22:d467526abc4a 33
hux 22:d467526abc4a 34 public: // some short hands (inline)
hux 22:d467526abc4a 35 GattServer& gatt() { return pble->gattServer(); }
hux 22:d467526abc4a 36
hux 22:d467526abc4a 37 public: // setup GAP advertising
hux 22:d467526abc4a 38 void device(const char *name); // set device name characteristic
hux 22:d467526abc4a 39
hux 22:d467526abc4a 40 // adding custom service
hux 22:d467526abc4a 41
hux 23:677689000369 42 void config(GattService &svc); // configure custom service
hux 22:d467526abc4a 43
hux 22:d467526abc4a 44 // advertising flags
hux 22:d467526abc4a 45
hux 22:d467526abc4a 46 void mode(const char *p); // Set advertising type and flags
hux 22:d467526abc4a 47 void data(const uint8_t*, size_t); // advertising data
hux 22:d467526abc4a 48 void data(const char *str); // advertising data
hux 22:d467526abc4a 49 void name(const char *str); // add name to device
hux 22:d467526abc4a 50 void start(void); // start advertising
hux 22:d467526abc4a 51 void start(int msec); // start advertising (msec: periode)
hux 24:0f08f68579bd 52 void peripheral(cptr pmod,int ms=100);// advertise as a peripheral
hux 22:d467526abc4a 53
hux 23:677689000369 54 void copy(GattCharacteristic &dst);
hux 23:677689000369 55 void get(GattCharacteristic &chr, Buffer &data);
hux 23:677689000369 56
hux 22:d467526abc4a 57 void onConnect(void (*fptr)(Blob&)); // setup disconnect callback
hux 22:d467526abc4a 58 void onDisconnect(void (*fptr)(Blob&));// setup disconnect callback
hux 22:d467526abc4a 59 void onWritten(void (*fptr)(Blob&)); // setup data written callback
hux 22:d467526abc4a 60 };
hux 22:d467526abc4a 61
hux 24:0f08f68579bd 62 // Setup Advertising Name (syntactic sugar)
hux 22:d467526abc4a 63
hux 24:0f08f68579bd 64 inline void name(Blob &o, const char *text)
hux 24:0f08f68579bd 65 {
hux 24:0f08f68579bd 66 o.name(text); // setup advertising name
hux 24:0f08f68579bd 67 }
hux 24:0f08f68579bd 68
hux 24:0f08f68579bd 69 // Setup Device Name (syntactic sugar)
hux 24:0f08f68579bd 70
hux 24:0f08f68579bd 71 inline void device(Blob &o, const char *text)
hux 24:0f08f68579bd 72 {
hux 24:0f08f68579bd 73 o.device(text); // setup device name
hux 24:0f08f68579bd 74 }
hux 22:d467526abc4a 75
hux 24:0f08f68579bd 76 // Setup Advertising Data (syntactic sugar)
hux 24:0f08f68579bd 77
hux 24:0f08f68579bd 78 inline void data(Blob &o, const char *text)
hux 24:0f08f68579bd 79 {
hux 24:0f08f68579bd 80 o.data(text); // setup advertising data
hux 24:0f08f68579bd 81 }
hux 24:0f08f68579bd 82
hux 24:0f08f68579bd 83 // Start Advertising in Peripheral Mode
hux 24:0f08f68579bd 84
hux 24:0f08f68579bd 85 inline void peripheral(Blob &o, const char *mode, int msec)
hux 24:0f08f68579bd 86 {
hux 24:0f08f68579bd 87 o.peripheral(mode,msec); // start advertising as a peripheral
hux 24:0f08f68579bd 88 }
hux 24:0f08f68579bd 89
hux 22:d467526abc4a 90 #endif // _BLOB_H_