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 init.cpp Source File

init.cpp

00001 // init.cpp - initialize BLE system
00002 
00003 #include "bricks/init.h"
00004 #include "bricks/blinker.h"
00005 #include "bricks/trace.h"
00006 
00007    static void (*cbSetup)(O&o) = 0;    // setup callback 
00008    static void (*cbError)(O&o) = 0;    // error callback 
00009 
00010    static void cbDefaultError(O&o)     // default error handler
00011    {
00012       Blinker blink;
00013       blink.error();                   // 'error' blink sequence
00014    }
00015 
00016    static void cbDefaultComplete(O&o)  // default error handler
00017    {
00018        // empty
00019    }
00020    
00021    static void initComplete(BLE::InitializationCompleteCallbackContext *params)
00022    {
00023       Blob o;                          // setup a blob
00024       o.pComplete = params;            // store to provide access
00025  
00026       // params->error = (ble_error_t)((int)BLE_ERROR_NONE+1);  // uncomment for debug
00027       
00028       trace(o,2,"<initialized>\n");
00029 
00030       if (params->error != BLE_ERROR_NONE)
00031       {
00032          trace(o,0,"error\n");
00033          if (cbError)
00034             (*cbError)(o);             // handle error in follow-up
00035             
00036          return;
00037       }
00038 
00039          // Ensure that it is the default instance of BLE
00040       
00041       if(o.getInstanceID() != BLE::DEFAULT_INSTANCE)
00042       {
00043          return;
00044       }
00045     
00046       (*cbSetup)(o);                   // followup with setup
00047    }
00048 
00049 
00050    void init(O&o, void (*scb)(O&o),void (*ecb)(O&o))   // init BLE system
00051    {
00052       cbSetup = scb;                   // store setup callback
00053       cbError = ecb;                   // store error callback
00054       o.init(initComplete);
00055    }
00056 
00057 
00058    void init(O&o, void (*scb)(O&o))    // initialize BLE system
00059    {
00060       init(o,scb,cbDefaultError);      // continue with default error callback
00061    }
00062 
00063    void init(O&o)                      // initialize BLE system
00064    {
00065       init(o,cbDefaultComplete,cbDefaultError); 
00066       while (!o.hasInitialized())
00067       {
00068          trace(o,1,"waiting for initialized BLE!\n");
00069          wait_ms(200);
00070       }
00071    }