mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
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:
parent
01df3ff477
commit
553e572eb5
@ -407,3 +407,15 @@ bool MeshService::isToPhoneQueueEmpty()
|
|||||||
{
|
{
|
||||||
return toPhoneQueue.isEmpty();
|
return toPhoneQueue.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t MeshService::GetTimeSinceMeshPacket(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;
|
||||||
|
}
|
||||||
|
@ -151,6 +151,8 @@ class MeshService
|
|||||||
|
|
||||||
ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id);
|
ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id);
|
||||||
|
|
||||||
|
uint32_t GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if HAS_GPS
|
#if HAS_GPS
|
||||||
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
|
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
|
||||||
|
@ -187,18 +187,6 @@ float EnvironmentTelemetryModule::CelsiusToFahrenheit(float c)
|
|||||||
return (c * 9) / 5 + 32;
|
return (c * 9) / 5 + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetTimeSinceMeshPacket(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 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);
|
||||||
@ -213,7 +201,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
|
|||||||
|
|
||||||
// Decode the last measurement packet
|
// Decode the last measurement packet
|
||||||
meshtastic_Telemetry lastMeasurement;
|
meshtastic_Telemetry lastMeasurement;
|
||||||
uint32_t agoSecs = GetTimeSinceMeshPacket(lastMeasurementPacket);
|
uint32_t agoSecs = service->GetTimeSinceMeshPacket(lastMeasurementPacket);
|
||||||
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
||||||
|
|
||||||
const meshtastic_Data &p = lastMeasurementPacket->decoded;
|
const meshtastic_Data &p = lastMeasurementPacket->decoded;
|
||||||
|
@ -94,18 +94,6 @@ bool PowerTelemetryModule::wantUIFrame()
|
|||||||
return moduleConfig.telemetry.power_screen_enabled;
|
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)
|
void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
@ -119,7 +107,7 @@ void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *s
|
|||||||
|
|
||||||
meshtastic_Telemetry lastMeasurement;
|
meshtastic_Telemetry lastMeasurement;
|
||||||
|
|
||||||
uint32_t agoSecs = GetTimeyWimeySinceMeshPacket(lastMeasurementPacket);
|
uint32_t agoSecs = service->GetTimeSinceMeshPacket(lastMeasurementPacket);
|
||||||
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
const char *lastSender = getSenderShortName(*lastMeasurementPacket);
|
||||||
|
|
||||||
const meshtastic_Data &p = lastMeasurementPacket->decoded;
|
const meshtastic_Data &p = lastMeasurementPacket->decoded;
|
||||||
|
Loading…
Reference in New Issue
Block a user