From 76e202739df1523638febb69a98827b49c4e2e87 Mon Sep 17 00:00:00 2001 From: Daniel Ansorregui Date: Sat, 11 Dec 2021 16:14:38 +0000 Subject: [PATCH 1/2] Set all pins to INPUT before deep sleep * Some pins otherwise are left as output And their value is kept in deep sleep This can cause power usage in deep sleep * From my measurements 0.13mA Or, 3mAh / day extra usage --- src/Watchy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Watchy.cpp b/src/Watchy.cpp index a334f5b..1df910f 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -41,6 +41,10 @@ void Watchy::init(String datetime){ } void Watchy::deepSleep(){ + // Set all pins to input to avoid power leaking out + for(int i=0; i<48; i++) { + pinMode(i, INPUT); + } esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press esp_deep_sleep_start(); From b794d8ee7997a67e6cf41a69ba6deaba479761f9 Mon Sep 17 00:00:00 2001 From: SQFMI Date: Sun, 12 Dec 2021 16:43:38 -0500 Subject: [PATCH 2/2] Moved clear alarm function --- src/Watchy.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Watchy.cpp b/src/Watchy.cpp index 1df910f..05facaa 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -21,7 +21,6 @@ void Watchy::init(String datetime){ switch (wakeup_reason) { case ESP_SLEEP_WAKEUP_EXT0: //RTC Alarm - RTC.clearAlarm(); //resets the alarm flag in the RTC if(guiState == WATCHFACE_STATE){ RTC.read(currentTime); showWatchFace(true); //partial updates on tick @@ -41,13 +40,14 @@ void Watchy::init(String datetime){ } void Watchy::deepSleep(){ - // Set all pins to input to avoid power leaking out - for(int i=0; i<48; i++) { - pinMode(i, INPUT); - } - esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt - esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press - esp_deep_sleep_start(); + RTC.clearAlarm(); //resets the alarm flag in the RTC + // Set pins 0-39 to input to avoid power leaking out + for(int i=0; i<40; i++) { + pinMode(i, INPUT); + } + esp_sleep_enable_ext0_wakeup(RTC_PIN, 0); //enable deep sleep wake on RTC interrupt + esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press + esp_deep_sleep_start(); } void Watchy::handleButtonPress(){ @@ -87,7 +87,6 @@ void Watchy::handleButtonPress(){ //Back Button else if (wakeupBit & BACK_BTN_MASK){ if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu - RTC.clearAlarm(); //resets the alarm flag in the RTC RTC.read(currentTime); showWatchFace(false); }else if(guiState == APP_STATE){ @@ -166,7 +165,6 @@ void Watchy::handleButtonPress(){ }else if(digitalRead(BACK_BTN_PIN) == 1){ lastTimeout = millis(); if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu - RTC.clearAlarm(); //resets the alarm flag in the RTC RTC.read(currentTime); showWatchFace(false); break; //leave loop @@ -910,4 +908,4 @@ void Watchy::updateFWBegin(){ // time_t t = makeTime(tm); // return t + FUDGE; //add fudge factor to allow for compile time -// } \ No newline at end of file +// }