From fad1980f9814f6f57d2ca964cb0b6e7f4f20b929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Tue, 23 Sep 2025 20:57:48 +0200 Subject: [PATCH] TactilityC: Forgot the most important function, getting the unit string of course! --- TactilityC/Include/tt_hal_radio.h | 12 ++++++++++++ TactilityC/Source/tt_hal_radio.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/TactilityC/Include/tt_hal_radio.h b/TactilityC/Include/tt_hal_radio.h index 994b4dda..7d2a69bf 100644 --- a/TactilityC/Include/tt_hal_radio.h +++ b/TactilityC/Include/tt_hal_radio.h @@ -128,6 +128,18 @@ RadioParameterStatus tt_hal_radio_set_parameter(RadioHandle handle, RadioParamet */ RadioParameterStatus tt_hal_radio_get_parameter(RadioHandle handle, RadioParameter parameter, float *value); +/** + * Get the unit string of a parameter. + * If the parameter isn't available, the returned string is empty. + * If the unit string does not fit into the provided character array, + * it is truncated but always null terminated. + * @param[in] handle the radio driver handle + * @param[in] parameter the parameter + * @param[out] str character array to store the unit string into + * @param[in] maxSize the maximum size the array str can hold + */ +void tt_hal_radio_get_parameter_unit_str(RadioHandle handle, RadioParameter parameter, char str[], unsigned maxSize); + /** * Check whenever the radio driver object can transmit a certain modulation. * @param[in] handle the radio driver handle diff --git a/TactilityC/Source/tt_hal_radio.cpp b/TactilityC/Source/tt_hal_radio.cpp index bfccaed4..f9fa5f4c 100644 --- a/TactilityC/Source/tt_hal_radio.cpp +++ b/TactilityC/Source/tt_hal_radio.cpp @@ -69,6 +69,17 @@ extern "C" { return fromCpp(wrapper->device->getParameter(toCpp(parameter), *value)); } + void tt_hal_radio_get_parameter_unit_str(RadioHandle handle, RadioParameter parameter, char str[], unsigned maxSize) { + auto wrapper = static_cast(handle); + assert(str); + std::string unitString = wrapper->device->getParameterUnit(toCpp(parameter)).toString(); + size_t i = 0; + for (; i < (maxSize - 1); ++i) { + str[i] = unitString[i]; + } + str[i] = '\0'; + } + bool tt_hal_radio_can_transmit(RadioHandle handle, Modulation modulation) { auto wrapper = static_cast(handle); return wrapper->device->canTransmit(toCpp(modulation));