From 911083c49d8ee58dec810dd74ff2f0cf045af381 Mon Sep 17 00:00:00 2001 From: code8buster Date: Sun, 4 Dec 2022 01:57:00 -0500 Subject: [PATCH] Adds a flag to turn the GPS power rail off entirely on tbeam --- src/ButtonThread.h | 17 +++++++++++++++-- src/gps/GPS.cpp | 1 - src/gps/GPS.h | 4 +++- src/sleep.cpp | 16 ++++++++++++++++ src/sleep.h | 2 +- variants/tbeam/platformio.ini | 1 + 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 088642099..23859b8ad 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -5,6 +5,7 @@ #include "configuration.h" #include "graphics/Screen.h" #include "power.h" +#include "GPS.h" #include namespace concurrency @@ -159,9 +160,21 @@ class ButtonThread : public concurrency::OSThread static void userButtonDoublePressed() { -#if defined(USE_EINK) && defined(PIN_EINK_EN) + #if defined(USE_EINK) && defined(PIN_EINK_EN) digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); -#endif + #endif + #if defined(GPS_POWER_TOGGLE) + if(gps->gpsPowerflag) + { + DEBUG_MSG("Flag set to false for gps power\n"); + } + else + { + DEBUG_MSG("Flag set to true to restore power\n"); + } + gps->gpsPowerflag = !(gps->gpsPowerflag); + doGPSpowersave(gps->gpsPowerflag); + #endif } static void userButtonMultiPressed() diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 54dc59cbb..2a00af475 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -276,7 +276,6 @@ bool GPS::setup() delay(10); digitalWrite(PIN_GPS_RESET, 0); #endif - setAwake(true); // Wake GPS power before doing any init bool ok = setupGPS(); diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 8f04b6793..c9f0ff41b 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -77,6 +77,8 @@ class GPS : private concurrency::OSThread /// Return true if we are connected to a GPS bool isConnected() const { return hasGPS; } + bool gpsPowerflag; + /** * Restart our lock attempt - try to get and broadcast a GPS reading ASAP * called after the CPU wakes from light-sleep state @@ -128,7 +130,6 @@ class GPS : private concurrency::OSThread void setNumSatellites(uint8_t n); - private: /// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs /// always returns 0 to indicate okay to sleep int prepareSleep(void *unused); @@ -136,6 +137,7 @@ class GPS : private concurrency::OSThread /// Prepare the GPS for the cpu entering deep sleep, expect to be gone for at least 100s of msecs /// always returns 0 to indicate okay to sleep int prepareDeepSleep(void *unused); + private: /** * Switch the GPS into a mode where we are actively looking for a lock, or alternatively switch GPS into a low power mode diff --git a/src/sleep.cpp b/src/sleep.cpp index 39ee43ebc..7f6735939 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -167,6 +167,22 @@ static void waitEnterSleep() notifySleep.notifyObservers(NULL); } +void doGPSpowersave(bool on) +{ + if (on) + { + DEBUG_MSG("Turning GPS back on\n"); + gps->forceWake(1); + setGPSPower(1); + } + else + { + DEBUG_MSG("Turning off GPS chip\n"); + notifySleep.notifyObservers(NULL); + setGPSPower(0); + } +} + void doDeepSleep(uint64_t msecToWake) { DEBUG_MSG("Entering deep sleep for %lu seconds\n", msecToWake / 1000); diff --git a/src/sleep.h b/src/sleep.h index 7f0592af4..f911a7cc8 100644 --- a/src/sleep.h +++ b/src/sleep.h @@ -13,7 +13,7 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t msecToWake); extern esp_sleep_source_t wakeCause; #endif void setGPSPower(bool on); - +void doGPSpowersave(bool on); // Perform power on init that we do on each wake from deep sleep void initDeepSleep(); diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 578a74f7b..df526ae5b 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -6,4 +6,5 @@ lib_deps = ${esp32_base.lib_deps} build_flags = ${esp32_base.build_flags} -D TBEAM_V10 -I variants/tbeam + ;-DGPS_POWER_TOGGLE ;uncomment this line to allow a double press on the user button to turn off gps entirely. upload_speed = 921600