mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 06:02:05 +00:00
Fix for EnvironmentTelemetry Screen (#3785)
* Update EnvironmentTelemetry.cpp * Update EnvironmentTelemetry.cpp Corrected lines I deleted by mistake * trunk fmt --------- Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
This commit is contained in:
parent
e98c3bf5d0
commit
77a66e1dce
@ -151,45 +151,53 @@ uint32_t GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp)
|
|||||||
void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_MEDIUM);
|
|
||||||
display->drawString(x, y, "Environment");
|
|
||||||
if (lastMeasurementPacket == nullptr) {
|
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(x, y += fontHeight(FONT_MEDIUM), "No measurement");
|
|
||||||
|
if (lastMeasurementPacket == nullptr) {
|
||||||
|
// If there's no valid packet, display "Environment"
|
||||||
|
display->drawString(x, y, "Environment");
|
||||||
|
display->drawString(x, y += fontHeight(FONT_SMALL), "No measurement");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode the last measurement packet
|
||||||
meshtastic_Telemetry lastMeasurement;
|
meshtastic_Telemetry lastMeasurement;
|
||||||
|
|
||||||
uint32_t agoSecs = GetTimeSinceMeshPacket(lastMeasurementPacket);
|
uint32_t agoSecs = GetTimeSinceMeshPacket(lastMeasurementPacket);
|
||||||
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
||||||
|
|
||||||
auto &p = lastMeasurementPacket->decoded;
|
auto &p = lastMeasurementPacket->decoded;
|
||||||
if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) {
|
if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) {
|
||||||
display->setFont(FONT_SMALL);
|
display->drawString(x, y, "Measurement Error");
|
||||||
display->drawString(x, y += fontHeight(FONT_MEDIUM), "Measurement Error");
|
|
||||||
LOG_ERROR("Unable to decode last packet");
|
LOG_ERROR("Unable to decode last packet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
display->setFont(FONT_SMALL);
|
// Display "Env. From: ..." on its own
|
||||||
|
display->drawString(x, y, "Env. From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
||||||
|
|
||||||
String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C";
|
String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C";
|
||||||
if (moduleConfig.telemetry.environment_display_fahrenheit) {
|
if (moduleConfig.telemetry.environment_display_fahrenheit) {
|
||||||
last_temp = String(CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F";
|
last_temp = String(CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F";
|
||||||
}
|
}
|
||||||
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,
|
// Continue with the remaining details
|
||||||
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Temp/Hum: " + last_temp + " / " +
|
"Temp/Hum: " + last_temp + " / " +
|
||||||
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
||||||
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0)
|
|
||||||
|
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) {
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
"Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
||||||
if (lastMeasurement.variant.environment_metrics.voltage != 0)
|
}
|
||||||
|
|
||||||
|
if (lastMeasurement.variant.environment_metrics.voltage != 0) {
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " +
|
"Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " +
|
||||||
String(lastMeasurement.variant.environment_metrics.current, 0) + "mA");
|
String(lastMeasurement.variant.environment_metrics.current, 0) + "mA");
|
||||||
if (lastMeasurement.variant.environment_metrics.iaq != 0)
|
}
|
||||||
|
if (lastMeasurement.variant.environment_metrics.iaq != 0) {
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL), "IAQ: " + String(lastMeasurement.variant.environment_metrics.iaq));
|
display->drawString(x, y += fontHeight(FONT_SMALL), "IAQ: " + String(lastMeasurement.variant.environment_metrics.iaq));
|
||||||
|
}
|
||||||
if (lastMeasurement.variant.environment_metrics.distance != 0)
|
if (lastMeasurement.variant.environment_metrics.distance != 0)
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Water Level: " + String(lastMeasurement.variant.environment_metrics.distance, 0) + "mm");
|
"Water Level: " + String(lastMeasurement.variant.environment_metrics.distance, 0) + "mm");
|
||||||
|
Loading…
Reference in New Issue
Block a user