Skip to content

Commit

Permalink
A single generate_click lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 31, 2019
1 parent c014f8d commit 1eeef30
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,19 @@ void MarlinUI::update() {

// If the action button is pressed...
static bool wait_for_unclick; // = 0
auto generate_click = [&]() {
if (!wait_for_unclick) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - 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
}
};

#if ENABLED(TOUCH_BUTTONS)
if (touch_buttons) {
if (!wait_for_unclick && (buttons & EN_C)) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - 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
}
if (buttons & EN_C)
generate_click();
else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage"
const millis_t ms = millis();
if (ELAPSED(ms, next_button_update_ms)) {
Expand All @@ -790,19 +795,16 @@ void MarlinUI::update() {
}
}
else
#endif //TOUCH_BUTTONS
//
// Integrated LCD click handling via button_pressed()
//
if (!external_control && button_pressed()) {
if (!wait_for_unclick) { // If not waiting for a debounce release:
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks
lcd_clicked = !wait_for_user && !no_reentry; // - 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
#endif // TOUCH_BUTTONS
{
//
// Integrated LCD click handling via button_pressed()
//
if (!external_control && button_pressed())
generate_click();
else
wait_for_unclick = false;
}
}
else wait_for_unclick = false;

#if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS))
if (LCD_BACK_CLICKED()) {
Expand Down

0 comments on commit 1eeef30

Please sign in to comment.