diff --git a/ble/BLE.h b/ble/BLE.h index a406ce6..5484c40 100644 --- a/ble/BLE.h +++ b/ble/BLE.h @@ -1126,7 +1126,7 @@ public: * to ble.onRadioNotification(...) should be replaced with * ble.gap().onRadioNotification(...). */ - void onRadioNotification(Gap::RadioNotificationEventCallback_t callback) { + void onRadioNotification(void (*callback)(bool)) { gap().onRadioNotification(callback); } diff --git a/ble/Gap.h b/ble/Gap.h index 179d00e..ea76ef0 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -141,7 +141,7 @@ public: typedef void (*TimeoutEventCallback_t)(TimeoutSource_t source); typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params); typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t); - typedef void (*RadioNotificationEventCallback_t)(bool radio_active); /* gets passed true for ACTIVE; false for INACTIVE. */ + typedef FunctionPointerWithContext RadioNotificationEventCallback_t; /* * The following functions are meant to be overridden in the platform-specific sub-class. @@ -769,6 +769,27 @@ public: return err; } + /** + * Initialize radio-notification events to be generated from the stack. + * This API doesn't need to be called directly; + * + * Radio Notification is a feature that enables ACTIVE and INACTIVE + * (nACTIVE) signals from the stack that notify the application when the + * radio is in use. + * + * The ACTIVE signal is sent before the Radio Event starts. The nACTIVE + * signal is sent at the end of the Radio Event. These signals can be used + * by the application programmer to synchronize application logic with radio + * activity. For example, the ACTIVE signal can be used to shut off external + * devices to manage peak current drawn during periods when the radio is on, + * or to trigger sensor data collection for transmission in the Radio Event. + * + * @return BLE_ERROR_NONE on successful initialization, otherwise an error code. + */ + virtual ble_error_t initRadioNotification(void) { + return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */ + } + private: ble_error_t setAdvertisingData(void) { return setAdvertisingData(_advPayload, _scanResponse); @@ -834,7 +855,7 @@ public: * * Radio Notification is a feature that enables ACTIVE and INACTIVE * (nACTIVE) signals from the stack that notify the application when the - * radio is in use. The signal is sent using software interrupt. + * radio is in use. * * The ACTIVE signal is sent before the Radio Event starts. The nACTIVE * signal is sent at the end of the Radio Event. These signals can be used @@ -846,8 +867,25 @@ public: * @param callback * The application handler to be invoked in response to a radio * ACTIVE/INACTIVE event. + * + * or in the other version: + * + * @param tptr + * Pointer to the object of a class defining the member callback + * function (mptr). + * @param mptr + * The member callback (within the context of an object) to be + * invoked in response to a radio ACTIVE/INACTIVE event. */ - virtual void onRadioNotification(RadioNotificationEventCallback_t callback) {radioNotificationCallback = callback;} + void onRadioNotification(void (*callback)(bool param)) { + radioNotificationCallback.attach(callback); + initRadioNotification(); + } + template + void onRadioNotification(T *tptr, void (T::*mptr)(bool)) { + radioNotificationCallback.attach(tptr, mptr); + initRadioNotification(); + } protected: Gap() :