From 2df5e58920d72b9c3aa01f0890240be48e208376 Mon Sep 17 00:00:00 2001 From: robbycandra Date: Fri, 30 Aug 2019 13:04:59 +0700 Subject: [PATCH 1/9] Add Option to Reverse Menu Encoder --- ...8g_dev_tft_320x240_upscale_from_128x64.cpp | 47 +++++++++++++++++++ Marlin/src/lcd/ultralcd.cpp | 44 ++++++++--------- 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp index 868f3f15be13..e8e432f90005 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp @@ -251,6 +251,52 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341 B01111111,B11111111,B11111111,B11111110, }; +#if ENABLED(REVERSE_MENU_DIRECTION) + static const uint8_t buttonA[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00111111,B11100001, + B10000111,B11111100,B00111111,B11100001, + B10000011,B11111000,B00000000,B00000001, + B10000001,B11110000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B01000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; + static const uint8_t buttonB[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B01100000,B00000010,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00001111,B10000001, + B10000000,B01100000,B00011111,B11000001, + B10000111,B11111110,B00111111,B11100001, + B10000111,B11111110,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; +#else static const uint8_t buttonA[] = { B01111111,B11111111,B11111111,B11111110, B10000000,B00000000,B00000000,B00000001, @@ -296,6 +342,7 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341 B10000000,B00000000,B00000000,B00000001, B01111111,B11111111,B11111111,B11111110, }; +#endif static const uint8_t buttonC[] = { B01111111,B11111111,B11111111,B11111110, diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 5228292b7020..839e8503bf87 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -775,22 +775,30 @@ void MarlinUI::update() { }; #if ENABLED(TOUCH_BUTTONS) + // Uodate touch buttons after update buttons + // This prevent overlaping Encoder Process + if (ELAPSED(ms, next_button_update_ms)) { + touch_buttons = read_touch_buttons(); + buttons |= touch_buttons; + } + if (touch_buttons) { + #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS + return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; + #endif 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)) { - next_button_update_ms = ms + 50; - encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP); - if (buttons & EN_A) encoderDiff *= -1; - if (!wait_for_unclick) { - next_button_update_ms += 250; - #if HAS_BUZZER - buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); - #endif - wait_for_unclick = true; // - Set debounce flag to ignore continous clicks - } + next_button_update_ms = ms + 50; // Set delay for continuous click + encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection ; + if (buttons & EN_B) encoderDiff *= -1; + buttons = 0; // Job done, clear buttons to prevent unwanted process. + if (!wait_for_unclick) { // If begin of click process then + next_button_update_ms += 250; // add delay time + #if HAS_BUZZER // beep if posible + buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); + #endif + wait_for_unclick = true; // - Set debounce flag to mark continous clicks } } } @@ -885,15 +893,6 @@ void MarlinUI::update() { slow_buttons = read_slow_buttons(); // Buttons that take too long to read in interrupt context #endif - #if ENABLED(TOUCH_BUTTONS) - touch_buttons = read_touch_buttons(); - if (touch_buttons) { - #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif - } - #endif - #if ENABLED(REPRAPWORLD_KEYPAD) if (handle_keypad()) { @@ -1241,9 +1240,6 @@ void MarlinUI::update() { #if HAS_SLOW_BUTTONS | slow_buttons #endif - #if ENABLED(TOUCH_BUTTONS) - | touch_buttons - #endif ; #elif HAS_ADC_BUTTONS buttons = 0; From 4c3c843fb2b6df2024a8d470fa6ee510561cd060 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 30 Aug 2019 18:20:45 -0500 Subject: [PATCH 2/9] Clean up spacing, indentation --- ...8g_dev_tft_320x240_upscale_from_128x64.cpp | 193 +++++++++--------- Marlin/src/lcd/ultralcd.cpp | 12 +- 2 files changed, 103 insertions(+), 102 deletions(-) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp index e8e432f90005..e8654eb3d3ff 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp @@ -251,98 +251,102 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341 B01111111,B11111111,B11111111,B11111110, }; -#if ENABLED(REVERSE_MENU_DIRECTION) - static const uint8_t buttonA[] = { - B01111111,B11111111,B11111111,B11111110, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00111111,B11100001, - B10000111,B11111100,B00111111,B11100001, - B10000011,B11111000,B00000000,B00000001, - B10000001,B11110000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B01000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B01111111,B11111111,B11111111,B11111110, - }; - static const uint8_t buttonB[] = { - B01111111,B11111111,B11111111,B11111110, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B01100000,B00000010,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00001111,B10000001, - B10000000,B01100000,B00011111,B11000001, - B10000111,B11111110,B00111111,B11100001, - B10000111,B11111110,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B01111111,B11111111,B11111111,B11111110, - }; -#else - static const uint8_t buttonA[] = { - B01111111,B11111111,B11111111,B11111110, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B01000000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000001,B11110000,B00000000,B00000001, - B10000011,B11111000,B00000000,B00000001, - B10000111,B11111100,B00111111,B11100001, - B10000000,B11100000,B00111111,B11100001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B11100000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B01111111,B11111111,B11111111,B11111110, - }; + #if ENABLED(REVERSE_MENU_DIRECTION) + + static const uint8_t buttonA[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00111111,B11100001, + B10000111,B11111100,B00111111,B11100001, + B10000011,B11111000,B00000000,B00000001, + B10000001,B11110000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B01000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; + static const uint8_t buttonB[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B01100000,B00000010,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00001111,B10000001, + B10000000,B01100000,B00011111,B11000001, + B10000111,B11111110,B00111111,B11100001, + B10000111,B11111110,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; - static const uint8_t buttonB[] = { - B01111111,B11111111,B11111111,B11111110, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000111,B00000001, - B10000111,B11111110,B00000111,B00000001, - B10000111,B11111110,B00111111,B11100001, - B10000000,B01100000,B00011111,B11000001, - B10000000,B01100000,B00001111,B10000001, - B10000000,B01100000,B00000111,B00000001, - B10000000,B01100000,B00000010,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B10000000,B00000000,B00000000,B00000001, - B01111111,B11111111,B11111111,B11111110, - }; -#endif + #else + + static const uint8_t buttonA[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B01000000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000001,B11110000,B00000000,B00000001, + B10000011,B11111000,B00000000,B00000001, + B10000111,B11111100,B00111111,B11100001, + B10000000,B11100000,B00111111,B11100001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B11100000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; + + static const uint8_t buttonB[] = { + B01111111,B11111111,B11111111,B11111110, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000111,B00000001, + B10000111,B11111110,B00000111,B00000001, + B10000111,B11111110,B00111111,B11100001, + B10000000,B01100000,B00011111,B11000001, + B10000000,B01100000,B00001111,B10000001, + B10000000,B01100000,B00000111,B00000001, + B10000000,B01100000,B00000010,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B10000000,B00000000,B00000000,B00000001, + B01111111,B11111111,B11111111,B11111110, + }; + + #endif static const uint8_t buttonC[] = { B01111111,B11111111,B11111111,B11111110, @@ -400,11 +404,8 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341 // Used to fill RGB565 (16bits) background inline void memset2(const void *ptr, uint16_t fill, size_t cnt) { - uint16_t* wptr = (uint16_t*) ptr; - for (size_t i = 0; i < cnt; i += 2) { - *wptr = fill; - wptr++; - } + uint16_t* wptr = (uint16_t*)ptr; + for (size_t i = 0; i < cnt; i += 2) { *wptr = fill; wptr++; } } static bool preinit = true; diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 839e8503bf87..4370fc1c2edf 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -765,6 +765,7 @@ 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 @@ -775,8 +776,9 @@ void MarlinUI::update() { }; #if ENABLED(TOUCH_BUTTONS) - // Uodate touch buttons after update buttons - // This prevent overlaping Encoder Process + + // Update touch buttons after update buttons + // to prevent overlapping Encoder Process if (ELAPSED(ms, next_button_update_ms)) { touch_buttons = read_touch_buttons(); buttons |= touch_buttons; @@ -790,7 +792,7 @@ void MarlinUI::update() { generate_click(); else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage" next_button_update_ms = ms + 50; // Set delay for continuous click - encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection ; + encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; if (buttons & EN_B) encoderDiff *= -1; buttons = 0; // Job done, clear buttons to prevent unwanted process. if (!wait_for_unclick) { // If begin of click process then @@ -805,9 +807,7 @@ void MarlinUI::update() { else #endif // TOUCH_BUTTONS { - // - // Integrated LCD click handling via button_pressed() - // + // Integrated LCD click handling via button_pressed if (!external_control && button_pressed()) generate_click(); else From a3a2d9477c18d4eaba619ea86d2681d8674d8e65 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 30 Aug 2019 20:53:43 -0500 Subject: [PATCH 3/9] Simplify touch button code --- Marlin/src/lcd/ultralcd.cpp | 93 +++++++++++++++++-------------------- Marlin/src/lcd/ultralcd.h | 4 -- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 4370fc1c2edf..2bc28a0f8a02 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -116,8 +116,6 @@ #endif #if ENABLED(TOUCH_BUTTONS) #include "../feature/touch/xpt2046.h" - volatile uint8_t MarlinUI::touch_buttons; - uint8_t MarlinUI::read_touch_buttons() { return touch.read_buttons(); } #endif #endif @@ -345,9 +343,6 @@ void MarlinUI::init() { #if HAS_SLOW_BUTTONS slow_buttons = 0; #endif - #if ENABLED(TOUCH_BUTTONS) - touch_buttons = 0; - #endif #endif update_buttons(); @@ -764,62 +759,55 @@ void MarlinUI::update() { update_buttons(); // 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 - } - }; + static bool wait_for_unclick; // = false #if ENABLED(TOUCH_BUTTONS) - // Update touch buttons after update buttons - // to prevent overlapping Encoder Process - if (ELAPSED(ms, next_button_update_ms)) { - touch_buttons = read_touch_buttons(); - buttons |= touch_buttons; - } + static bool arrow_pressed; // = false - if (touch_buttons) { - #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif - if (buttons & EN_C) - generate_click(); - else if (buttons & (EN_A | EN_B)) { // Ignore the encoder if clicked, to prevent "slippage" - next_button_update_ms = ms + 50; // Set delay for continuous click - encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; - if (buttons & EN_B) encoderDiff *= -1; - buttons = 0; // Job done, clear buttons to prevent unwanted process. - if (!wait_for_unclick) { // If begin of click process then - next_button_update_ms += 250; // add delay time - #if HAS_BUZZER // beep if posible - buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); - #endif - wait_for_unclick = true; // - Set debounce flag to mark continous clicks + // Handle touch_buttons which are slow to read + if (ELAPSED(ms, next_button_update_ms)) { + const uint8_t touch_buttons = touch.read_buttons(), + touch_arrows = touch_buttons & (EN_A | EN_B); + if (touch_buttons) { + if (touch_buttons & EN_C) buttons |= EN_C; + #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS + return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; + #endif + if (touch_arrows) { + next_button_update_ms = ms + 50; // Set delay for repeat + encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; + if (touch_buttons & EN_B) encoderDiff *= -1; + if (!wait_for_unclick && !arrow_pressed) { // On click prepare for repeat + arrow_pressed = true; // Mark arrow as pressed + next_button_update_ms += 250; // Longer delay on first press + #if HAS_BUZZER + buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); + #endif + } } } + if (!touch_arrows) arrow_pressed = false; } - else + #endif // TOUCH_BUTTONS - { - // Integrated LCD click handling via button_pressed - if (!external_control && button_pressed()) - generate_click(); - else - wait_for_unclick = false; - } - #if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS)) - if (LCD_BACK_CLICKED()) { - quick_feedback(); - goto_previous_screen(); + // 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 + } + else + wait_for_unclick = false; + + if (LCD_BACK_CLICKED()) { + quick_feedback(); + goto_previous_screen(); + } #endif // HAS_LCD_MENU @@ -1241,8 +1229,11 @@ void MarlinUI::update() { | slow_buttons #endif ; + #elif HAS_ADC_BUTTONS + buttons = 0; + #endif #if HAS_ADC_BUTTONS diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index 26e9261bd528..968dfd3ec747 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -531,10 +531,6 @@ class MarlinUI { static volatile uint8_t slow_buttons; static uint8_t read_slow_buttons(); #endif - #if ENABLED(TOUCH_BUTTONS) - static volatile uint8_t touch_buttons; - static uint8_t read_touch_buttons(); - #endif static void update_buttons(); static inline bool button_pressed() { return BUTTON_CLICK(); } From bdea5e09554a618f2bd5f1911870cf5ab22db809 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 30 Aug 2019 21:50:54 -0500 Subject: [PATCH 4/9] No "pulses" needed for touch buttons --- Marlin/src/inc/Conditionals_LCD.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 2d088ed30bcb..0e1e65c87f17 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -288,7 +288,11 @@ #endif #ifndef STD_ENCODER_PULSES_PER_STEP - #define STD_ENCODER_PULSES_PER_STEP 5 + #if ENABLED(TOUCH_BUTTONS) + #define STD_ENCODER_PULSES_PER_STEP 1 + #else + #define STD_ENCODER_PULSES_PER_STEP 5 + #endif #endif #ifndef STD_ENCODER_STEPS_PER_MENU_ITEM #define STD_ENCODER_STEPS_PER_MENU_ITEM 1 From fcf84d5a39e5cd434e93531a0d3a44b40da1b893 Mon Sep 17 00:00:00 2001 From: robbycandra Date: Sat, 31 Aug 2019 22:34:51 +0700 Subject: [PATCH 5/9] Back Button and prepare for full screen touch function --- Marlin/src/lcd/ultralcd.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 2bc28a0f8a02..f75179de50ae 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -767,14 +767,28 @@ void MarlinUI::update() { // Handle touch_buttons which are slow to read if (ELAPSED(ms, next_button_update_ms)) { - const uint8_t touch_buttons = touch.read_buttons(), - touch_arrows = touch_buttons & (EN_A | EN_B); + uint8_t touch_buttons = touch.read_buttons(); if (touch_buttons) { - if (touch_buttons & EN_C) buttons |= EN_C; #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; #endif - if (touch_arrows) { + // B1000000 ia a flag that touched area is Menu Item. + if (touch_buttons & B10000000) { // Processing Menu Area touch + if (!wait_for_unclick) { // If not waiting for a debounce release: + wait_for_unclick = true; // - Set debounce flag to ignore continous clicks + wait_for_user = false; // - Any click clears wait for user + // TODO for next PR. + // lcd_menu_touched_coord = touch_buttons; // Safe 7bit touched screen coordinate + next_button_update_ms = millis() + 500; // Set Delay + #if HAS_LCD_MENU + refresh(); + #endif + } + touch_buttons = 0; + } + if (touch_buttons & EN_C) buttons |= EN_C; + if (touch_buttons & EN_D) buttons |= EN_D; + if (touch_buttons & (EN_A | EN_B)) { next_button_update_ms = ms + 50; // Set delay for repeat encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; if (touch_buttons & EN_B) encoderDiff *= -1; @@ -787,7 +801,7 @@ void MarlinUI::update() { } } } - if (!touch_arrows) arrow_pressed = false; + if (!(touch_buttons & (EN_A | EN_B))) arrow_pressed = false; } #endif // TOUCH_BUTTONS From bc26cf59618459b40171475413e43c9046049384 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 31 Aug 2019 20:21:24 -0500 Subject: [PATCH 6/9] Simplify return-to-status timer --- Marlin/src/lcd/ultralcd.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index f75179de50ae..8ae74b8d86c9 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -741,16 +741,19 @@ void MarlinUI::update() { static millis_t next_lcd_update_ms; millis_t ms = millis(); + #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS + static millis_t return_to_status_ms = 0; + #define RESET_STATUS_TIMEOUT() (return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS) + #else + #define RESET_STATUS_TIMEOUT() NOOP + #endif + #ifdef LED_BACKLIGHT_TIMEOUT leds.update_timeout(powersupply_on); #endif #if HAS_LCD_MENU - #if LCD_TIMEOUT_TO_STATUS - static millis_t return_to_status_ms = 0; - #endif - // Handle any queued Move Axis motion manage_manual_move(); @@ -769,14 +772,12 @@ void MarlinUI::update() { if (ELAPSED(ms, next_button_update_ms)) { uint8_t touch_buttons = touch.read_buttons(); if (touch_buttons) { - #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif // B1000000 ia a flag that touched area is Menu Item. if (touch_buttons & B10000000) { // Processing Menu Area touch if (!wait_for_unclick) { // If not waiting for a debounce release: wait_for_unclick = true; // - Set debounce flag to ignore continous clicks wait_for_user = false; // - Any click clears wait for user + RESET_STATUS_TIMEOUT(); // TODO for next PR. // lcd_menu_touched_coord = touch_buttons; // Safe 7bit touched screen coordinate next_button_update_ms = millis() + 500; // Set Delay @@ -896,13 +897,7 @@ void MarlinUI::update() { #endif #if ENABLED(REPRAPWORLD_KEYPAD) - - if (handle_keypad()) { - #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif - } - + if (handle_keypad()) RESET_STATUS_TIMEOUT(); #endif const float abs_diff = ABS(encoderDiff); @@ -948,9 +943,7 @@ void MarlinUI::update() { encoderDiff = 0; } - #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif + RESET_STATUS_TIMEOUT(); refresh(LCDVIEW_REDRAW_NOW); @@ -983,9 +976,7 @@ void MarlinUI::update() { lcd_status_update_delay = 12; } refresh(LCDVIEW_REDRAW_NOW); - #if LCD_TIMEOUT_TO_STATUS - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; - #endif + RESET_STATUS_TIMEOUT(); } #endif @@ -1059,7 +1050,7 @@ void MarlinUI::update() { #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS // Return to Status Screen after a timeout if (on_status_screen() || defer_return_to_status) - return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; + RESET_STATUS_TIMEOUT(); else if (ELAPSED(ms, return_to_status_ms)) return_to_status(); #endif From 7b1dab3f01be8b159e8ea50150efe275468259b8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 31 Aug 2019 20:21:56 -0500 Subject: [PATCH 7/9] Adjust touch code, comments --- Marlin/src/lcd/ultralcd.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 8ae74b8d86c9..9cdaa12a4bc9 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -766,36 +766,36 @@ void MarlinUI::update() { #if ENABLED(TOUCH_BUTTONS) + #define TOUCH_MENU_MASK 0x80 + static bool arrow_pressed; // = false - // Handle touch_buttons which are slow to read + // Handle touch events which are slow to read if (ELAPSED(ms, next_button_update_ms)) { uint8_t touch_buttons = touch.read_buttons(); if (touch_buttons) { - // B1000000 ia a flag that touched area is Menu Item. - if (touch_buttons & B10000000) { // Processing Menu Area touch - if (!wait_for_unclick) { // If not waiting for a debounce release: - wait_for_unclick = true; // - Set debounce flag to ignore continous clicks - wait_for_user = false; // - Any click clears wait for user RESET_STATUS_TIMEOUT(); + if (touch_buttons & TOUCH_MENU_MASK) { // Processing Menu Area touch? + if (!wait_for_unclick) { // If not waiting for a debounce release: + wait_for_unclick = true; // - Set debounce flag to ignore continous clicks + wait_for_user = false; // - Any click clears wait for user // TODO for next PR. - // lcd_menu_touched_coord = touch_buttons; // Safe 7bit touched screen coordinate - next_button_update_ms = millis() + 500; // Set Delay + //uint8_t tpos = touch_buttons & ~(TOUCH_MENU_MASK); // Safe 7bit touched screen coordinate + next_button_update_ms = ms + 500; // Defer next check for 1/2 second #if HAS_LCD_MENU refresh(); #endif - } - touch_buttons = 0; + } + touch_buttons = 0; // Swallow the touch } - if (touch_buttons & EN_C) buttons |= EN_C; - if (touch_buttons & EN_D) buttons |= EN_D; - if (touch_buttons & (EN_A | EN_B)) { - next_button_update_ms = ms + 50; // Set delay for repeat + buttons |= (touch_buttons & (EN_C | EN_D)); // Pass on Click and Back buttons + if (touch_buttons & (EN_A | EN_B)) { // A and/or B button? encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; if (touch_buttons & EN_B) encoderDiff *= -1; + next_button_update_ms = ms + 50; // Assume the repeat delay if (!wait_for_unclick && !arrow_pressed) { // On click prepare for repeat - arrow_pressed = true; // Mark arrow as pressed next_button_update_ms += 250; // Longer delay on first press + arrow_pressed = true; // Mark arrow as pressed #if HAS_BUZZER buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); #endif From ee4b53c651b45011a77e98ee33db185b85abb850 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 31 Aug 2019 20:32:55 -0500 Subject: [PATCH 8/9] Fix next_button_update_ms for slow buttons --- Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp | 6 +++--- Marlin/src/lcd/ultralcd.cpp | 2 +- Marlin/src/lcd/ultralcd.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp index a8cf421dcb8d..b7ebc111a5e6 100644 --- a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp @@ -371,8 +371,8 @@ bool MarlinUI::detected() { #if HAS_SLOW_BUTTONS uint8_t MarlinUI::read_slow_buttons() { #if ENABLED(LCD_I2C_TYPE_MCP23017) - // Reading these buttons this is likely to be too slow to call inside interrupt context - // so they are called during normal lcd_update + // Reading these buttons is too slow for interrupt context + // so they are read during LCD update in the main loop. uint8_t slow_bits = lcd.readButtons() #if !BUTTON_EXISTS(ENC) << B_I2C_BTN_OFFSET @@ -381,7 +381,7 @@ bool MarlinUI::detected() { #if ENABLED(LCD_I2C_VIKI) if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated - #endif // LCD_I2C_VIKI + #endif return slow_bits; #endif // LCD_I2C_TYPE_MCP23017 } diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 9cdaa12a4bc9..936ab00ec21d 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -133,7 +133,7 @@ uint8_t MarlinUI::lcd_status_update_delay = 1; // First update one loop delayed millis_t MarlinUI::next_filament_display; // = 0 #endif -millis_t next_button_update_ms; +millis_t MarlinUI::next_button_update_ms; // = 0 #if HAS_GRAPHICAL_LCD bool MarlinUI::drawing_screen, MarlinUI::first_page; // = false diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index 968dfd3ec747..973fbc451e92 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -306,6 +306,8 @@ class MarlinUI { #if HAS_SPI_LCD + static millis_t next_button_update_ms; + static bool detected(); static LCDViewAction lcdDrawUpdate; From 4005250079a20279d86d48a4dc86576af158c910 Mon Sep 17 00:00:00 2001 From: robbycandra Date: Wed, 4 Sep 2019 10:46:12 +0700 Subject: [PATCH 9/9] Reverse Default Encoder Direction --- Marlin/src/lcd/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 936ab00ec21d..ba2de995e428 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -791,7 +791,7 @@ void MarlinUI::update() { buttons |= (touch_buttons & (EN_C | EN_D)); // Pass on Click and Back buttons if (touch_buttons & (EN_A | EN_B)) { // A and/or B button? encoderDiff = (ENCODER_STEPS_PER_MENU_ITEM) * (ENCODER_PULSES_PER_STEP) * encoderDirection; - if (touch_buttons & EN_B) encoderDiff *= -1; + if (touch_buttons & EN_A) encoderDiff *= -1; next_button_update_ms = ms + 50; // Assume the repeat delay if (!wait_for_unclick && !arrow_pressed) { // On click prepare for repeat next_button_update_ms += 250; // Longer delay on first press