Skip to content

Commit

Permalink
🚸 Ignore first click on asleep LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 14, 2024
1 parent 5de9fc5 commit 282f90c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,9 @@ void MarlinUI::clear_for_drawing() {
}

#if HAS_DISPLAY_SLEEP
static bool asleep = false;
bool MarlinUI::display_is_asleep() { return asleep; }
void MarlinUI::sleep_display(const bool sleep/*=true*/) {
static bool asleep = false;
if (asleep != sleep) {
sleep ? u8g.sleepOn() : u8g.sleepOff();
asleep = sleep;
Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,13 @@ void MarlinUI::init() {
// If the action button is pressed...
static bool wait_for_unclick; // = false

// Set lcd_clicked for most clicks.
// Ignore the click when clearing wait_for_user or waking the screen.
auto do_click = [&]{
wait_for_unclick = true; // - Set debounce flag to ignore continuous clicks
lcd_clicked = !wait_for_user; // - Keep the click if not waiting for a user-click
wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound
wait_for_unclick = true;
lcd_clicked = !wait_for_user && !display_is_asleep();
wait_for_user = false;
quick_feedback();
};

#if HAS_TOUCH_BUTTONS
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class MarlinUI {
#endif

// Sleep or wake the display (e.g., by turning the backlight off/on).
static bool display_is_asleep() IF_DISABLED(HAS_DISPLAY_SLEEP, { return false; });
static void sleep_display(const bool=true) IF_DISABLED(HAS_DISPLAY_SLEEP, {});
static void wake_display() { sleep_display(false); }

Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) {
next_sleep_ms = ui.sleep_timeout_minutes ? millis() + MIN_TO_MS(ui.sleep_timeout_minutes) : 0;
}

bool MarlinUI::display_is_asleep() { return touch.isSleeping(); }
void MarlinUI::sleep_display(const bool sleep/*=true*/) {
if (!sleep) touch.wakeUp();
}
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ uint8_t TouchButtons::read_buttons() {
next_sleep_ms = ui.sleep_timeout_minutes ? millis() + MIN_TO_MS(ui.sleep_timeout_minutes) : 0;
}

bool MarlinUI::display_is_asleep() {
return touchBt.isSleeping();
}
void MarlinUI::sleep_display(const bool sleep/*=true*/) {
if (!sleep) touchBt.wakeUp();
}
Expand Down

0 comments on commit 282f90c

Please sign in to comment.