diff --git a/source/nRF5xn.cpp b/source/nRF5xn.cpp index d505753..1d673e9 100644 --- a/source/nRF5xn.cpp +++ b/source/nRF5xn.cpp @@ -77,12 +77,14 @@ const char *nRF5xn::getVersion(void) return versionString; } -ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t callback) +ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext callback) { if (initialized) { - if (callback) { - callback(BLE::Instance(instanceID), BLE_ERROR_ALREADY_INITIALIZED); - } + BLE::InitializationCompleteCallbackContext context = { + BLE::Instance(instanceID), + BLE_ERROR_ALREADY_INITIALIZED + }; + callback.call(&context); return BLE_ERROR_ALREADY_INITIALIZED; } @@ -92,9 +94,11 @@ ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, BLE::InitializationComple btle_init(); initialized = true; - if (callback) { - callback(BLE::Instance(instanceID), BLE_ERROR_NONE); - } + BLE::InitializationCompleteCallbackContext context = { + BLE::Instance(instanceID), + BLE_ERROR_NONE + }; + callback.call(&context); return BLE_ERROR_NONE; } diff --git a/source/nRF5xn.h b/source/nRF5xn.h index 105c0af..2dd13c9 100644 --- a/source/nRF5xn.h +++ b/source/nRF5xn.h @@ -34,7 +34,7 @@ public: nRF5xn(void); virtual ~nRF5xn(void); - virtual ble_error_t init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t); + virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext callback); virtual bool hasInitialized(void) const { return initialized; }