From 10b9632bed6ef78ef2460b71526111d89b4113c2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 4 Apr 2019 02:29:44 -0500 Subject: [PATCH] Fix menu history item selection --- Marlin/src/lcd/menu/menu.cpp | 23 ++++++++++------------- Marlin/src/lcd/menu/menu.h | 4 ++-- Marlin/src/lcd/ultralcd.h | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 77b2e18fa7..0365df2356 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -54,10 +54,12 @@ //////////////////////////////////////////// // Menu Navigation -int8_t encoderTopLine; +int8_t encoderTopLine, encoderLine, screen_items; + typedef struct { screenFunc_t menu_function; uint32_t encoder_position; + uint8_t top_line, items; } menuPosition; menuPosition screen_history[6]; uint8_t screen_history_depth = 0; @@ -80,20 +82,14 @@ bool no_reentry = false; void MarlinUI::return_to_status() { goto_screen(status_screen); } void MarlinUI::save_previous_screen() { - if (screen_history_depth < COUNT(screen_history)) { - screen_history[screen_history_depth].menu_function = currentScreen; - screen_history[screen_history_depth].encoder_position = encoderPosition; - ++screen_history_depth; - } + if (screen_history_depth < COUNT(screen_history)) + screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items }; } void MarlinUI::goto_previous_screen() { if (screen_history_depth > 0) { - --screen_history_depth; - goto_screen( - screen_history[screen_history_depth].menu_function, - screen_history[screen_history_depth].encoder_position - ); + menuPosition &sh = screen_history[--screen_history_depth]; + goto_screen(sh.menu_function, sh.encoder_position, sh.top_line, sh.items); } else return_to_status(); @@ -197,7 +193,7 @@ bool printer_busy() { /** * General function to go directly to a screen */ -void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) { +void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) { if (currentScreen != screen) { #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) @@ -246,6 +242,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) { currentScreen = screen; encoderPosition = encoder; + encoderTopLine = top; + screen_items = items; if (screen == status_screen) { defer_status_screen(false); #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -314,7 +312,6 @@ void MarlinUI::synchronize(PGM_P const msg/*=NULL*/) { * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM * screen_items is the total number of items in the menu (after one call) */ -int8_t encoderLine, screen_items; void scroll_screen(const uint8_t limit, const bool is_menu) { ui.encoder_direction_menus(); ENCODER_RATE_MULTIPLY(false); diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index c17f116775..e695a02433 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -309,8 +309,8 @@ class MenuItem_bool { #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL) #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0) -#define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__) -#define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__) +#define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__) +#define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__) #define MENU_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__) #define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__) #define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__) diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index f8899f1175..df36256ba1 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -419,7 +419,7 @@ public: static void synchronize(PGM_P const msg=NULL); static screenFunc_t currentScreen; - static void goto_screen(const screenFunc_t screen, const uint32_t encoder=0); + static void goto_screen(const screenFunc_t screen, const uint32_t encoder=0, const uint8_t top=0, const uint8_t items=0); static void save_previous_screen(); static void goto_previous_screen(); static void return_to_status();