Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ats-mini/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
37 changes: 30 additions & 7 deletions ats-mini/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ats-mini/ats-mini.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down