From 603cce2988b8640d94199403ad6bd35b23062fd0 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 5 May 2026 10:12:50 -0500 Subject: [PATCH] Add informSearchFailed method to update GPS power state handling (#10394) --- src/gps/GPS.cpp | 7 +++++-- src/gps/GPSUpdateScheduling.cpp | 10 ++++++++++ src/gps/GPSUpdateScheduling.h | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 1260d8b15..f42678182 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1017,10 +1017,13 @@ void GPS::up() setPowerState(GPS_ACTIVE); } -// We've got a GPS lock. Enter a low power state, potentially. +// We've finished a GPS search cycle (lock or timeout). Enter a low power state, potentially. void GPS::down() { - scheduling.informGotLock(); + if (hasValidLocation) + scheduling.informGotLock(); + else + scheduling.informSearchFailed(); uint32_t predictedSearchDuration = scheduling.predictedSearchDurationMs(); uint32_t sleepTime = scheduling.msUntilNextSearch(); uint32_t updateInterval = Default::getConfiguredOrDefaultMs(config.position.gps_update_interval); diff --git a/src/gps/GPSUpdateScheduling.cpp b/src/gps/GPSUpdateScheduling.cpp index 53d6c833f..45634d2d3 100644 --- a/src/gps/GPSUpdateScheduling.cpp +++ b/src/gps/GPSUpdateScheduling.cpp @@ -17,6 +17,16 @@ void GPSUpdateScheduling::informGotLock() updateLockTimePrediction(); } +// Search finished without obtaining a fix. We still need to mark the end time so +// the next sleep is timed correctly, but we must not feed the timeout duration +// into predictedMsToGetLock — doing so poisons msUntilNextSearch() and causes +// down() to fall into GPS_IDLE, leaving the chip awake on subsequent indoor cycles. +void GPSUpdateScheduling::informSearchFailed() +{ + searchEndedMs = millis(); + LOG_DEBUG("GPS search ended without fix after %us", (searchEndedMs - searchStartedMs) / 1000); +} + // Clear old lock-time prediction data. // When re-enabling GPS with user button. void GPSUpdateScheduling::reset() diff --git a/src/gps/GPSUpdateScheduling.h b/src/gps/GPSUpdateScheduling.h index 7e121c9b6..64835a469 100644 --- a/src/gps/GPSUpdateScheduling.h +++ b/src/gps/GPSUpdateScheduling.h @@ -8,7 +8,8 @@ class GPSUpdateScheduling public: // Marks the time of these events, for calculation use void informSearching(); - void informGotLock(); // Predicted lock-time is recalculated here + void informGotLock(); // Predicted lock-time is recalculated here + void informSearchFailed(); // Search ended without a fix; prediction is left untouched void reset(); // Reset the prediction - after GPS::disable() / GPS::enable() bool isUpdateDue(); // Is it time to begin searching for a GPS position?