TactilityC: Add context to Radio HAL callbacks?
This commit is contained in:
parent
bf62c9670d
commit
65f450a0e0
@ -68,7 +68,7 @@ struct RadioTxPacket {
|
|||||||
uint32_t address;
|
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 (*RadioTxStateCallback)(RadioTxId id, RadioTxState state);
|
||||||
typedef void (*RadioOnReceiveCallback)(DeviceId id, const RadioRxPacket* packet);
|
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.
|
* Subscribe for any state change of the radio driver object.
|
||||||
* @param[in] handle the radio driver handle
|
* @param[in] handle the radio driver handle
|
||||||
* @param[in] callback function to call when the state of the radio changes
|
* @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
|
* @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.
|
* 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);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -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<DeviceWrapper*>(handle);
|
auto wrapper = static_cast<DeviceWrapper*>(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) {
|
if (callback) {
|
||||||
callback(id, fromCpp(state));
|
callback(id, fromCpp(state), ctx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -157,6 +157,11 @@ extern "C" {
|
|||||||
auto wrapper = static_cast<DeviceWrapper*>(handle);
|
auto wrapper = static_cast<DeviceWrapper*>(handle);
|
||||||
wrapper->device->unsubscribeRx(id);
|
wrapper->device->unsubscribeRx(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tt_hal_radio_unsubscribe_state(RadioHandle handle, RadioStateSubscriptionId id) {
|
||||||
|
auto wrapper = static_cast<DeviceWrapper*>(handle);
|
||||||
|
wrapper->device->unsubscribeStateChange(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static RadioState fromCpp(tt::hal::radio::RadioDevice::State state) {
|
static RadioState fromCpp(tt::hal::radio::RadioDevice::State state) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user