From 4223701d0ed874ae06124a065721bc5d3003bf65 Mon Sep 17 00:00:00 2001 From: m1nl Date: Wed, 2 Jul 2025 22:26:19 +0200 Subject: [PATCH] do not enter light-sleep when GPS is in GPS_ACTIVE state --- src/gps/GPS.cpp | 10 +++++++++- src/gps/GPS.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 3a6b19f64..8bc2a543d 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -805,13 +805,15 @@ bool GPS::setup() } notifyDeepSleepObserver.observe(¬ifyDeepSleep); + preflightSleepObserver.observe(&preflightSleep); return true; } GPS::~GPS() { - // we really should unregister our sleep observer + // we really should unregister our sleep observers + preflightSleepObserver.unobserve(&preflightSleep); notifyDeepSleepObserver.unobserve(¬ifyDeepSleep); } @@ -1171,6 +1173,12 @@ int GPS::prepareDeepSleep(void *unused) return 0; } +// Prevents entering light-sleep when GPS is in active state +int GPS::preflightSleepCb(void *unused) +{ + return (powerState == GPS_ACTIVE); +} + static const char *PROBE_MESSAGE = "Trying %s (%s)..."; static const char *DETECTED_MESSAGE = "%s detected"; diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 9be57017f..f5cd38b5c 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -186,6 +186,7 @@ class GPS : private concurrency::OSThread uint8_t numSatellites = 0; CallbackObserver notifyDeepSleepObserver = CallbackObserver(this, &GPS::prepareDeepSleep); + CallbackObserver preflightSleepObserver = CallbackObserver(this, &GPS::preflightSleepCb); /** If !NULL we will use this serial port to construct our GPS */ #if defined(ARCH_RP2040) @@ -213,6 +214,9 @@ class GPS : private concurrency::OSThread /// always returns 0 to indicate okay to sleep int prepareDeepSleep(void *unused); + // Prevents entering light-sleep when GPS is in active state + int preflightSleepCb(void *unused); + /** Set power with EN pin, if relevant */ void writePinEN(bool on);