From 7d745ec40802d8b0f1fcc18b0de4cd9c4f23816a Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Mon, 1 Sep 2025 08:34:54 +1000 Subject: [PATCH] Hold for >20s after GPS lock GPS chips are designed to stay locked for a while to download some data and save it. This data is important for speeding up future locks, and making them higher quality. Our present configuration could make every lock perform similar to first lock. This patch sets a hold of between 20s and 10% of the lock search time after lock is acquired. This should allow the GPS to finish its work before we turn it off. Fixes https://github.com/meshtastic/firmware/issues/7466 --- src/gps/GPS.cpp | 13 ++++++++++--- src/gps/GPS.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index ae74f0fe2..ef37df196 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1126,6 +1126,10 @@ int32_t GPS::runOnce() LOG_DEBUG("hasValidLocation RISING EDGE"); hasValidLocation = true; shouldPublish = true; + lastFixStartMsec = millis(); + // Calculate hold duration: 10% of search time or 20s, whichever is smaller + uint32_t tenPercent = scheduling.elapsedSearchMs() / 10; + fixHoldEnds = lastFixStartMsec + ((tenPercent < 20000) ? tenPercent : 20000); } bool tooLong = scheduling.searchedTooLong(); @@ -1135,7 +1139,7 @@ int32_t GPS::runOnce() // Once we get a location we no longer desperately want an update if ((gotLoc && gotTime) || tooLong) { - if (tooLong) { + if (tooLong && !gotLoc) { // we didn't get a location during this ack window, therefore declare loss of lock if (hasValidLocation) { LOG_DEBUG("hasValidLocation FALLING EDGE"); @@ -1143,8 +1147,11 @@ int32_t GPS::runOnce() p = meshtastic_Position_init_default; hasValidLocation = false; } - - down(); + if (millis() > fixHoldEnds) { + down(); + } else { + LOG_DEBUG("Holding for GPS data download: %d ms", fixHoldEnds - millis()); + } shouldPublish = true; // publish our update for this just finished acquisition window } diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 9be57017f..3dcb17611 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -159,7 +159,7 @@ class GPS : private concurrency::OSThread uint8_t fixType = 0; // fix type from GPGSA #endif - uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0; + uint32_t lastFixStartMsec = 0, fixHoldEnds = 0; uint32_t rx_gpio = 0; uint32_t tx_gpio = 0;