From 1d504e596df79b0572de23f628af457a017b6be3 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 11 Jun 2020 23:21:18 -0300 Subject: [PATCH] Touch-to-jog on edit screens (#18266) --- Marlin/src/lcd/menu/menu.cpp | 6 +++--- Marlin/src/lcd/ultralcd.cpp | 18 ++++++++++++------ Marlin/src/lcd/ultralcd.h | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 0832ed8b3f..58a759655c 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -84,9 +84,8 @@ void MarlinUI::save_previous_screen() { } void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) { - #if DISABLED(TURBO_BACK_MENU_ITEM) - constexpr bool is_back = false; - #endif + TERN(TURBO_BACK_MENU_ITEM,,constexpr bool is_back = false); + TERN_(TOUCH_BUTTONS, on_edit_screen = false); if (screen_history_depth > 0) { menuPosition &sh = screen_history[--screen_history_depth]; goto_screen(sh.menu_function, @@ -155,6 +154,7 @@ void MenuEditItemBase::goto_edit_screen( const screenFunc_t cb, // Callback after edit const bool le // Flag to call cb() during editing ) { + TERN_(TOUCH_BUTTONS, ui.on_edit_screen = true); ui.screen_changed = true; ui.save_previous_screen(); ui.refresh(); diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 0869cbf5c5..4c416093ae 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -119,6 +119,7 @@ MarlinUI ui; #endif #if ENABLED(TOUCH_BUTTONS) #include "../feature/touch/xpt2046.h" + bool MarlinUI::on_edit_screen = false; #endif #endif @@ -1445,18 +1446,23 @@ void MarlinUI::update() { // - On menu screens move directly to the touched item // - On menu screens, right side (last 3 cols) acts like a scroll - half up => prev page, half down = next page // - On select screens (and others) touch the Right Half for +, Left Half for - + // - On edit screens, touch Up Half for -, Bottom Half to + // - void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y) { - if (screen_items > 0) { - //last 3 cols act as a scroll :-) + void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t, const uint8_t) { + const int8_t xdir = col < (LCD_WIDTH ) / 2 ? -1 : 1, + ydir = row < (LCD_HEIGHT) / 2 ? -1 : 1; + if (on_edit_screen) + encoderDiff = ENCODER_PULSES_PER_STEP * ydir; + else if (screen_items > 0) { + // Last 3 cols act as a scroll :-) if (col > (LCD_WIDTH) - 3) - //2 * LCD_HEIGHT to scroll to bottom of next page. If we did 1 * LCD_HEIGHT, it just go 1 item down - encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * (row < (LCD_HEIGHT) / 2 ? -1 : 1); + // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.) + encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir; else encoderDiff = ENCODER_PULSES_PER_STEP * (row - encoderPosition + encoderTopLine); } else if (!on_status_screen()) - encoderDiff = ENCODER_PULSES_PER_STEP * (col < (LCD_WIDTH) / 2 ? -1 : 1); + encoderDiff = ENCODER_PULSES_PER_STEP * xdir; } #endif diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index 1b3ffd7660..6ddacaf706 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -418,6 +418,7 @@ public: #endif #if ENABLED(TOUCH_BUTTONS) + static bool on_edit_screen; static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y); #endif