diff --git a/ats-mini/Common.h b/ats-mini/Common.h index 687bc53b..2d0febda 100644 --- a/ats-mini/Common.h +++ b/ats-mini/Common.h @@ -51,6 +51,7 @@ #define ENCODER_PIN_A 2 // GPIO02 #define ENCODER_PIN_B 1 // GPIO01 #define ENCODER_PUSH_BUTTON 21 // GPIO21 +#define ENCODER_PIN_BITMASK(PIN) (1ULL << PIN) // Compute number of items in an array #define ITEM_COUNT(array) (sizeof(array) / sizeof((array)[0])) diff --git a/ats-mini/Utils.cpp b/ats-mini/Utils.cpp index a1b1a334..b1847e8d 100644 --- a/ats-mini/Utils.cpp +++ b/ats-mini/Utils.cpp @@ -140,6 +140,23 @@ void tempMuteOn(bool x) } } +// +// Enable an RTC GPIO pin helper function +// +void enableRtcPin(gpio_num_t pin) { + rtc_gpio_pullup_en(pin); + rtc_gpio_pulldown_dis(pin); +} + +// +// Disable an RTC GPIO pin helper function +// +void disableRtcPin(gpio_num_t pin) { + rtc_gpio_pullup_dis(pin); + rtc_gpio_pulldown_dis(pin); + rtc_gpio_deinit(pin); + pinMode(pin, INPUT_PULLUP); +} // // Turn sleep on (1) or off (0), or get current status (2) @@ -169,9 +186,14 @@ bool sleepOn(int x) while(true) { - esp_sleep_enable_ext0_wakeup((gpio_num_t)ENCODER_PUSH_BUTTON, LOW); - rtc_gpio_pullup_en((gpio_num_t)ENCODER_PUSH_BUTTON); - rtc_gpio_pulldown_dis((gpio_num_t)ENCODER_PUSH_BUTTON); + uint64_t wakeupBitmask = ENCODER_PIN_BITMASK(ENCODER_PUSH_BUTTON); + enableRtcPin((gpio_num_t)ENCODER_PUSH_BUTTON); + if(currentSleep) { + wakeupBitmask |= ENCODER_PIN_BITMASK(ENCODER_PIN_A) | ENCODER_PIN_BITMASK(ENCODER_PIN_B); + enableRtcPin((gpio_num_t)ENCODER_PIN_A); + enableRtcPin((gpio_num_t)ENCODER_PIN_B); + } + esp_sleep_enable_ext1_wakeup(wakeupBitmask, ESP_EXT1_WAKEUP_ALL_LOW); esp_light_sleep_start(); // Waking up here @@ -192,10 +214,11 @@ bool sleepOn(int x) if(wasLongPressed) break; } // Reenable the pin as well as the display - rtc_gpio_pullup_dis((gpio_num_t)ENCODER_PUSH_BUTTON); - rtc_gpio_pulldown_dis((gpio_num_t)ENCODER_PUSH_BUTTON); - rtc_gpio_deinit((gpio_num_t)ENCODER_PUSH_BUTTON); - pinMode(ENCODER_PUSH_BUTTON, INPUT_PULLUP); + disableRtcPin((gpio_num_t)ENCODER_PUSH_BUTTON); + if(currentSleep) { + disableRtcPin((gpio_num_t)ENCODER_PIN_A); + disableRtcPin((gpio_num_t)ENCODER_PIN_B); + } if(squelchCutoff) tempMuteOn(true); sleepOn(false); // Enable WiFi diff --git a/ats-mini/ats-mini.ino b/ats-mini/ats-mini.ino index 22ba8e62..7ca9d6da 100644 --- a/ats-mini/ats-mini.ino +++ b/ats-mini/ats-mini.ino @@ -712,6 +712,12 @@ void loop() // Block encoder rotation when in the locked sleep mode if(encoderCount && sleepOn() && sleepModeIdx==SLEEP_LOCKED) encoderCount = 0; + // Don't wake in unlocked sleep mode + if(encoderCount && currentSleep && sleepOn() && sleepModeIdx!=SLEEP_UNLOCKED) { + sleepOn(false); + needRedraw = true; + } + // Activate push and rotate mode (can span multiple loop iterations until the button is released) if (encoderCount && pb1st.isPressed) pushAndRotate = true;