From 90a10a692a7715e3ccc99a9cb027ce7532fd8738 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Tue, 18 Sep 2018 14:00:57 +0200 Subject: [PATCH] Enable button debouncing also in modal mode (!lcd_update_enabled). In lcd_clicked() consume click event immediately. --- Firmware/lcd.cpp | 89 ++++++++++++++++++++----------------------- Firmware/menu.cpp | 2 + Firmware/ultralcd.cpp | 2 + 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index 5ac6c317..7cd67fe3 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -686,7 +686,11 @@ LongTimer lcd_timeoutToStatus; uint8_t lcd_clicked(void) { bool clicked = LCD_CLICKED; - if(clicked) lcd_button_pressed = 0; + if(clicked) + { + lcd_button_pressed = 0; + lcd_buttons &= 0xff^EN_C; + } return clicked; } @@ -709,7 +713,7 @@ Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); void lcd_quick_feedback(void) { lcd_draw_update = 2; - lcd_button_pressed = false; + lcd_button_pressed = false; lcd_beeper_quick_feedback(); } @@ -766,51 +770,42 @@ void lcd_buttons_update(void) uint8_t newbutton = 0; if (READ(BTN_EN1) == 0) newbutton |= EN_A; if (READ(BTN_EN2) == 0) newbutton |= EN_B; - if (lcd_update_enabled) - { //if we are in non-modal mode, long press can be used and short press triggers with button release - if (READ(BTN_ENC) == 0) - { //button is pressed - lcd_timeoutToStatus.start(); - if (!buttonBlanking.running() || buttonBlanking.expired(BUTTON_BLANKING_TIME)) { - buttonBlanking.start(); - safetyTimer.start(); - if ((lcd_button_pressed == 0) && (lcd_long_press_active == 0)) - { - longPressTimer.start(); - lcd_button_pressed = 1; - } - else - { - if (longPressTimer.expired(LONG_PRESS_TIME)) - { - lcd_long_press_active = 1; - if (lcd_longpress_func) - lcd_longpress_func(); - } - } - } - } - else - { //button not pressed - if (lcd_button_pressed) - { //button was released - buttonBlanking.start(); - if (lcd_long_press_active == 0) - { //button released before long press gets activated - newbutton |= EN_C; - } - //else if (menu_menu == lcd_move_z) lcd_quick_feedback(); - //lcd_button_pressed is set back to false via lcd_quick_feedback function - } - else - lcd_long_press_active = 0; - } - } - else - { //we are in modal mode - if (READ(BTN_ENC) == 0) - newbutton |= EN_C; - } + + if (READ(BTN_ENC) == 0) + { //button is pressed + lcd_timeoutToStatus.start(); + if (!buttonBlanking.running() || buttonBlanking.expired(BUTTON_BLANKING_TIME)) { + buttonBlanking.start(); + safetyTimer.start(); + if ((lcd_button_pressed == 0) && (lcd_long_press_active == 0)) + { + //long press is not possible in modal mode + if (lcd_update_enabled) longPressTimer.start(); + lcd_button_pressed = 1; + } + else if (longPressTimer.expired(LONG_PRESS_TIME)) + { + lcd_long_press_active = 1; + if (lcd_longpress_func) + lcd_longpress_func(); + } + } + } + else + { //button not pressed + if (lcd_button_pressed) + { //button was released + buttonBlanking.start(); + if (lcd_long_press_active == 0) + { //button released before long press gets activated + newbutton |= EN_C; + } + //else if (menu_menu == lcd_move_z) lcd_quick_feedback(); + //lcd_button_pressed is set back to false via lcd_quick_feedback function + } + else + lcd_long_press_active = 0; + } lcd_buttons = newbutton; //manage encoder rotation diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index bd523826..a92fc857 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -236,6 +236,8 @@ uint8_t menu_item_function_P(const char* str, menu_func_t func) if (menu_clicked && (lcd_encoder == menu_item)) { menu_clicked = false; + lcd_button_pressed = 0; + lcd_buttons &= 0xff^EN_C; lcd_update_enabled = 0; if (func) func(); lcd_update_enabled = 1; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index cd73912e..89e6c6c2 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -463,6 +463,8 @@ static uint8_t menu_item_sdfile(const char* } if (menu_clicked && (lcd_encoder == menu_item)) { + lcd_button_pressed = 0; + lcd_buttons &= 0xff^EN_C; menu_action_sdfile(str_fn); return menu_item_ret(); }