From eca5e46d17322c0c45e1bea90238edf180cd4cca Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2022 21:19:41 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Simplify=20move=20menus=20with?= =?UTF-8?q?=20substitution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/menu/menu_advanced.cpp | 2 +- Marlin/src/lcd/menu/menu_motion.cpp | 79 ++++++++------------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index a6ebb10407..5d86b97b5d 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -483,7 +483,7 @@ void menu_backlash(); // M204 T Travel Acceleration EDIT_ITEM_FAST(float5_25, MSG_A_TRAVEL, &planner.settings.travel_acceleration, 25, max_accel); - #define EDIT_AMAX(Q,L) EDIT_ITEM_FAST(long5_25, MSG_AMAX_##Q, &planner.settings.max_acceleration_mm_per_s2[_AXIS(Q)], L, max_accel_edit_scaled[_AXIS(Q)], []{ planner.reset_acceleration_rates(); }) + #define EDIT_AMAX(Q,L) EDIT_ITEM_FAST_N(long5_25, _AXIS(Q), MSG_AMAX_N, &planner.settings.max_acceleration_mm_per_s2[_AXIS(Q)], L, max_accel_edit_scaled[_AXIS(Q)], []{ planner.reset_acceleration_rates(); }) NUM_AXIS_CODE( EDIT_AMAX(A, 100), EDIT_AMAX(B, 100), EDIT_AMAX(C, 10), EDIT_AMAX(I, 10), EDIT_AMAX(J, 10), EDIT_AMAX(K, 10), diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 151bd374c2..de16f90637 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -54,9 +54,7 @@ // "Motion" > "Move Axis" submenu // -// TODO: Use substitution here with MSG_MOVE_N - -static void _lcd_move_xyz(FSTR_P const name, const AxisEnum axis) { +static void _lcd_move_xyz(const AxisEnum axis) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); if (ui.encoderPosition && !ui.manual_move.processing) { // Get motion limit from software endstops, if any @@ -83,37 +81,20 @@ static void _lcd_move_xyz(FSTR_P const name, const AxisEnum axis) { const float pos = ui.manual_move.axis_value(axis); if (parser.using_inch_units()) { const float imp_pos = LINEAR_UNIT(pos); - MenuEditItemBase::draw_edit_screen(name, ftostr63(imp_pos)); + MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ftostr63(imp_pos)); } else - MenuEditItemBase::draw_edit_screen(name, ui.manual_move.menu_scale >= 0.1f ? (LARGE_AREA_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos)); + MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ui.manual_move.menu_scale >= 0.1f ? (LARGE_AREA_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos)); } } -void lcd_move_x() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_X), X_AXIS); } -#if HAS_Y_AXIS - void lcd_move_y() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_Y), Y_AXIS); } -#endif -#if HAS_Z_AXIS - void lcd_move_z() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_Z), Z_AXIS); } -#endif -#if HAS_I_AXIS - void lcd_move_i() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_I), I_AXIS); } -#endif -#if HAS_J_AXIS - void lcd_move_j() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_J), J_AXIS); } -#endif -#if HAS_K_AXIS - void lcd_move_k() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_K), K_AXIS); } -#endif -#if HAS_U_AXIS - void lcd_move_u() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_U), U_AXIS); } -#endif -#if HAS_V_AXIS - void lcd_move_v() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_V), V_AXIS); } -#endif -#if HAS_W_AXIS - void lcd_move_w() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_W), W_AXIS); } -#endif + +void _lcd_move_axis_n() { _lcd_move_xyz(AxisEnum(MenuItemBase::itemIndex)); } + +// Move functions for non-menu code that hasn't set itemIndex (e.g., keypad) +void lcd_move_axis(const AxisEnum axis) { MenuEditItemBase::itemIndex = int8_t(axis); _lcd_move_axis_n(); } + +// Move Z easy accessor +void lcd_move_z() { lcd_move_axis(Z_AXIS); } #if E_MANUAL @@ -200,6 +181,8 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int END_MENU(); } +void _menu_move_n_distance() { _menu_move_distance(AxisEnum(MenuItemBase::itemIndex), _lcd_move_axis_n); } + #if E_MANUAL inline void _goto_menu_move_distance_e() { @@ -230,38 +213,20 @@ void menu_move() { EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled); #endif + // Move submenu for each axis if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) { if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) { - SUBMENU(MSG_MOVE_X, []{ _menu_move_distance(X_AXIS, lcd_move_x); }); - #if HAS_Y_AXIS - SUBMENU(MSG_MOVE_Y, []{ _menu_move_distance(Y_AXIS, lcd_move_y); }); + for (uint8_t a = X_AXIS; a <= min(int(Y_AXIS), NUM_AXES - 1); a++) + SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance); + } + else { + #if ENABLED(DELTA) + ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); }); #endif } - #if ENABLED(DELTA) - else - ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); }); - #endif - #if HAS_Z_AXIS - SUBMENU(MSG_MOVE_Z, []{ _menu_move_distance(Z_AXIS, lcd_move_z); }); - #endif - #if HAS_I_AXIS - SUBMENU(MSG_MOVE_I, []{ _menu_move_distance(I_AXIS, lcd_move_i); }); - #endif - #if HAS_J_AXIS - SUBMENU(MSG_MOVE_J, []{ _menu_move_distance(J_AXIS, lcd_move_j); }); - #endif - #if HAS_K_AXIS - SUBMENU(MSG_MOVE_K, []{ _menu_move_distance(K_AXIS, lcd_move_k); }); - #endif - #if HAS_U_AXIS - SUBMENU(MSG_MOVE_U, []{ _menu_move_distance(U_AXIS, lcd_move_u); }); - #endif - #if HAS_V_AXIS - SUBMENU(MSG_MOVE_V, []{ _menu_move_distance(V_AXIS, lcd_move_v); }); - #endif - #if HAS_W_AXIS - SUBMENU(MSG_MOVE_W, []{ _menu_move_distance(W_AXIS, lcd_move_w); }); + for (uint8_t a = Z_AXIS; a < NUM_AXES; a++) + SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance); #endif } else