diff --git a/Marlin/src/lcd/menu/game/game.cpp b/Marlin/src/lcd/menu/game/game.cpp index 9393552437..d1f74a6bce 100644 --- a/Marlin/src/lcd/menu/game/game.cpp +++ b/Marlin/src/lcd/menu/game/game.cpp @@ -56,7 +56,6 @@ void MarlinGame::draw_game_over() { void MarlinGame::init_game(const uint8_t init_state, const screenFunc_t screen) { score = 0; game_state = init_state; - ui.encoder_direction_normal(); ui.goto_screen(screen); ui.defer_status_screen(); } diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 3d661c6f0f..d8f734bb02 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -130,7 +130,6 @@ void MenuItem_gcode::action(PGM_P const pgcode) { queue.inject_P(pgcode); } * MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999) */ void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) { - ui.encoder_direction_normal(); if (int16_t(ui.encoderPosition) < 0) ui.encoderPosition = 0; if (int16_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue; if (ui.should_draw()) @@ -276,7 +275,11 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co drawing_screen = false; #endif - set_ui_selection(false); + #if HAS_LCD_MENU + encoder_direction_normal(); + #endif + + set_selection(false); } } @@ -371,7 +374,6 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) { #else constexpr bool do_probe = true; #endif - ui.encoder_direction_normal(); if (ui.encoderPosition) { const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR); ui.encoderPosition = 0; @@ -448,14 +450,16 @@ void _lcd_draw_homing() { // // Selection screen presents a prompt and two options // -bool ui_selection; // = false -void set_ui_selection(const bool sel) { ui_selection = sel; } -void do_select_screen(PGM_P const yes, PGM_P const no, selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) { - if (ui.encoderPosition) { - ui_selection = ((ENCODERBASE) > 0) == (int16_t(ui.encoderPosition) > 0); - ui.encoderPosition = 0; +bool MarlinUI::selection; // = false +bool MarlinUI::update_selection() { + if (encoderPosition) { + selection = int16_t(encoderPosition) > 0; + encoderPosition = 0; } - const bool got_click = ui.use_click(); + return selection; +} +void do_select_screen(PGM_P const yes, PGM_P const no, selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) { + const bool ui_selection = ui.update_selection(), got_click = ui.use_click(); if (got_click || ui.should_draw()) { draw_select_screen(yes, no, ui_selection, pref, string, suff); if (got_click) { ui_selection ? yesFunc() : noFunc(); } diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index 7bd1c819cd..a51c154b51 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -71,7 +71,6 @@ DECLARE_MENU_EDIT_TYPE(uint32_t, long5_25, ftostr5rj, 0.04f ); // 123 typedef void (*selectFunc_t)(); void draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff); -void set_ui_selection(const bool sel); void do_select_screen(PGM_P const yes, PGM_P const no, selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr); inline void do_select_screen_yn(selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr) { do_select_screen(PSTR(MSG_YES), PSTR(MSG_NO), yesFunc, noFunc, pref, string, suff); diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 10d0e5d7cd..a559a68527 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -111,7 +111,7 @@ static inline void _lcd_level_bed_corners_homing() { if (all_axes_homed()) { bed_corner = 0; ui.goto_screen(menu_level_bed_corners); - set_ui_selection(true); + ui.set_selection(true); _lcd_goto_next_corner(); } } diff --git a/Marlin/src/lcd/menu/menu_bed_leveling.cpp b/Marlin/src/lcd/menu/menu_bed_leveling.cpp index c463faa910..70a04e2de0 100644 --- a/Marlin/src/lcd/menu/menu_bed_leveling.cpp +++ b/Marlin/src/lcd/menu/menu_bed_leveling.cpp @@ -89,7 +89,6 @@ // Step 7: Get the Z coordinate, click goes to the next point or exits // void _lcd_level_bed_get_z() { - ui.encoder_direction_normal(); if (ui.use_click()) { diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 2a258048e5..04f84d9818 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -62,7 +62,6 @@ static void lcd_factory_settings() { #include "../lcdprint.h" static void progress_bar_test() { - ui.encoder_direction_normal(); static int8_t bar_percent = 0; if (ui.use_click()) { ui.goto_previous_screen(); diff --git a/Marlin/src/lcd/menu/menu_mixer.cpp b/Marlin/src/lcd/menu/menu_mixer.cpp index 1a17dbd260..31f5107837 100644 --- a/Marlin/src/lcd/menu/menu_mixer.cpp +++ b/Marlin/src/lcd/menu/menu_mixer.cpp @@ -41,7 +41,6 @@ void lcd_mixer_gradient_z_start_edit() { ui.defer_status_screen(); - ui.encoder_direction_normal(); ENCODER_RATE_MULTIPLY(true); if (ui.encoderPosition != 0) { mixer.gradient.start_z += float(int16_t(ui.encoderPosition)) * 0.1; @@ -66,7 +65,6 @@ void lcd_mixer_gradient_z_end_edit() { ui.defer_status_screen(); - ui.encoder_direction_normal(); ENCODER_RATE_MULTIPLY(true); if (ui.encoderPosition != 0) { mixer.gradient.end_z += float(int16_t(ui.encoderPosition)) * 0.1; diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index a87329e325..4af8b8e58d 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -74,7 +74,6 @@ inline void manual_move_to_current(AxisEnum axis static void _lcd_move_xyz(PGM_P name, AxisEnum axis) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); - ui.encoder_direction_normal(); if (ui.encoderPosition && !ui.processing_manual_move) { // Start with no limits to movement @@ -158,7 +157,6 @@ static void _lcd_move_e( #endif ) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); - ui.encoder_direction_normal(); if (ui.encoderPosition) { if (!ui.processing_manual_move) { const float diff = float(int16_t(ui.encoderPosition)) * move_menu_scale; diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index adbcbefc56..1c038ea133 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -73,7 +73,6 @@ void _lcd_babystep(const AxisEnum axis, PGM_P const msg) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); - ui.encoder_direction_normal(); if (ui.encoderPosition) { const int16_t steps = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR); ui.encoderPosition = 0; diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 2323804658..3a84d22fdc 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -468,7 +468,6 @@ void _lcd_ubl_output_map_lcd() { static int16_t step_scaler = 0; if (ui.use_click()) return _lcd_ubl_map_lcd_edit_cmd(); - ui.encoder_direction_normal(); if (ui.encoderPosition) { step_scaler += int16_t(ui.encoderPosition); diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index b932b4b4c5..cf16395854 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -392,7 +392,7 @@ bool MarlinUI::get_blink() { #if HAS_ENCODER_ACTION refresh(LCDVIEW_REDRAW_NOW); #if HAS_LCD_MENU - if (encoderDirection == -1) { // ADC_KEYPAD forces REVERSE_MENU_DIRECTION, so this indicates menu navigation + if (encoderDirection == -(ENCODERBASE)) { // ADC_KEYPAD forces REVERSE_MENU_DIRECTION, so this indicates menu navigation if (RRK(EN_KEYPAD_UP)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; else if (RRK(EN_KEYPAD_DOWN)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM; else if (RRK(EN_KEYPAD_LEFT)) { MenuItem_back::action(); quick_feedback(); } @@ -480,7 +480,6 @@ bool MarlinUI::get_blink() { void MarlinUI::status_screen() { #if HAS_LCD_MENU - encoder_direction_normal(); ENCODER_RATE_MULTIPLY(false); #endif diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index f0fdbf764f..2abc562283 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -424,6 +424,11 @@ public: static int16_t preheat_hotend_temp[2], preheat_bed_temp[2]; static uint8_t preheat_fan_speed[2]; + // Select Screen (modal NO/YES style dialog) + static bool selection; + static void set_selection(const bool sel) { selection = sel; } + static bool update_selection(); + static void manage_manual_move(); static bool lcd_clicked;