diff --git a/TactilityC/Include/tt_hal_radio.h b/TactilityC/Include/tt_hal_radio.h index 7c47d0b3..6521b52e 100644 --- a/TactilityC/Include/tt_hal_radio.h +++ b/TactilityC/Include/tt_hal_radio.h @@ -68,7 +68,7 @@ struct RadioTxPacket { uint32_t address; }; -typedef void (*RadioStateCallback)(DeviceId id, RadioState state); +typedef void (*RadioStateCallback)(DeviceId id, RadioState state, void* ctx); typedef void (*RadioTxStateCallback)(RadioTxId id, RadioTxState state); typedef void (*RadioOnReceiveCallback)(DeviceId id, const RadioRxPacket* packet); @@ -209,9 +209,10 @@ RadioRxSubscriptionId tt_hal_radio_subscribe_receive(RadioHandle handle, RadioOn * Subscribe for any state change of the radio driver object. * @param[in] handle the radio driver handle * @param[in] callback function to call when the state of the radio changes + * @param[in] ctx context which will be passed to the callback function * @return the identifier for the subscription */ -RadioStateSubscriptionId tt_hal_radio_subscribe_state(RadioHandle handle, RadioStateCallback callback); +RadioStateSubscriptionId tt_hal_radio_subscribe_state(RadioHandle handle, RadioStateCallback callback, void* ctx); /** * Unsubscribe for any received packet that the radio driver object receives. @@ -220,6 +221,13 @@ RadioStateSubscriptionId tt_hal_radio_subscribe_state(RadioHandle handle, RadioS */ void tt_hal_radio_unsubscribe_receive(RadioHandle handle, RadioRxSubscriptionId id); +/** + * Unsubscribe for any state change of the radio driver object. + * @param[in] handle the radio driver handle + * @param[in] id the identifier for the subscription + */ +void tt_hal_radio_unsubscribe_state(RadioHandle handle, RadioStateSubscriptionId id); + #ifdef __cplusplus } #endif diff --git a/TactilityC/Source/tt_hal_radio.cpp b/TactilityC/Source/tt_hal_radio.cpp index 58d4bd29..d6651b07 100644 --- a/TactilityC/Source/tt_hal_radio.cpp +++ b/TactilityC/Source/tt_hal_radio.cpp @@ -129,11 +129,11 @@ extern "C" { }); } - RadioStateSubscriptionId tt_hal_radio_subscribe_state(RadioHandle handle, RadioStateCallback callback) { + RadioStateSubscriptionId tt_hal_radio_subscribe_state(RadioHandle handle, RadioStateCallback callback, void* ctx) { auto wrapper = static_cast(handle); - return wrapper->device->subscribeStateChange([callback](tt::hal::Device::Id id, tt::hal::radio::RadioDevice::State state) { + return wrapper->device->subscribeStateChange([callback, ctx](tt::hal::Device::Id id, tt::hal::radio::RadioDevice::State state) { if (callback) { - callback(id, fromCpp(state)); + callback(id, fromCpp(state), ctx); } }); } @@ -157,6 +157,11 @@ extern "C" { auto wrapper = static_cast(handle); wrapper->device->unsubscribeRx(id); } + + void tt_hal_radio_unsubscribe_state(RadioHandle handle, RadioStateSubscriptionId id) { + auto wrapper = static_cast(handle); + wrapper->device->unsubscribeStateChange(id); + } } static RadioState fromCpp(tt::hal::radio::RadioDevice::State state) {