A blue button is always a nice toy ...

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Sun Oct 01 12:49:25 2017 +0000
Revision:
29:a6b74dfdd5f2
A blue button is always a nice toy ...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 29:a6b74dfdd5f2 1 // init.cpp - initialize BLE system
hux 29:a6b74dfdd5f2 2
hux 29:a6b74dfdd5f2 3 #include "bricks/init.h"
hux 29:a6b74dfdd5f2 4 #include "bricks/blinker.h"
hux 29:a6b74dfdd5f2 5 #include "bricks/trace.h"
hux 29:a6b74dfdd5f2 6
hux 29:a6b74dfdd5f2 7 static void (*cbSetup)(O&o) = 0; // setup callback
hux 29:a6b74dfdd5f2 8 static void (*cbError)(O&o) = 0; // error callback
hux 29:a6b74dfdd5f2 9
hux 29:a6b74dfdd5f2 10 static void cbDefaultError(O&o) // default error handler
hux 29:a6b74dfdd5f2 11 {
hux 29:a6b74dfdd5f2 12 Blinker blink;
hux 29:a6b74dfdd5f2 13 blink.error(); // 'error' blink sequence
hux 29:a6b74dfdd5f2 14 }
hux 29:a6b74dfdd5f2 15
hux 29:a6b74dfdd5f2 16 static void cbDefaultComplete(O&o) // default error handler
hux 29:a6b74dfdd5f2 17 {
hux 29:a6b74dfdd5f2 18 // empty
hux 29:a6b74dfdd5f2 19 }
hux 29:a6b74dfdd5f2 20
hux 29:a6b74dfdd5f2 21 static void initComplete(BLE::InitializationCompleteCallbackContext *params)
hux 29:a6b74dfdd5f2 22 {
hux 29:a6b74dfdd5f2 23 Blob o; // setup a blob
hux 29:a6b74dfdd5f2 24 o.pComplete = params; // store to provide access
hux 29:a6b74dfdd5f2 25
hux 29:a6b74dfdd5f2 26 // params->error = (ble_error_t)((int)BLE_ERROR_NONE+1); // uncomment for debug
hux 29:a6b74dfdd5f2 27
hux 29:a6b74dfdd5f2 28 trace(o,2,"<initialized>\n");
hux 29:a6b74dfdd5f2 29
hux 29:a6b74dfdd5f2 30 if (params->error != BLE_ERROR_NONE)
hux 29:a6b74dfdd5f2 31 {
hux 29:a6b74dfdd5f2 32 trace(o,0,"error\n");
hux 29:a6b74dfdd5f2 33 if (cbError)
hux 29:a6b74dfdd5f2 34 (*cbError)(o); // handle error in follow-up
hux 29:a6b74dfdd5f2 35
hux 29:a6b74dfdd5f2 36 return;
hux 29:a6b74dfdd5f2 37 }
hux 29:a6b74dfdd5f2 38
hux 29:a6b74dfdd5f2 39 // Ensure that it is the default instance of BLE
hux 29:a6b74dfdd5f2 40
hux 29:a6b74dfdd5f2 41 if(o.getInstanceID() != BLE::DEFAULT_INSTANCE)
hux 29:a6b74dfdd5f2 42 {
hux 29:a6b74dfdd5f2 43 return;
hux 29:a6b74dfdd5f2 44 }
hux 29:a6b74dfdd5f2 45
hux 29:a6b74dfdd5f2 46 (*cbSetup)(o); // followup with setup
hux 29:a6b74dfdd5f2 47 }
hux 29:a6b74dfdd5f2 48
hux 29:a6b74dfdd5f2 49
hux 29:a6b74dfdd5f2 50 void init(O&o, void (*scb)(O&o),void (*ecb)(O&o)) // init BLE system
hux 29:a6b74dfdd5f2 51 {
hux 29:a6b74dfdd5f2 52 cbSetup = scb; // store setup callback
hux 29:a6b74dfdd5f2 53 cbError = ecb; // store error callback
hux 29:a6b74dfdd5f2 54 o.init(initComplete);
hux 29:a6b74dfdd5f2 55 }
hux 29:a6b74dfdd5f2 56
hux 29:a6b74dfdd5f2 57
hux 29:a6b74dfdd5f2 58 void init(O&o, void (*scb)(O&o)) // initialize BLE system
hux 29:a6b74dfdd5f2 59 {
hux 29:a6b74dfdd5f2 60 init(o,scb,cbDefaultError); // continue with default error callback
hux 29:a6b74dfdd5f2 61 }
hux 29:a6b74dfdd5f2 62
hux 29:a6b74dfdd5f2 63 void init(O&o) // initialize BLE system
hux 29:a6b74dfdd5f2 64 {
hux 29:a6b74dfdd5f2 65 init(o,cbDefaultComplete,cbDefaultError);
hux 29:a6b74dfdd5f2 66 while (!o.hasInitialized())
hux 29:a6b74dfdd5f2 67 {
hux 29:a6b74dfdd5f2 68 trace(o,1,"waiting for initialized BLE!\n");
hux 29:a6b74dfdd5f2 69 wait_ms(200);
hux 29:a6b74dfdd5f2 70 }
hux 29:a6b74dfdd5f2 71 }