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);