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 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-23 22:33:52 +02:00
co-authored by Claude Opus 5.5
parent 467d64af40
commit d2e1f086e2
4 changed files with 21 additions and 4 deletions
@@ -7,6 +7,8 @@
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LPPDataHelpers.h>
#include <helpers/sensors/LocationProvider.h>
#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");
@@ -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();
+2 -2
View File
@@ -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)) {
@@ -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[] = {