From 10b69564dfa0462385226cfd62c00804b545d302 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Tue, 26 Dec 2023 00:27:51 +0300 Subject: [PATCH] add crct.temperature --- Src/cyphal_application/CMakeLists.txt | 2 ++ Src/cyphal_application/README.md | 1 + Src/cyphal_application/lights/lights.cpp | 19 +++++++++++++------ Src/cyphal_application/lights/params.yaml | 5 +++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Src/cyphal_application/CMakeLists.txt b/Src/cyphal_application/CMakeLists.txt index 410b9a6..0aa6215 100644 --- a/Src/cyphal_application/CMakeLists.txt +++ b/Src/cyphal_application/CMakeLists.txt @@ -5,7 +5,9 @@ set(applicationSourceCode Src/cyphal_application/lights/lights.cpp Src/cyphal_application/application.cpp + Libs/Cyphal/Udral/rgbled.cpp + Libs/Cyphal/Udral/circuit_status.cpp ) set(applicationHeaders Src diff --git a/Src/cyphal_application/README.md b/Src/cyphal_application/README.md index 370c41e..b91a6fd 100644 --- a/Src/cyphal_application/README.md +++ b/Src/cyphal_application/README.md @@ -3,6 +3,7 @@ The node has the following interface: | № | Type | Message | Topic name | | -- | ---- | ------- | ----------- | | 1 | sub | reg.udral.physics.optics.HighColor.0.1 | lights | {'type': 'Port', 'data_type': 'reg.udral.physics.optics.HighColor.0.1', 'enum_base': 'RGBLED'}| +| 2 | pub | uavcan.si.sample.temperature.Scalar.1.0 | crct.temp | {'type': 'Port', 'data_type': 'uavcan.si.sample.temperature.Scalar.1.0', 'enum_base': 'PARAM_CRCT_TEMPERATURE'}| The node has the following registers: diff --git a/Src/cyphal_application/lights/lights.cpp b/Src/cyphal_application/lights/lights.cpp index 7d766f5..3c59be7 100644 --- a/Src/cyphal_application/lights/lights.cpp +++ b/Src/cyphal_application/lights/lights.cpp @@ -45,15 +45,22 @@ void RgbLights::update() { } next_time_ms = HAL_GetTick() + 10; + // Temperature + static const uint16_t TEMP_REF = 25; + static const uint16_t ADC_REF = 1750; ///< v_ref / 3.3 * 4095 + static const uint16_t AVG_SLOPE = 5; ///< avg_slope/(3.3/4096) + _temp_pub.setPortId(paramsGetIntegerValue(PARAM_CRCT_TEMPERATURE_ID)); + if (_temp_pub.isEnabled()) { + uint16_t adc_measurement = AdcPeriphery::get(AdcChannel::ADC_TEMPERATURE); + uavcan_si_sample_temperature_Scalar_1_0 msg; + msg.kelvin = (ADC_REF - adc_measurement) / AVG_SLOPE + TEMP_REF + 273; + _temp_pub.publish(msg); + } + + // Lights auto color = _rgbled_sub.get(); static Leds_Color_t leds; - // static uint8_t counter = 0; - // leds.colors[counter].shades.red = color.red * RED_SCALE; - // leds.colors[counter].shades.green = color.green * GREEN_SCALE; - // leds.colors[counter].shades.blue = color.blue * BLUE_SCALE; - // counter = (counter + 1) % 32; - for (uint_fast8_t led_idx = 0; led_idx < 32; led_idx++) { leds.colors[led_idx].shades.red = color.red * RED_SCALE; leds.colors[led_idx].shades.green = color.green * GREEN_SCALE; diff --git a/Src/cyphal_application/lights/params.yaml b/Src/cyphal_application/lights/params.yaml index 563a703..d1058b5 100644 --- a/Src/cyphal_application/lights/params.yaml +++ b/Src/cyphal_application/lights/params.yaml @@ -7,3 +7,8 @@ uavcan.sub.lights: type: Port data_type: reg.udral.physics.optics.HighColor.0.1 enum_base: RGBLED + +uavcan.pub.crct.temp: + type: Port + data_type: uavcan.si.sample.temperature.Scalar.1.0 + enum_base: PARAM_CRCT_TEMPERATURE