A blue button is always a nice toy ...
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: bricks/blob.h
- Revision:
- 22:d467526abc4a
- Child:
- 23:677689000369
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bricks/blob.h Sun Dec 18 05:33:58 2016 +0000 @@ -0,0 +1,84 @@ +// blob.cpp - 'BLOBs' are BLuetooth OBjects +#ifndef _BLOB_H_ +#define _BLOB_H_ + +#include "ble/BLE.h" +#include "ble/Gap.h" + +#define ICCC BLE::InitializationCompleteCallbackContext // pure short hand +#define GDCP Gap::DisconnectionCallbackParams_t // pure short hand +#define GCCP Gap::ConnectionCallbackParams_t // pure short hand +#define GWCP GattWriteCallbackParams // pure short hand + + typedef uint8_t byte; + typedef const char *cptr; + + class Service + { + public: + GattService *pService; + + private: + GattCharacteristic **pCharacteristics; + int count; + uint16_t uuid; + + public: + Service(uint16_t uid); + void add(GattCharacteristic *p); + GattService *create(); // actual creation of GATT service + }; + + class Characteristic + { + public: + GattCharacteristic *pc; + Characteristic(Service &svc, uint16_t uuid, cptr mode, cptr name); + Characteristic(Service &svc, uint16_t uuid, cptr mode); + }; + + + class Blob + { + public: + BLE *pble; // to access THE ble object + const ICCC *pComplete; // params to ICCC context + const GCCP *pConnect; // params to GCCP context + const GDCP *pDisconnect; // params to GDPC context + const GWCP *pWritten; // params to GWCP context + + public: + Blob(); // standard constructor + void init(void (*)(Blob&),void (*)(Blob&)); // initialize BLE system + void init(void (*)(Blob&)); // initialize BLE system + void sleep(void); // low power wait + + public: // some short hands (inline) + GattServer& gatt() { return pble->gattServer(); } + + public: // setup GAP advertising + void device(const char *name); // set device name characteristic + + // adding custom service + + void service(Service &svc); // add custom service + void service(GattService &svc); // add custom service + + // advertising flags + + void mode(const char *p); // Set advertising type and flags + void data(const uint8_t*, size_t); // advertising data + void data(const char *str); // advertising data + void name(const char *str); // add name to device + void start(void); // start advertising + void start(int msec); // start advertising (msec: periode) + void advertise(cptr pmod,int ms=100);// advertise + + void onConnect(void (*fptr)(Blob&)); // setup disconnect callback + void onDisconnect(void (*fptr)(Blob&));// setup disconnect callback + void onWritten(void (*fptr)(Blob&)); // setup data written callback + }; + + + +#endif // _BLOB_H_ \ No newline at end of file