Merge remote-tracking branch 'origin/develop' into pr10715-fix

# Conflicts:
#	src/graphics/Screen.cpp
#	src/modules/Telemetry/Sensor/PMSA003ISensor.h
#	src/modules/Telemetry/Sensor/SCD30Sensor.h
#	src/modules/Telemetry/Sensor/SCD4XSensor.h
#	src/modules/Telemetry/Sensor/SEN5XSensor.cpp
#	src/modules/Telemetry/Sensor/SEN5XSensor.h
#	src/modules/Telemetry/Sensor/SFA30Sensor.h
This commit is contained in:
Thomas Göttgens
2026-07-03 11:12:16 +02:00
535 changed files with 20722 additions and 20884 deletions
@@ -262,6 +262,11 @@ void AirQualityTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSta
return;
}
// Same String(float) stack-overflow guard as EnvironmentTelemetry: form_formaldehyde is the only
// float rendered here, and its raw bytes are unvalidated on decode.
telemetry.variant.air_quality_metrics.form_formaldehyde =
UnitConversions::displaySafeFloat(telemetry.variant.air_quality_metrics.form_formaldehyde);
const auto &m = telemetry.variant.air_quality_metrics;
// Check if any telemetry field has valid data
+26 -3
View File
@@ -119,6 +119,10 @@ extern void drawCommonHeader(OLEDDisplay *display, int16_t x, int16_t y, const c
#include "Sensor/T1000xSensor.h"
#endif
#if __has_include(<Adafruit_SPA06_003.h>)
#include "Sensor/SPA06Sensor.h"
#endif
#ifdef SENSECAP_INDICATOR
#include "Sensor/IndicatorSensor.h"
#endif
@@ -167,12 +171,15 @@ void EnvironmentTelemetryModule::i2cScanFinished(ScanI2C *i2cScanner)
// Not a real I2C device, uses UART
addSensor<IndicatorSensor>(i2cScanner, ScanI2C::DeviceType::NONE);
#endif
addSensor<RCWL9620Sensor>(i2cScanner, ScanI2C::DeviceType::RCWL9620);
addSensor<CGRadSensSensor>(i2cScanner, ScanI2C::DeviceType::CGRADSENS);
#if HAS_SPA06 && __has_include(<Adafruit_SPA06_003.h>)
addSensor<SPA06Sensor>(i2cScanner, ScanI2C::DeviceType::SPA06);
#endif
#endif
#endif
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL
addSensor<RCWL9620Sensor>(i2cScanner, ScanI2C::DeviceType::RCWL9620);
addSensor<CGRadSensSensor>(i2cScanner, ScanI2C::DeviceType::CGRADSENS);
#if __has_include(<DFRobot_LarkWeatherStation.h>)
addSensor<DFRobotLarkSensor>(i2cScanner, ScanI2C::DeviceType::DFROBOT_LARK);
#endif
@@ -368,6 +375,22 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
return;
}
// Bound the float metrics before String(float) renders them (see UnitConversions::displaySafeFloat);
// the stored packet is always the environment variant.
{
auto &e = telemetry.variant.environment_metrics;
e.temperature = UnitConversions::displaySafeFloat(e.temperature);
e.relative_humidity = UnitConversions::displaySafeFloat(e.relative_humidity);
e.barometric_pressure = UnitConversions::displaySafeFloat(e.barometric_pressure);
e.voltage = UnitConversions::displaySafeFloat(e.voltage);
e.current = UnitConversions::displaySafeFloat(e.current);
e.lux = UnitConversions::displaySafeFloat(e.lux);
e.white_lux = UnitConversions::displaySafeFloat(e.white_lux);
e.weight = UnitConversions::displaySafeFloat(e.weight);
e.distance = UnitConversions::displaySafeFloat(e.distance);
e.radiation = UnitConversions::displaySafeFloat(e.radiation);
}
const auto &m = telemetry.variant.environment_metrics;
// Check if any telemetry field has valid data
@@ -436,7 +459,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
bool isCooldownOver = (now - lastAlertTime > 60000);
if (isOwnTelemetry && bannerMsg && isCooldownOver) {
LOG_INFO("drawFrame: IAQ %d (own) — showing banner: %s", m.iaq, bannerMsg);
LOG_INFO("drawFrame: IAQ %d (own) - showing banner: %s", m.iaq, bannerMsg);
screen->showSimpleBanner(bannerMsg, 3000);
// Only buzz if IAQ is over 200
@@ -39,4 +39,4 @@ class PMSA003ISensor : public TelemetrySensor
#endif
};
#endif
#endif
+1 -1
View File
@@ -52,4 +52,4 @@ class SCD30Sensor : public TelemetrySensor
meshtastic_AdminMessage *response) override;
};
#endif
#endif
+1 -1
View File
@@ -62,4 +62,4 @@ class SCD4XSensor : public TelemetrySensor
meshtastic_AdminMessage *response) override;
};
#endif
#endif
+2 -2
View File
@@ -338,7 +338,7 @@ bool SEN5XSensor::vocStateToSensor()
// Note: send command already takes into account the CRC
// buffer size increment needed
if (!sendCommand(SEN5X_RW_VOCS_STATE, vocState, SEN5X_VOC_STATE_BUFFER_SIZE)) {
LOG_ERROR("%s: Error sending VOC's state command'", sensorName);
LOG_ERROR("%s: Error sending VOC's state command", sensorName);
return false;
}
@@ -354,7 +354,7 @@ bool SEN5XSensor::vocStateFromSensor()
LOG_INFO("%s: Getting VOC state from sensor", sensorName);
// Ask VOCs state from the sensor
if (!sendCommand(SEN5X_RW_VOCS_STATE)) {
LOG_ERROR("%s: Error sending VOC's state command'", sensorName);
LOG_ERROR("%s: Error sending VOC's state command", sensorName);
return false;
}
+1 -1
View File
@@ -170,4 +170,4 @@ See: https://sensirion.com/resource/application_note/low_power_mode/sen5x
meshtastic_AdminMessage *response) override;
};
#endif
#endif
@@ -0,0 +1,60 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_SPA06_003.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "SPA06Sensor.h"
#include "TelemetrySensor.h"
#include <Adafruit_SPA06_003.h>
SPA06Sensor::SPA06Sensor()
: TelemetrySensor(meshtastic_TelemetrySensorType_SPA06, "SPA06"), spa_temp(nullptr), spa_pressure(nullptr)
{
}
bool SPA06Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
{
LOG_INFO("Init sensor: %s", sensorName);
status = spa06.begin(dev->address.address, bus);
if (!status) {
return status;
}
// Set moderate precision for faster sampling
spa06.setPressureOversampling(SPA06_003_OVERSAMPLE_8); // 8x oversampling
spa06.setTemperatureOversampling(SPA06_003_OVERSAMPLE_8); // 8x oversampling
// Set measurement rate. 1 Hz is ample for telemetry (polled every tens of seconds)
// and draws far less power than 32 Hz, while staying in continuous mode so getMetrics()
// remains non-blocking (fresh data always available).
spa06.setPressureMeasureRate(SPA06_003_RATE_1); // 1 Hz
spa06.setTemperatureMeasureRate(SPA06_003_RATE_1); // 1 Hz
spa06.setMeasurementMode(SPA06_003_MEAS_CONTINUOUS_BOTH);
spa_temp = spa06.getTemperatureSensor();
spa_pressure = spa06.getPressureSensor();
initI2CSensor();
return status;
}
bool SPA06Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
if (!spa_temp || !spa_pressure) {
return false;
}
sensors_event_t temp, press;
if (!spa_temp->getEvent(&temp) || !spa_pressure->getEvent(&press)) {
LOG_DEBUG("SPA06 getEvents no data");
return false;
}
measurement->variant.environment_metrics.has_temperature = true;
measurement->variant.environment_metrics.has_barometric_pressure = true;
measurement->variant.environment_metrics.temperature = temp.temperature;
measurement->variant.environment_metrics.barometric_pressure = press.pressure;
return true;
}
#endif
@@ -0,0 +1,22 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_SPA06_003.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include <Adafruit_SPA06_003.h>
class SPA06Sensor : public TelemetrySensor
{
private:
Adafruit_SPA06_003 spa06;
Adafruit_Sensor *spa_temp;
Adafruit_Sensor *spa_pressure;
public:
SPA06Sensor();
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) override;
};
#endif
+11
View File
@@ -1,5 +1,7 @@
#pragma once
#include <cmath>
class UnitConversions
{
public:
@@ -7,4 +9,13 @@ class UnitConversions
static float MetersPerSecondToKnots(float metersPerSecond);
static float MetersPerSecondToMilesPerHour(float metersPerSecond);
static float HectoPascalToInchesOfMercury(float hectoPascal);
// Bound a float before Arduino String(float) renders it: its fixed char[33] + dtostrf overflow
// near FLT_MAX (stack smash). Clamp to +/-1e9 (<=10 digits) and drop non-finite values.
static inline float displaySafeFloat(float v)
{
if (!std::isfinite(v))
return 0.0f;
return v < -1e9f ? -1e9f : (v > 1e9f ? 1e9f : v);
}
};