From 48fa9f2242641e27a51b2f928f99ee648529194e Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Sat, 28 Sep 2024 09:34:37 +0200 Subject: [PATCH] Only check threshold if GPS softsleep is supported --- src/gps/GPS.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 569254d023..fdad2b24bb 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -916,20 +916,22 @@ void GPS::down() softsleepSupported = true; #endif - // How long does gps_update_interval need to be, for GPS_HARDSLEEP to become more efficient than GPS_SOFTSLEEP? - // Heuristic equation. A compromise manually fitted to power observations from U-blox NEO-6M and M10050 - // https://www.desmos.com/calculator/6gvjghoumr - // This is not particularly accurate, but probably an impromevement over a single, fixed threshold - uint32_t hardsleepThreshold = (2750 * pow(predictedSearchDuration / 1000, 1.22)); - LOG_DEBUG("gps_update_interval >= %us needed to justify hardsleep\n", hardsleepThreshold / 1000); - - // If update interval too short: softsleep (if supported by hardware) - if (softsleepSupported && updateInterval < hardsleepThreshold) - setPowerState(GPS_SOFTSLEEP, sleepTime); - + if (softsleepSupported) { + // How long does gps_update_interval need to be, for GPS_HARDSLEEP to become more efficient than GPS_SOFTSLEEP? + // Heuristic equation. A compromise manually fitted to power observations from U-blox NEO-6M and M10050 + // https://www.desmos.com/calculator/6gvjghoumr + // This is not particularly accurate, but probably an impromevement over a single, fixed threshold + uint32_t hardsleepThreshold = (2750 * pow(predictedSearchDuration / 1000, 1.22)); + LOG_DEBUG("gps_update_interval >= %us needed to justify hardsleep\n", hardsleepThreshold / 1000); + + // If update interval too short: softsleep (if supported by hardware) + if (updateInterval < hardsleepThreshold) { + setPowerState(GPS_SOFTSLEEP, sleepTime); + return; + } + } // If update interval long enough (or softsleep unsupported): hardsleep instead - else - setPowerState(GPS_HARDSLEEP, sleepTime); + setPowerState(GPS_HARDSLEEP, sleepTime); } }