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:
Sat Jan 14 08:43:14 2017 +0000
Revision:
27:32267cee7cb8
Setup a GATT Detector Service. There is some bug in the GATT setup, resulting in different behavior between Nordic nRF51822-DK and NUCLEO-L476RG, but with the workaround it works also for the NUCLEO board. (using Bricks V1A)

Who changed what in which revision?

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