A single generate_click lambda

This commit is contained in:
Scott Lahteine 2019-08-30 19:14:43 -05:00
parent c014f8dc78
commit 1eeef30097

View file

@ -765,14 +765,19 @@ void MarlinUI::update() {
// If the action button is pressed... // If the action button is pressed...
static bool wait_for_unclick; // = 0 static bool wait_for_unclick; // = 0
#if ENABLED(TOUCH_BUTTONS) auto generate_click = [&]() {
if (touch_buttons) { if (!wait_for_unclick) { // If not waiting for a debounce release:
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 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 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 wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound quick_feedback(); // - Always make a click sound
} }
};
#if ENABLED(TOUCH_BUTTONS)
if (touch_buttons) {
if (buttons & EN_C)
generate_click();
else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage" else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage"
const millis_t ms = millis(); const millis_t ms = millis();
if (ELAPSED(ms, next_button_update_ms)) { if (ELAPSED(ms, next_button_update_ms)) {
@ -790,19 +795,16 @@ void MarlinUI::update() {
} }
} }
else else
#endif //TOUCH_BUTTONS #endif // TOUCH_BUTTONS
{
// //
// Integrated LCD click handling via button_pressed() // Integrated LCD click handling via button_pressed()
// //
if (!external_control && button_pressed()) { if (!external_control && button_pressed())
if (!wait_for_unclick) { // If not waiting for a debounce release: generate_click();
wait_for_unclick = true; // - Set debounce flag to ignore continous clicks else
lcd_clicked = !wait_for_user && !no_reentry; // - Keep the click if not waiting for a user-click wait_for_unclick = false;
wait_for_user = false; // - Any click clears wait for user
quick_feedback(); // - Always make a click sound
} }
}
else wait_for_unclick = false;
#if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS)) #if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS))
if (LCD_BACK_CLICKED()) { if (LCD_BACK_CLICKED()) {