Browse Source

🐛 Fix Manual Move axis selection (#24404)

Scott Lahteine 1 year ago
parent
commit
d8545551fe

+ 9
- 9
Marlin/src/lcd/e3v2/jyersui/dwin.cpp View File

@@ -283,7 +283,7 @@ CrealityDWINClass CrealityDWIN;
283 283
 
284 284
     #endif
285 285
 
286
-    void manual_move(bool zmove=false) {
286
+    void manual_mesh_move(const bool zmove=false) {
287 287
       if (zmove) {
288 288
         planner.synchronize();
289 289
         current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
@@ -3035,7 +3035,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3035 3035
                   mesh_conf.goto_mesh_value = true;
3036 3036
                   mesh_conf.mesh_x = mesh_conf.mesh_y = 0;
3037 3037
                   Popup_Handler(MoveWait);
3038
-                  mesh_conf.manual_move();
3038
+                  mesh_conf.manual_mesh_move();
3039 3039
                   Draw_Menu(UBLMesh);
3040 3040
                 #endif
3041 3041
               #elif HAS_BED_PROBE
@@ -3091,7 +3091,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3091 3091
                 TERN_(HAS_HEATED_BED, thermalManager.wait_for_bed_heating());
3092 3092
               #endif
3093 3093
               Popup_Handler(MoveWait);
3094
-              mesh_conf.manual_move();
3094
+              mesh_conf.manual_mesh_move();
3095 3095
               Draw_Menu(LevelManual);
3096 3096
             }
3097 3097
             break;
@@ -3328,7 +3328,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3328 3328
                   mesh_conf.mesh_x++;
3329 3329
                 else
3330 3330
                   mesh_conf.mesh_x--;
3331
-                mesh_conf.manual_move();
3331
+                mesh_conf.manual_mesh_move();
3332 3332
               }
3333 3333
             }
3334 3334
             break;
@@ -3375,7 +3375,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3375 3375
             else {
3376 3376
               mesh_conf.goto_mesh_value = !mesh_conf.goto_mesh_value;
3377 3377
               current_position.z = 0;
3378
-              mesh_conf.manual_move(true);
3378
+              mesh_conf.manual_mesh_move(true);
3379 3379
               Draw_Checkbox(row, mesh_conf.goto_mesh_value);
3380 3380
             }
3381 3381
             break;
@@ -3428,7 +3428,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3428 3428
                   mesh_conf.mesh_x++;
3429 3429
                 else
3430 3430
                   mesh_conf.mesh_x--;
3431
-                mesh_conf.manual_move();
3431
+                mesh_conf.manual_mesh_move();
3432 3432
               }
3433 3433
               else {
3434 3434
                 gcode.process_subcommands_now(F("G29 S"));
@@ -3449,7 +3449,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
3449 3449
                   mesh_conf.mesh_x--;
3450 3450
                 else
3451 3451
                   mesh_conf.mesh_x++;
3452
-                mesh_conf.manual_move();
3452
+                mesh_conf.manual_mesh_move();
3453 3453
               }
3454 3454
             }
3455 3455
             break;
@@ -4109,8 +4109,8 @@ void CrealityDWINClass::Value_Control() {
4109 4109
           planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
4110 4110
           planner.synchronize();
4111 4111
           break;
4112
-        case UBLMesh:     mesh_conf.manual_move(true); break;
4113
-        case LevelManual: mesh_conf.manual_move(selection == LEVELING_M_OFFSET); break;
4112
+        case UBLMesh:     mesh_conf.manual_mesh_move(true); break;
4113
+        case LevelManual: mesh_conf.manual_mesh_move(selection == LEVELING_M_OFFSET); break;
4114 4114
       #endif
4115 4115
     }
4116 4116
     if (valuepointer == &planner.flow_percentage[0])

+ 1
- 2
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp View File

@@ -410,8 +410,7 @@ void MarlinUI::draw_status_message(const bool blink) {
410 410
       const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
411 411
       DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));
412 412
 
413
-      extern screenFunc_t _manual_move_func_ptr;
414
-      if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
413
+      if (ui.can_show_slider()) {
415 414
 
416 415
         const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
417 416
                            slider_height = 16,

+ 1
- 1
Marlin/src/lcd/language/language_en.h View File

@@ -309,7 +309,7 @@ namespace Language_en {
309 309
   LSTR MSG_MOVE_Z                         = _UxGT("Move Z");
310 310
   LSTR MSG_MOVE_N                         = _UxGT("Move @");
311 311
   LSTR MSG_MOVE_E                         = _UxGT("Move Extruder");
312
-  LSTR MSG_MOVE_EN                        = _UxGT("Move E*");
312
+  LSTR MSG_MOVE_EN                        = _UxGT("Move *");
313 313
   LSTR MSG_HOTEND_TOO_COLD                = _UxGT("Hotend too cold");
314 314
   LSTR MSG_MOVE_N_MM                      = _UxGT("Move $mm");
315 315
   LSTR MSG_MOVE_01MM                      = _UxGT("Move 0.1mm");

+ 5
- 4
Marlin/src/lcd/marlinui.cpp View File

@@ -763,6 +763,7 @@ void MarlinUI::init() {
763 763
 
764 764
     millis_t ManualMove::start_time = 0;
765 765
     float ManualMove::menu_scale = 1;
766
+    screenFunc_t ManualMove::screen_ptr;
766 767
     #if IS_KINEMATIC
767 768
       float ManualMove::offset = 0;
768 769
       xyze_pos_t ManualMove::all_axes_destination = { 0 };
@@ -772,6 +773,9 @@ void MarlinUI::init() {
772 773
       int8_t ManualMove::e_index = 0;
773 774
     #endif
774 775
     AxisEnum ManualMove::axis = NO_AXIS_ENUM;
776
+    #if ENABLED(MANUAL_E_MOVES_RELATIVE)
777
+      float ManualMove::e_origin = 0;
778
+    #endif
775 779
 
776 780
     /**
777 781
      * If a manual move has been posted and its time has arrived, and if the planner
@@ -788,9 +792,6 @@ void MarlinUI::init() {
788 792
      * For kinematic machines:
789 793
      *   - Set manual_move.offset to modify one axis and post the move.
790 794
      *     This is used to achieve more rapid stepping on kinematic machines.
791
-     *
792
-     * Currently used by the _lcd_move_xyz function in menu_motion.cpp
793
-     * and the ubl_map_move_to_xy function in menu_ubl.cpp.
794 795
      */
795 796
     void ManualMove::task() {
796 797
 
@@ -861,7 +862,7 @@ void MarlinUI::init() {
861 862
 
862 863
       void MarlinUI::external_encoder() {
863 864
         if (external_control && encoderDiff) {
864
-          bedlevel.encoder_diff += encoderDiff;  // Encoder for UBL G29 mesh editing
865
+          bedlevel.encoder_diff += encoderDiff; // Encoder for UBL G29 mesh editing
865 866
           encoderDiff = 0;                  // Hide encoder events from the screen handler
866 867
           refresh(LCDVIEW_REDRAW_NOW);      // ...but keep the refresh.
867 868
         }

+ 9
- 9
Marlin/src/lcd/marlinui.h View File

@@ -137,12 +137,16 @@ typedef bool (*statusResetFunc_t)();
137 137
       static xyze_pos_t all_axes_destination;
138 138
     #endif
139 139
   public:
140
+    static screenFunc_t screen_ptr;
140 141
     static float menu_scale;
141 142
     #if IS_KINEMATIC
142 143
       static float offset;
143 144
     #endif
145
+    #if ENABLED(MANUAL_E_MOVES_RELATIVE)
146
+      static float e_origin;
147
+    #endif
144 148
     template <typename T>
145
-    void set_destination(const T& dest) {
149
+    static void set_destination(const T& dest) {
146 150
       #if IS_KINEMATIC
147 151
         // Moves are segmented, so the entire move is not submitted at once.
148 152
         // Using a separate variable prevents corrupting the in-progress move.
@@ -153,10 +157,10 @@ typedef bool (*statusResetFunc_t)();
153 157
         current_position.set(dest);
154 158
       #endif
155 159
     }
156
-    float axis_value(const AxisEnum axis) {
160
+    static float axis_value(const AxisEnum axis) {
157 161
       return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis);
158 162
     }
159
-    bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
163
+    static bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
160 164
       #if IS_KINEMATIC
161 165
         float &valref = offset;
162 166
         const float rmin = min - current_position[axis], rmax = max - current_position[axis];
@@ -166,12 +170,7 @@ typedef bool (*statusResetFunc_t)();
166 170
       #endif
167 171
       valref += diff;
168 172
       const float pre = valref;
169
-      if (min != max) {
170
-        if (diff < 0)
171
-          NOLESS(valref, rmin);
172
-        else
173
-          NOMORE(valref, rmax);
174
-      }
173
+      if (min != max) { if (diff < 0) NOLESS(valref, rmin); else NOMORE(valref, rmax); }
175 174
       return pre != valref;
176 175
     }
177 176
     #if IS_KINEMATIC
@@ -552,6 +551,7 @@ public:
552 551
 
553 552
     // Manual Movement
554 553
     static ManualMove manual_move;
554
+    static bool can_show_slider() { return !external_control && currentScreen != manual_move.screen_ptr; }
555 555
 
556 556
     // Select Screen (modal NO/YES style dialog)
557 557
     static bool selection;

+ 18
- 31
Marlin/src/lcd/menu/menu_motion.cpp View File

@@ -46,15 +46,11 @@
46 46
   #include "../../feature/bedlevel/bedlevel.h"
47 47
 #endif
48 48
 
49
-#if ENABLED(MANUAL_E_MOVES_RELATIVE)
50
-  float manual_move_e_origin = 0;
51
-#endif
52
-
53 49
 //
54 50
 // "Motion" > "Move Axis" submenu
55 51
 //
56 52
 
57
-static void _lcd_move_xyz(const AxisEnum axis) {
53
+void lcd_move_axis(const AxisEnum axis) {
58 54
   if (ui.use_click()) return ui.goto_previous_screen_no_defer();
59 55
   if (ui.encoderPosition && !ui.manual_move.processing) {
60 56
     // Get motion limit from software endstops, if any
@@ -88,11 +84,6 @@ static void _lcd_move_xyz(const AxisEnum axis) {
88 84
   }
89 85
 }
90 86
 
91
-void _lcd_move_axis_n() { _lcd_move_xyz(AxisEnum(MenuItemBase::itemIndex)); }
92
-
93
-// Move functions for non-menu code that hasn't set itemIndex (e.g., keypad)
94
-void lcd_move_axis(const AxisEnum axis) { MenuEditItemBase::itemIndex = int8_t(axis); _lcd_move_axis_n(); }
95
-
96 87
 // Move Z easy accessor
97 88
 void lcd_move_z() { lcd_move_axis(Z_AXIS); }
98 89
 
@@ -115,7 +106,7 @@ void lcd_move_z() { lcd_move_axis(Z_AXIS); }
115 106
         GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
116 107
         ftostr41sign(current_position.e
117 108
           PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
118
-          MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
109
+          MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin)
119 110
         )
120 111
       );
121 112
     } // should_draw
@@ -140,26 +131,22 @@ void lcd_move_z() { lcd_move_axis(Z_AXIS); }
140 131
   #define FINE_MANUAL_MOVE 0.025
141 132
 #endif
142 133
 
143
-screenFunc_t _manual_move_func_ptr;
144
-
145 134
 void _goto_manual_move(const_float_t scale) {
146 135
   ui.defer_status_screen();
147 136
   ui.manual_move.menu_scale = scale;
148
-  ui.goto_screen(_manual_move_func_ptr);
137
+  ui.goto_screen(ui.manual_move.screen_ptr);
149 138
   thermalManager.set_menu_cold_override(true);
150 139
 }
151 140
 
152 141
 void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
153
-  _manual_move_func_ptr = func;
142
+  ui.manual_move.screen_ptr = func;
154 143
   START_MENU();
155 144
   if (LCD_HEIGHT >= 4) {
156
-    switch (axis) {
157
-      #define _CASE_MOVE(N) case N##_AXIS: STATIC_ITEM_N(N##_AXIS, MSG_MOVE_N, SS_DEFAULT|SS_INVERT); break;
158
-      MAIN_AXIS_MAP(_CASE_MOVE)
159
-      default:
160
-        TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e);
161
-        STATIC_ITEM(MSG_MOVE_E, SS_DEFAULT|SS_INVERT);
162
-        break;
145
+    if (axis < NUM_AXES)
146
+      STATIC_ITEM_N(axis, MSG_MOVE_N, SS_DEFAULT|SS_INVERT);
147
+    else {
148
+      TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = current_position.e);
149
+      STATIC_ITEM_N(eindex, MSG_MOVE_EN, SS_DEFAULT|SS_INVERT);
163 150
     }
164 151
   }
165 152
 
@@ -181,8 +168,6 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
181 168
   END_MENU();
182 169
 }
183 170
 
184
-void _menu_move_n_distance() { _menu_move_distance(AxisEnum(MenuItemBase::itemIndex), _lcd_move_axis_n); }
185
-
186 171
 #if E_MANUAL
187 172
 
188 173
   inline void _goto_menu_move_distance_e() {
@@ -216,8 +201,10 @@ void menu_move() {
216 201
   // Move submenu for each axis
217 202
   if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
218 203
     if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
219
-      for (uint8_t a = X_AXIS; a <= min(int(Y_AXIS), NUM_AXES - 1); a++)
220
-        SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance);
204
+      SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); });
205
+      #if HAS_Y_AXIS
206
+        SUBMENU_N(Y_AXIS, MSG_MOVE_N, []{ _menu_move_distance(Y_AXIS, []{ lcd_move_axis(Y_AXIS); }); });
207
+      #endif
221 208
     }
222 209
     else {
223 210
       #if ENABLED(DELTA)
@@ -225,8 +212,8 @@ void menu_move() {
225 212
       #endif
226 213
     }
227 214
     #if HAS_Z_AXIS
228
-      for (uint8_t a = Z_AXIS; a < NUM_AXES; a++)
229
-        SUBMENU_N(a, MSG_MOVE_N, _menu_move_n_distance);
215
+      #define _AXIS_MOVE(N) SUBMENU_N(N, MSG_MOVE_N, []{ _menu_move_distance(AxisEnum(N), []{ lcd_move_axis(AxisEnum(N)); }); });
216
+      REPEAT_S(2, NUM_AXES, _AXIS_MOVE);
230 217
     #endif
231 218
   }
232 219
   else
@@ -271,9 +258,9 @@ void menu_move() {
271 258
   #if E_MANUAL
272 259
 
273 260
     // The current extruder
274
-    SUBMENU(MSG_MOVE_E, []{ _menu_move_distance_e_maybe(); });
261
+    SUBMENU(MSG_MOVE_E, _menu_move_distance_e_maybe);
275 262
 
276
-    #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(MenuItemBase::itemIndex); }, MenuItemBase::itemIndex); });
263
+    #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(N); }, N); });
277 264
 
278 265
     #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
279 266
 
@@ -285,7 +272,7 @@ void menu_move() {
285 272
     #elif MULTI_E_MANUAL
286 273
 
287 274
       // Independent extruders with one E stepper per hotend
288
-      LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
275
+      REPEAT(E_MANUAL, SUBMENU_MOVE_E);
289 276
 
290 277
     #endif
291 278
 

+ 1
- 2
Marlin/src/lcd/tft/ui_1024x600.cpp View File

@@ -394,8 +394,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
394 394
     }
395 395
   #endif
396 396
 
397
-  extern screenFunc_t _manual_move_func_ptr;
398
-  if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
397
+  if (ui.can_show_slider()) {
399 398
 
400 399
     #define SLIDER_LENGTH 600
401 400
     #define SLIDER_Y_POSITION 200

+ 1
- 2
Marlin/src/lcd/tft/ui_320x240.cpp View File

@@ -383,8 +383,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
383 383
     }
384 384
   #endif
385 385
 
386
-  extern screenFunc_t _manual_move_func_ptr;
387
-  if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
386
+  if (ui.can_show_slider()) {
388 387
 
389 388
     #define SLIDER_LENGTH 224
390 389
     #define SLIDER_Y_POSITION 140

+ 1
- 2
Marlin/src/lcd/tft/ui_480x320.cpp View File

@@ -388,8 +388,7 @@ void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const va
388 388
     }
389 389
   #endif
390 390
 
391
-  extern screenFunc_t _manual_move_func_ptr;
392
-  if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
391
+  if (ui.can_show_slider()) {
393 392
 
394 393
     #define SLIDER_LENGTH 336
395 394
     #define SLIDER_Y_POSITION 186

Loading…
Cancel
Save