Bluetooth Connected TOF Sensor

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

bricks/blob.h

Committer:
hux
Date:
2017-01-06
Revision:
23:677689000369
Parent:
22:d467526abc4a
Child:
24:0f08f68579bd

File content as of revision 23:677689000369:

// blob.cpp - 'BLOBs' are BLuetooth OBjects
#ifndef _BLOB_H_
#define _BLOB_H_

#include "ble/BLE.h"
#include "ble/Gap.h"
#include "bricks/service.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

#define GattListLength(list) (sizeof(list) / sizeof(GattCharacteristic *))

   typedef uint8_t byte;
   typedef const char *cptr;
   typedef uint8_t Buffer[10];

   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 config(Service &svc);           // configure custom service
         void config(GattService &svc);       // configure 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 copy(GattCharacteristic &dst);
         void get(GattCharacteristic &chr, Buffer &data);

         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_