From d2e1f086e27b4eee825e6ce8f17cf3740d87df05 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:33:52 +0200 Subject: [PATCH] fix(ui): the chip's temperature when no sensor reads one The telemetry reply adds the MCU temperature, the screens read only the sensors: on a board without a temperature sensor (the L1) the app showed a temperature and the clock field '--'. The clock, Status and the L2's Home now fall back to the chip's, like the reply. The bot's !temp and {temp} still read only the sensors. Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/ui-core/Telemetry.h | 17 +++++++++++++++++ examples/companion_radio/ui-lvgl/HomeScreen.h | 2 +- examples/companion_radio/ui-new/HomeScreen.h | 4 ++-- examples/companion_radio/ui-new/StatusScreen.h | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/companion_radio/ui-core/Telemetry.h b/examples/companion_radio/ui-core/Telemetry.h index 1a75473f..a6fd35f6 100644 --- a/examples/companion_radio/ui-core/Telemetry.h +++ b/examples/companion_radio/ui-core/Telemetry.h @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include #include "Battery.h" @@ -64,6 +66,21 @@ static uint8_t lppType(uint8_t f) { // Read from the sensors, not the radio or GPS. static bool isSensor(uint8_t f) { return lppType(f) != 0; } +// The sensors' readings, plus the chip's own temperature (NaN where a board has +// none) when no sensor reads one: the telemetry reply sends it too, so a board +// without a temperature sensor shows on screen what the app shows. +static void querySensors(SensorManager& sm, float mcu_temp, CayenneLPP& lpp) { + sm.querySensors(0xFF, lpp); + if (isnan(mcu_temp)) return; + LPPReader r(lpp.getBuffer(), lpp.getSize()); + uint8_t ch, type; + while (r.readHeader(ch, type)) { + if (type == LPP_TEMPERATURE) return; + r.skipData(type); + } + lpp.addTemperature(TELEM_CHANNEL_SELF, mcu_temp); +} + // Altitude always in the small unit (never km / mi). static void altText(float m, bool imperial, const Style& st, char* v, int n) { snprintf(v, n, "%.0f%s%s", imperial ? m * 3.28084f : m, st.spaced ? " " : "", imperial ? "ft" : "m"); diff --git a/examples/companion_radio/ui-lvgl/HomeScreen.h b/examples/companion_radio/ui-lvgl/HomeScreen.h index 7d36e8e9..b0bdb737 100644 --- a/examples/companion_radio/ui-lvgl/HomeScreen.h +++ b/examples/companion_radio/ui-lvgl/HomeScreen.h @@ -621,7 +621,7 @@ void UITask::homeFieldText(uint8_t f, char* v, int n) { if (_sensors && (s_lpp_ms == 0 || millis() - s_lpp_ms > 5000)) { s_lpp_ms = millis() | 1; s_lpp.reset(); - _sensors->querySensors(0xFF, s_lpp); + telemetry::querySensors(*_sensors, board.getMCUTemperature(), s_lpp); } in.lpp = s_lpp.getBuffer(); in.lpp_len = s_lpp.getSize(); diff --git a/examples/companion_radio/ui-new/HomeScreen.h b/examples/companion_radio/ui-new/HomeScreen.h index acc76b3a..109a72ca 100644 --- a/examples/companion_radio/ui-new/HomeScreen.h +++ b/examples/companion_radio/ui-new/HomeScreen.h @@ -102,7 +102,7 @@ static void formatDashVal(uint8_t field, char* val, int val_len, uint16_t batt_m if (telemetry::isSensor(field)) { if (!lpp) { static CayenneLPP s_lpp(200); s_lpp.reset(); - { CardKBBusLock bus_lock; sensors.querySensors(0xFF, s_lpp); } + { CardKBBusLock bus_lock; telemetry::querySensors(sensors, board.getMCUTemperature(), s_lpp); } lpp = &s_lpp; } in.lpp = lpp->getBuffer(); @@ -650,7 +650,7 @@ class HomeScreen : public UIScreen { sensors_lpp.reset(); sensors_nb = 0; sensors_lpp.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f); - { CardKBBusLock bus_lock; sensors.querySensors(0xFF, sensors_lpp); } + { CardKBBusLock bus_lock; telemetry::querySensors(sensors, board.getMCUTemperature(), sensors_lpp); } LPPReader reader (sensors_lpp.getBuffer(), sensors_lpp.getSize()); uint8_t channel, type; while(reader.readHeader(channel, type)) { diff --git a/examples/companion_radio/ui-new/StatusScreen.h b/examples/companion_radio/ui-new/StatusScreen.h index ec08ebfb..46035125 100644 --- a/examples/companion_radio/ui-new/StatusScreen.h +++ b/examples/companion_radio/ui-new/StatusScreen.h @@ -237,7 +237,7 @@ private: // Sensors: every reading but the battery (above) and the position (GPS). if (!_lpp_at || millis() - _lpp_at > 5000) { // both passes (measure, draw) read one query _lpp.reset(); - { CardKBBusLock bus_lock; sensors.querySensors(0xFF, _lpp); } // shares the CardKB's bus + { CardKBBusLock bus_lock; telemetry::querySensors(sensors, board.getMCUTemperature(), _lpp); } // shares the CardKB's bus _lpp_at = millis() | 1; } static const struct { uint8_t type; const char* name; } NAMES[] = {