Hugo Pristauz / Mbed 2 deprecated S16_Blue_ToF

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers callback.cpp Source File

callback.cpp

00001 // callback.cpp - deal with callbacks
00002 
00003 #include "bricks/blob.h"
00004 #include "bricks/callback.h"
00005 #include "bricks/trace.h" 
00006    
00007 //==============================================================================
00008 // Setup Data Written Callback
00009 //==============================================================================
00010    
00011    static void (*cbWritten)(O&o) = 0;       // where we have to follow up 
00012 
00013       // default onDataWritten callback
00014 
00015    static void dfWritten(const GattWriteCallbackParams *params)
00016    {
00017       O o;                                  // setup a blob
00018       o.pWritten = params;                  // store to provide access
00019 
00020       trace(o,2,"<data written>\n");
00021 
00022       if (cbWritten)
00023          (*cbWritten)(o);                   // user callback follow-up
00024    }
00025 
00026 
00027    void onWritten(O&o, void (*fptr)(O&o))   // setup data written callback
00028    {
00029       cbWritten = fptr;                     // remember function to follow-up
00030       o.gattServer().onDataWritten(dfWritten);// actual calback setup in GATT
00031    }
00032 
00033 //==============================================================================
00034 // Setup Connection Callback
00035 //==============================================================================
00036 
00037    static void (*cbConnect)(Blob&) = 0;// where we have to follow up 
00038 
00039       // default connection callback
00040       
00041    static void dfConnect(const Gap::ConnectionCallbackParams_t *params)
00042    {
00043       O o;                                    // setup a blob object
00044       o.pConnect = params;                    // store to provide access
00045       
00046       trace(o,2,"<connect>\n");
00047       
00048       if (cbConnect)
00049          (*cbConnect)(o);                     // user callback follow-up
00050    }
00051 
00052    void onConnect(O&o,void(*fptr)(O&))        // setup connection callback
00053    {
00054       cbConnect = fptr;                       // remember function to follow-up
00055       o.gap().onConnection(dfConnect);        // actual callback setup in GAP
00056    }
00057    
00058 //==============================================================================
00059 // Setup Disconnection Callback
00060 //==============================================================================
00061 
00062    static void (*cbDisconnect)(O&o) = 0;    // where we have to follow up 
00063 
00064       // default disconnection callback
00065       
00066    static void dfDisconnect(const Gap::DisconnectionCallbackParams_t *params)
00067    {
00068       Blob o;                               // setup a blob
00069       o.pDisconnect = params;               // store to provide access
00070       
00071       trace(o,2,"<disconnected>\n");
00072 
00073       if (cbDisconnect)
00074          (*cbDisconnect)(o);                // user callback follow-up
00075    }
00076 
00077    void onDisconnect(O&o,void(*fptr)(O&o))  // setup disconnection callback
00078    {
00079       cbDisconnect = fptr;                  // remember function to follow-up
00080       
00081       o.gap().onDisconnection(dfDisconnect);// actualcallback setup in GAP
00082    }
00083