Coalesce duplicated method GetTimeSinceMeshPacket (#4968)

GetTimeSinceMeshPacket was duplicated in PowerTelemetry and
EnvironmentalTelemetry, albeit one had a cooler name than the other.

As we add HealthTelemetry, to avoid creating a third instance of
this method, let's move it somewhere that makese sense.

Adds a new method GetTimeSinceMeshPacket to MeshService and updates
EnvironmentTelemetry and PowerTelemetry to use it.
This commit is contained in:
Tom Fifield
2024-10-06 19:40:06 +08:00
committed by GitHub
parent 01df3ff477
commit 553e572eb5
4 changed files with 20 additions and 30 deletions

View File

@@ -94,18 +94,6 @@ bool PowerTelemetryModule::wantUIFrame()
return moduleConfig.telemetry.power_screen_enabled;
}
uint32_t GetTimeyWimeySinceMeshPacket(const meshtastic_MeshPacket *mp)
{
uint32_t now = getTime();
uint32_t last_seen = mp->rx_time;
int delta = (int)(now - last_seen);
if (delta < 0) // our clock must be slightly off still - not set from GPS yet
delta = 0;
return delta;
}
void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
@@ -119,7 +107,7 @@ void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *s
meshtastic_Telemetry lastMeasurement;
uint32_t agoSecs = GetTimeyWimeySinceMeshPacket(lastMeasurementPacket);
uint32_t agoSecs = service->GetTimeSinceMeshPacket(lastMeasurementPacket);
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
const meshtastic_Data &p = lastMeasurementPacket->decoded;
@@ -265,4 +253,4 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
return false;
}
#endif
#endif