Browse Source

Streamline menu item logic (#17664)

Scott Lahteine 4 years ago
parent
commit
4f003fc7a7
No account linked to committer's email address

+ 38
- 1
Marlin/src/lcd/menu/menu.h View File

@@ -319,7 +319,33 @@ class MenuItem_bool : public MenuEditItemBase {
319 319
 ////////////////////////////////////////////
320 320
 
321 321
 /**
322
- * SCREEN_OR_MENU_LOOP generates init code for a screen or menu
322
+ * Marlin's native menu screens work by running a loop from the top visible line index
323
+ * to the bottom visible line index (according to how much the screen has been scrolled).
324
+ * This complete loop is done on every menu screen call.
325
+ *
326
+ * The menu system is highly dynamic, so it doesn't know ahead of any menu loop which
327
+ * items will be visible or hidden, so menu items don't have a fixed index number.
328
+ *
329
+ * During the loop, each menu item checks to see if its line is the current one. If it is,
330
+ * then it checks to see if a click has arrived so it can run its action. If the action
331
+ * doesn't redirect to another screen then the menu item calls its draw method.
332
+ *
333
+ * Menu item add-ons can do whatever they like.
334
+ *
335
+ * This mixture of drawing and processing inside a loop has the advantage that a single
336
+ * line can be used to represent a menu item, and that is the rationale for this design.
337
+ *
338
+ * One of the pitfalls of this method is that DOGM displays call the screen handler 2x,
339
+ * 4x, or 8x per screen update to draw just one segment of the screen. As a result, any
340
+ * menu item that exists in two screen segments is drawn and processed twice per screen
341
+ * update. With each item processed 5, 10, 20, or 40 times the logic has to be simple.
342
+ *
343
+ * To keep performance optimal, use the MENU_ITEM_IF/ELSE/ELIF macros. If function calls
344
+ * are needed to test conditions, they should come before START_MENU / START_SCREEN.
345
+ */
346
+
347
+/**
348
+ * SCREEN_OR_MENU_LOOP generates header code for a screen or menu
323 349
  *
324 350
  *   encoderTopLine is the top menu line to display
325 351
  *   _lcdLineNr is the index of the LCD line (e.g., 0-3)
@@ -510,6 +536,17 @@ class MenuItem_bool : public MenuEditItemBase {
510 536
 #define YESNO_ITEM_N_P(N,PLABEL, V...)      _CONFIRM_ITEM_N_P(N, PLABEL, ##V)
511 537
 #define YESNO_ITEM_N(N,LABEL, V...)            YESNO_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
512 538
 
539
+/**
540
+ * MENU_ITEM_IF/ELSE/ELIF
541
+ *
542
+ * Apply a condition for a menu item to exist.
543
+ * When the condition passes, NEXT_ITEM updates _thisItemNr.
544
+ * This cannot be used to wrap multiple menu items.
545
+ */
546
+#define MENU_ITEM_IF(COND)        if ((_menuLineNr == _thisItemNr) && (COND))
547
+#define MENU_ITEM_ELIF(COND) else if ((_menuLineNr == _thisItemNr) && (COND))
548
+#define MENU_ITEM_ELSE       else if  (_menuLineNr == _thisItemNr)
549
+
513 550
 ////////////////////////////////////////////
514 551
 /////////////// Menu Screens ///////////////
515 552
 ////////////////////////////////////////////

+ 44
- 37
Marlin/src/lcd/menu/menu_advanced.cpp View File

@@ -45,7 +45,6 @@
45 45
 
46 46
 #if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
47 47
   #include "../../feature/runout.h"
48
-  float lcd_runout_distance_mm;
49 48
 #endif
50 49
 
51 50
 #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)
@@ -148,9 +147,12 @@ void menu_cancelobject();
148 147
     #endif
149 148
 
150 149
     #if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
151
-      EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &lcd_runout_distance_mm, 1, 30, []{
152
-        runout.set_runout_distance(lcd_runout_distance_mm);
153
-      });
150
+      MENU_ITEM_IF(1) {
151
+        editable.decimal = runout.runout_distance();
152
+        EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
153
+          []{ runout.set_runout_distance(editable.decimal); }, true
154
+        );
155
+      }
154 156
     #endif
155 157
 
156 158
     END_MENU();
@@ -327,9 +329,6 @@ void menu_cancelobject();
327 329
 
328 330
   // M203 / M205 Velocity options
329 331
   void menu_advanced_velocity() {
330
-    START_MENU();
331
-    BACK_ITEM(MSG_ADVANCED_SETTINGS);
332
-
333 332
     // M203 Max Feedrate
334 333
     constexpr xyze_feedrate_t max_fr_edit =
335 334
       #ifdef MAX_FEEDRATE_EDIT_VALUES
@@ -345,6 +344,10 @@ void menu_cancelobject();
345 344
     #else
346 345
       const xyze_feedrate_t &max_fr_edit_scaled = max_fr_edit;
347 346
     #endif
347
+
348
+    START_MENU();
349
+    BACK_ITEM(MSG_ADVANCED_SETTINGS);
350
+
348 351
     #define EDIT_VMAX(N) EDIT_ITEM_FAST(float3, MSG_VMAX_##N, &planner.settings.max_feedrate_mm_s[_AXIS(N)], 1, max_fr_edit_scaled[_AXIS(N)])
349 352
     EDIT_VMAX(A);
350 353
     EDIT_VMAX(B);
@@ -369,18 +372,7 @@ void menu_cancelobject();
369 372
 
370 373
   // M201 / M204 Accelerations
371 374
   void menu_advanced_acceleration() {
372
-    START_MENU();
373
-    BACK_ITEM(MSG_ADVANCED_SETTINGS);
374
-
375 375
     const float max_accel = _MAX(planner.settings.max_acceleration_mm_per_s2[A_AXIS], planner.settings.max_acceleration_mm_per_s2[B_AXIS], planner.settings.max_acceleration_mm_per_s2[C_AXIS]);
376
-    // M204 P Acceleration
377
-    EDIT_ITEM_FAST(float5_25, MSG_ACC, &planner.settings.acceleration, 25, max_accel);
378
-
379
-    // M204 R Retract Acceleration
380
-    EDIT_ITEM_FAST(float5, MSG_A_RETRACT, &planner.settings.retract_acceleration, 100, planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)]);
381
-
382
-    // M204 T Travel Acceleration
383
-    EDIT_ITEM_FAST(float5_25, MSG_A_TRAVEL, &planner.settings.travel_acceleration, 25, max_accel);
384 376
 
385 377
     // M201 settings
386 378
     constexpr xyze_ulong_t max_accel_edit =
@@ -398,6 +390,18 @@ void menu_cancelobject();
398 390
       const xyze_ulong_t &max_accel_edit_scaled = max_accel_edit;
399 391
     #endif
400 392
 
393
+    START_MENU();
394
+    BACK_ITEM(MSG_ADVANCED_SETTINGS);
395
+
396
+    // M204 P Acceleration
397
+    EDIT_ITEM_FAST(float5_25, MSG_ACC, &planner.settings.acceleration, 25, max_accel);
398
+
399
+    // M204 R Retract Acceleration
400
+    EDIT_ITEM_FAST(float5, MSG_A_RETRACT, &planner.settings.retract_acceleration, 100, planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(active_extruder)]);
401
+
402
+    // M204 T Travel Acceleration
403
+    EDIT_ITEM_FAST(float5_25, MSG_A_TRAVEL, &planner.settings.travel_acceleration, 25, max_accel);
404
+
401 405
     #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(); })
402 406
     EDIT_AMAX(A, 100);
403 407
     EDIT_AMAX(B, 100);
@@ -413,8 +417,10 @@ void menu_cancelobject();
413 417
 
414 418
     #ifdef XY_FREQUENCY_LIMIT
415 419
       EDIT_ITEM(int8, MSG_XY_FREQUENCY_LIMIT, &planner.xy_freq_limit_hz, 0, 100, planner.refresh_frequency_limit, true);
416
-      editable.uint8 = uint8_t(LROUND(planner.xy_freq_min_speed_factor * 255 * 100)); // percent to u8
417
-      EDIT_ITEM(percent, MSG_XY_FREQUENCY_FEEDRATE, &editable.uint8, 3, 255, []{ planner.set_min_speed_factor_u8(editable.uint8); }, true);
420
+      MENU_ITEM_IF(1) {
421
+        editable.uint8 = uint8_t(LROUND(planner.xy_freq_min_speed_factor * 255 * 100)); // percent to u8
422
+        EDIT_ITEM(percent, MSG_XY_FREQUENCY_FEEDRATE, &editable.uint8, 3, 255, []{ planner.set_min_speed_factor_u8(editable.uint8); }, true);
423
+      }
418 424
     #endif
419 425
 
420 426
     END_MENU();
@@ -496,9 +502,8 @@ void menu_advanced_steps_per_mm() {
496 502
 }
497 503
 
498 504
 void menu_advanced_settings() {
499
-  #if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
500
-    lcd_runout_distance_mm = runout.runout_distance();
501
-  #endif
505
+  const bool is_busy = printer_busy();
506
+
502 507
   START_MENU();
503 508
   BACK_ITEM(MSG_CONFIGURATION);
504 509
 
@@ -522,13 +527,13 @@ void menu_advanced_settings() {
522 527
 
523 528
     // M851 - Z Probe Offsets
524 529
     #if HAS_BED_PROBE
525
-      if (!printer_busy())
526
-        SUBMENU(MSG_ZPROBE_OFFSETS, menu_probe_offsets);
530
+      if (!is_busy) SUBMENU(MSG_ZPROBE_OFFSETS, menu_probe_offsets);
527 531
     #endif
532
+
528 533
   #endif // !SLIM_LCD_MENUS
529 534
 
530 535
   // M92 - Steps Per mm
531
-  if (!printer_busy())
536
+  if (!is_busy)
532 537
     SUBMENU(MSG_STEPS_PER_MM, menu_advanced_steps_per_mm);
533 538
 
534 539
   #if ENABLED(BACKLASH_GCODE)
@@ -571,17 +576,19 @@ void menu_advanced_settings() {
571 576
   #endif
572 577
 
573 578
   #if ENABLED(SD_FIRMWARE_UPDATE)
574
-    bool sd_update_state = settings.sd_update_status();
575
-    EDIT_ITEM(bool, MSG_MEDIA_UPDATE, &sd_update_state, []{
576
-      //
577
-      // Toggle the SD Firmware Update state in EEPROM
578
-      //
579
-      const bool new_state = !settings.sd_update_status(),
580
-                 didset = settings.set_sd_update_status(new_state);
581
-      TERN_(HAS_BUZZER, ui.completion_feedback(didset));
582
-      ui.return_to_status();
583
-      if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
584
-    });
579
+    MENU_ITEM_IF (1) {
580
+      bool sd_update_state = settings.sd_update_status();
581
+      EDIT_ITEM(bool, MSG_MEDIA_UPDATE, &sd_update_state, []{
582
+        //
583
+        // Toggle the SD Firmware Update state in EEPROM
584
+        //
585
+        const bool new_state = !settings.sd_update_status(),
586
+                   didset = settings.set_sd_update_status(new_state);
587
+        ui.completion_feedback(didset);
588
+        ui.return_to_status();
589
+        if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
590
+      });
591
+    }
585 592
   #endif
586 593
 
587 594
   #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)

+ 8
- 13
Marlin/src/lcd/menu/menu_bed_corners.cpp View File

@@ -79,19 +79,14 @@ static inline void _lcd_level_bed_corners_homing() {
79 79
     bed_corner = 0;
80 80
     ui.goto_screen([]{
81 81
       MenuItem_confirm::select_screen(
82
-        GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE),
83
-        _lcd_goto_next_corner,
84
-        []{
85
-          TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
86
-          ui.goto_previous_screen_no_defer();
87
-        },
88
-        GET_TEXT(
89
-          #if ENABLED(LEVEL_CENTER_TOO)
90
-            MSG_LEVEL_BED_NEXT_POINT
91
-          #else
92
-            MSG_NEXT_CORNER
93
-          #endif
94
-        ), (PGM_P)nullptr, PSTR("?")
82
+          GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE)
83
+        , _lcd_goto_next_corner
84
+        , []{
85
+            TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
86
+            ui.goto_previous_screen_no_defer();
87
+          }
88
+        , GET_TEXT(TERN(LEVEL_CENTER_TOO, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER))
89
+        , (PGM_P)nullptr, PSTR("?")
95 90
       );
96 91
     });
97 92
     ui.set_selection(true);

+ 10
- 8
Marlin/src/lcd/menu/menu_bed_leveling.cpp View File

@@ -224,11 +224,12 @@
224 224
  *    Save Settings       (Req: EEPROM_SETTINGS)
225 225
  */
226 226
 void menu_bed_leveling() {
227
+  const bool is_homed = all_axes_known(),
228
+             is_valid = leveling_is_valid();
229
+
227 230
   START_MENU();
228 231
   BACK_ITEM(MSG_MOTION);
229 232
 
230
-  const bool is_homed = all_axes_known();
231
-
232 233
   // Auto Home if not using manual probing
233 234
   #if NONE(PROBE_MANUALLY, MESH_BED_LEVELING)
234 235
     if (!is_homed) GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
@@ -244,21 +245,22 @@ void menu_bed_leveling() {
244 245
   #endif
245 246
 
246 247
   #if ENABLED(MESH_EDIT_MENU)
247
-    if (leveling_is_valid())
248
-      SUBMENU(MSG_EDIT_MESH, menu_edit_mesh);
248
+    if (is_valid) SUBMENU(MSG_EDIT_MESH, menu_edit_mesh);
249 249
   #endif
250 250
 
251 251
   // Homed and leveling is valid? Then leveling can be toggled.
252
-  if (is_homed && leveling_is_valid()) {
252
+  if (is_homed && is_valid) {
253 253
     bool show_state = planner.leveling_active;
254 254
     EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
255 255
   }
256 256
 
257 257
   // Z Fade Height
258 258
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
259
-    // Shadow for editing the fade height
260
-    editable.decimal = planner.z_fade_height;
261
-    EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
259
+    MENU_ITEM_IF (1) {
260
+      // Shadow for editing the fade height
261
+      editable.decimal = planner.z_fade_height;
262
+      EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
263
+    }
262 264
   #endif
263 265
 
264 266
   //

+ 8
- 6
Marlin/src/lcd/menu/menu_cancelobject.cpp View File

@@ -53,17 +53,19 @@ static void lcd_cancel_object_confirm() {
53 53
 }
54 54
 
55 55
 void menu_cancelobject() {
56
+  const int8_t ao = cancelable.active_object;
57
+
56 58
   START_MENU();
57 59
   BACK_ITEM(MSG_MAIN);
58 60
 
59 61
   // Draw cancelable items in a loop
60
-  int8_t a = cancelable.active_object;
61 62
   for (int8_t i = -1; i < cancelable.object_count; i++) {
62
-    if (i == a) continue;
63
-    int8_t j = i < 0 ? a : i;
64
-    if (!cancelable.is_canceled(j))
65
-      SUBMENU_N(j, MSG_CANCEL_OBJECT_N, lcd_cancel_object_confirm);
66
-    if (i < 0) SKIP_ITEM();
63
+    if (i == ao) continue;                                          // Active is drawn on -1 index
64
+    const int8_t j = i < 0 ? ao : i;                                // Active or index item
65
+    MENU_ITEM_IF (!cancelable.is_canceled(j)) {                     // Not canceled already?
66
+      SUBMENU_N(j, MSG_CANCEL_OBJECT_N, lcd_cancel_object_confirm); // Offer the option.
67
+      if (i < 0) SKIP_ITEM();                                       // Extra line after active
68
+    }
67 69
   }
68 70
 
69 71
   END_MENU();

+ 10
- 6
Marlin/src/lcd/menu/menu_configuration.cpp View File

@@ -126,6 +126,8 @@ void menu_advanced_settings();
126 126
     #include "../../module/motion.h" // for active_extruder
127 127
 
128 128
     void menu_toolchange_migration() {
129
+      PGM_P const msg_migrate = GET_TEXT(MSG_TOOL_MIGRATION_SWAP);
130
+
129 131
       START_MENU();
130 132
       BACK_ITEM(MSG_CONFIGURATION);
131 133
 
@@ -134,7 +136,6 @@ void menu_advanced_settings();
134 136
       EDIT_ITEM(uint8, MSG_TOOL_MIGRATION_END, &migration.last, 0, EXTRUDERS - 1);
135 137
 
136 138
       // Migrate to a chosen extruder
137
-      PGM_P const msg_migrate = GET_TEXT(MSG_TOOL_MIGRATION_SWAP);
138 139
       LOOP_L_N(s, EXTRUDERS) {
139 140
         if (s != active_extruder) {
140 141
           ACTION_ITEM_N_P(s, msg_migrate, []{
@@ -182,11 +183,12 @@ void menu_advanced_settings();
182 183
 #if ENABLED(DUAL_X_CARRIAGE)
183 184
 
184 185
   void menu_idex() {
186
+    const bool need_g28 = !(TEST(axis_known_position, Y_AXIS) && TEST(axis_known_position, Z_AXIS));
187
+
185 188
     START_MENU();
186 189
     BACK_ITEM(MSG_CONFIGURATION);
187 190
 
188 191
     GCODES_ITEM(MSG_IDEX_MODE_AUTOPARK,  PSTR("M605 S1\nG28 X\nG1 X100"));
189
-    const bool need_g28 = !(TEST(axis_known_position, Y_AXIS) && TEST(axis_known_position, Z_AXIS));
190 192
     GCODES_ITEM(MSG_IDEX_MODE_DUPLICATE, need_g28
191 193
       ? PSTR("M605 S1\nT0\nG28\nM605 S2 X200\nG28 X\nG1 X100")                // If Y or Z is not homed, do a full G28 first
192 194
       : PSTR("M605 S1\nT0\nM605 S2 X200\nG28 X\nG1 X100")
@@ -237,9 +239,10 @@ void menu_advanced_settings();
237 239
 #endif
238 240
 
239 241
 #if ENABLED(TOUCH_MI_PROBE)
242
+
240 243
   void menu_touchmi() {
241
-    START_MENU();
242 244
     ui.defer_status_screen();
245
+    START_MENU();
243 246
     BACK_ITEM(MSG_CONFIGURATION);
244 247
     GCODES_ITEM(MSG_TOUCHMI_INIT, PSTR("M851 Z0\nG28\nG1 F200 Z0"));
245 248
     SUBMENU(MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
@@ -247,6 +250,7 @@ void menu_advanced_settings();
247 250
     GCODES_ITEM(MSG_TOUCHMI_ZTEST, PSTR("G28\nG1 F200 Z0"));
248 251
     END_MENU();
249 252
   }
253
+
250 254
 #endif
251 255
 
252 256
 #if ENABLED(CONTROLLER_FAN_MENU)
@@ -342,6 +346,8 @@ void menu_advanced_settings();
342 346
 #endif
343 347
 
344 348
 void menu_configuration() {
349
+  const bool busy = printer_busy();
350
+
345 351
   START_MENU();
346 352
   BACK_ITEM(MSG_MAIN);
347 353
 
@@ -367,7 +373,6 @@ void menu_configuration() {
367 373
     SUBMENU(MSG_CONTROLLER_FAN, menu_controller_fan);
368 374
   #endif
369 375
 
370
-  const bool busy = printer_busy();
371 376
   if (!busy) {
372 377
     #if EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION)
373 378
       SUBMENU(MSG_DELTA_CALIBRATE, menu_delta_calibrate);
@@ -435,8 +440,7 @@ void menu_configuration() {
435 440
 
436 441
   #if ENABLED(EEPROM_SETTINGS)
437 442
     ACTION_ITEM(MSG_STORE_EEPROM, lcd_store_settings);
438
-    if (!busy)
439
-      ACTION_ITEM(MSG_LOAD_EEPROM, lcd_load_settings);
443
+    if (!busy) ACTION_ITEM(MSG_LOAD_EEPROM, lcd_load_settings);
440 444
   #endif
441 445
 
442 446
   if (!busy)

+ 3
- 1
Marlin/src/lcd/menu/menu_delta_calibrate.cpp View File

@@ -118,6 +118,8 @@ void lcd_delta_settings() {
118 118
 }
119 119
 
120 120
 void menu_delta_calibrate() {
121
+  const bool all_homed = all_axes_homed();
122
+
121 123
   START_MENU();
122 124
   BACK_ITEM(MSG_MAIN);
123 125
 
@@ -133,7 +135,7 @@ void menu_delta_calibrate() {
133 135
 
134 136
   #if ENABLED(DELTA_CALIBRATION_MENU)
135 137
     SUBMENU(MSG_AUTO_HOME, _lcd_delta_calibrate_home);
136
-    if (all_axes_homed()) {
138
+    if (all_homed) {
137 139
       SUBMENU(MSG_DELTA_CALIBRATE_X, _goto_tower_x);
138 140
       SUBMENU(MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
139 141
       SUBMENU(MSG_DELTA_CALIBRATE_Z, _goto_tower_z);

+ 42
- 35
Marlin/src/lcd/menu/menu_filament.cpp View File

@@ -95,26 +95,37 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
95 95
  *
96 96
  */
97 97
 #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
98
-  void menu_change_filament() {
99
-    START_MENU();
100
-    BACK_ITEM(MSG_MAIN);
101 98
 
99
+  void menu_change_filament() {
102 100
     // Say "filament change" when no print is active
103 101
     editable.int8 = printingIsPaused() ? PAUSE_MODE_PAUSE_PRINT : PAUSE_MODE_CHANGE_FILAMENT;
104 102
 
103
+    #if E_STEPPERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
104
+      bool too_cold = false;
105
+      for (uint8_t s = 0; !too_cold && s < E_STEPPERS; s++)
106
+        too_cold = thermalManager.targetTooColdToExtrude(s);
107
+    #endif
108
+
109
+    #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
110
+      const bool is_busy = printer_busy();
111
+    #endif
112
+
113
+    START_MENU();
114
+    BACK_ITEM(MSG_MAIN);
115
+
105 116
     // Change filament
106 117
     #if E_STEPPERS == 1
107 118
       PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE);
108
-      if (thermalManager.targetTooColdToExtrude(active_extruder))
119
+      MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
109 120
         SUBMENU_P(msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
110
-      else
121
+      MENU_ITEM_ELSE
111 122
         GCODES_ITEM_P(msg, PSTR("M600 B0"));
112 123
     #else
113 124
       PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
114 125
       LOOP_L_N(s, E_STEPPERS) {
115
-        if (thermalManager.targetTooColdToExtrude(s))
126
+        MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
116 127
           SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
117
-        else {
128
+        MENU_ITEM_ELSE {
118 129
           ACTION_ITEM_N_P(s, msg, []{
119 130
             char cmd[13];
120 131
             sprintf_P(cmd, PSTR("M600 B0 T%i"), int(MenuItemBase::itemIndex));
@@ -125,20 +136,20 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
125 136
     #endif
126 137
 
127 138
     #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
128
-      if (!printer_busy()) {
139
+      if (!is_busy) {
129 140
         // Load filament
130 141
         #if E_STEPPERS == 1
131 142
           PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD);
132
-          if (thermalManager.targetTooColdToExtrude(active_extruder))
143
+          MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
133 144
             SUBMENU_P(msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, 0); });
134
-          else
145
+          MENU_ITEM_ELSE
135 146
             GCODES_ITEM_P(msg_load, PSTR("M701"));
136 147
         #else
137 148
           PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
138 149
           LOOP_L_N(s, E_STEPPERS) {
139
-            if (thermalManager.targetTooColdToExtrude(s))
150
+            MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
140 151
               SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
141
-            else {
152
+            MENU_ITEM_ELSE {
142 153
               ACTION_ITEM_N_P(s, msg_load, []{
143 154
                 char cmd[12];
144 155
                 sprintf_P(cmd, PSTR("M701 T%i"), int(MenuItemBase::itemIndex));
@@ -151,30 +162,22 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
151 162
         // Unload filament
152 163
         #if E_STEPPERS == 1
153 164
           PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD);
154
-          if (thermalManager.targetTooColdToExtrude(active_extruder))
165
+          MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
155 166
             SUBMENU_P(msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, 0); });
156
-          else
167
+          MENU_ITEM_ELSE
157 168
             GCODES_ITEM_P(msg_unload, PSTR("M702"));
158 169
         #else
159 170
           #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
160
-          {
161
-            bool too_cold = false;
162
-            LOOP_L_N(s, E_STEPPERS) {
163
-              if (thermalManager.targetTooColdToExtrude(s)) {
164
-                too_cold = true; break;
165
-              }
166
-            }
167
-            if (!too_cold)
168
-              GCODES_ITEM(MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
169
-            else
171
+            MENU_ITEM_IF (too_cold)
170 172
               SUBMENU(MSG_FILAMENTUNLOAD_ALL, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, -1); });
171
-          }
173
+            MENU_ITEM_ELSE
174
+              GCODES_ITEM(MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
172 175
           #endif
173 176
           PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
174 177
           LOOP_L_N(s, E_STEPPERS) {
175
-            if (thermalManager.targetTooColdToExtrude(s))
178
+            MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
176 179
               SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
177
-            else {
180
+            MENU_ITEM_ELSE {
178 181
               ACTION_ITEM_N_P(s, msg_unload, []{
179 182
                 char cmd[12];
180 183
                 sprintf_P(cmd, PSTR("M702 T%i"), int(MenuItemBase::itemIndex));
@@ -194,12 +197,9 @@ static uint8_t hotend_status_extruder = 0;
194 197
 
195 198
 static PGM_P pause_header() {
196 199
   switch (pause_mode) {
197
-    case PAUSE_MODE_CHANGE_FILAMENT:
198
-      return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER);
199
-    case PAUSE_MODE_LOAD_FILAMENT:
200
-      return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_LOAD);
201
-    case PAUSE_MODE_UNLOAD_FILAMENT:
202
-      return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_UNLOAD);
200
+    case PAUSE_MODE_CHANGE_FILAMENT:  return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER);
201
+    case PAUSE_MODE_LOAD_FILAMENT:    return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_LOAD);
202
+    case PAUSE_MODE_UNLOAD_FILAMENT:  return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_UNLOAD);
203 203
     default: break;
204 204
   }
205 205
   return GET_TEXT(MSG_FILAMENT_CHANGE_HEADER_PAUSE);
@@ -227,11 +227,18 @@ void menu_pause_option() {
227 227
     STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER);
228 228
   #endif
229 229
   ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_PURGE, []{ pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; });
230
+
230 231
   #if HAS_FILAMENT_SENSOR
231
-    if (runout.filament_ran_out)
232
+    const bool still_out = runout.filament_ran_out;
233
+    MENU_ITEM_IF (still_out)
232 234
       EDIT_ITEM(bool, MSG_RUNOUT_SENSOR, &runout.enabled, runout.reset);
235
+  #else
236
+    constexpr bool still_out = false;
233 237
   #endif
234
-      ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_RESUME, []{ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; });
238
+
239
+  MENU_ITEM_IF (!still_out)
240
+    ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_RESUME, []{ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; });
241
+
235 242
   END_MENU();
236 243
 }
237 244
 

+ 26
- 33
Marlin/src/lcd/menu/menu_info.cpp View File

@@ -34,8 +34,8 @@
34 34
   #include "game/game.h"
35 35
 #endif
36 36
 
37
-#define VALUE_ITEM(MSG, VALUE, STYL)    do{ char buffer[21]; strcpy_P(buffer, PSTR(": ")); strcpy(buffer + 2, VALUE); STATIC_ITEM(MSG, STYL, buffer); }while(0)
38
-#define VALUE_ITEM_P(MSG, PVALUE, STYL) do{ char buffer[21]; strcpy_P(buffer, PSTR(": ")); strcpy_P(buffer + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, STYL, buffer); }while(0)
37
+#define VALUE_ITEM(MSG, VALUE, STYL)    do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy(msg + 2, VALUE); STATIC_ITEM(MSG, STYL, msg); }while(0)
38
+#define VALUE_ITEM_P(MSG, PVALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy_P(msg + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, STYL, msg); }while(0)
39 39
 
40 40
 #if ENABLED(PRINTCOUNTER)
41 41
 
@@ -47,8 +47,6 @@
47 47
   void menu_info_stats() {
48 48
     if (ui.use_click()) return ui.go_back();
49 49
 
50
-    char buffer[21];  // For macro usage
51
-
52 50
     printStatistics stats = print_job_timer.getStats();
53 51
 
54 52
     char buffer[21];
@@ -245,17 +243,13 @@ void menu_info_board() {
245 243
     STATIC_ITEM_P(PSTR(MACHINE_NAME));                          // My3DPrinter
246 244
     STATIC_ITEM_P(PSTR(WEBSITE_URL));                           // www.my3dprinter.com
247 245
     VALUE_ITEM_P(MSG_INFO_EXTRUDERS, STRINGIFY(EXTRUDERS), SS_CENTER); // Extruders: 2
248
-    #if ENABLED(AUTO_BED_LEVELING_3POINT)
249
-      STATIC_ITEM(MSG_3POINT_LEVELING);                         // 3-Point Leveling
250
-    #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
251
-      STATIC_ITEM(MSG_LINEAR_LEVELING);                         // Linear Leveling
252
-    #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
253
-      STATIC_ITEM(MSG_BILINEAR_LEVELING);                       // Bi-linear Leveling
254
-    #elif ENABLED(AUTO_BED_LEVELING_UBL)
255
-      STATIC_ITEM(MSG_UBL_LEVELING);                            // Unified Bed Leveling
256
-    #elif ENABLED(MESH_BED_LEVELING)
257
-      STATIC_ITEM(MSG_MESH_LEVELING);                           // Mesh Leveling
258
-    #endif
246
+    STATIC_ITEM(
247
+      TERN_(AUTO_BED_LEVELING_3POINT, MSG_3POINT_LEVELING)      // 3-Point Leveling
248
+      TERN_(AUTO_BED_LEVELING_LINEAR, MSG_LINEAR_LEVELING)      // Linear Leveling
249
+      TERN_(AUTO_BED_LEVELING_BILINEAR, MSG_BILINEAR_LEVELING)  // Bi-linear Leveling
250
+      TERN_(AUTO_BED_LEVELING_UBL, MSG_UBL_LEVELING)            // Unified Bed Leveling
251
+      TERN_(MESH_BED_LEVELING, MSG_MESH_LEVELING)               // Mesh Leveling
252
+    );
259 253
     END_SCREEN();
260 254
   }
261 255
 
@@ -282,27 +276,26 @@ void menu_info() {
282 276
   #endif
283 277
 
284 278
   #if HAS_GAMES
279
+  {
285 280
     #if ENABLED(GAMES_EASTER_EGG)
286
-      SKIP_ITEM();
287
-      SKIP_ITEM();
288
-      SKIP_ITEM();
281
+      SKIP_ITEM(); SKIP_ITEM(); SKIP_ITEM();
289 282
     #endif
283
+
290 284
     // Game sub-menu or the individual game
291
-    {
292
-      SUBMENU(
293
-        #if HAS_GAME_MENU
294
-          MSG_GAMES, menu_game
295
-        #elif ENABLED(MARLIN_BRICKOUT)
296
-          MSG_BRICKOUT, brickout.enter_game
297
-        #elif ENABLED(MARLIN_INVADERS)
298
-          MSG_INVADERS, invaders.enter_game
299
-        #elif ENABLED(MARLIN_SNAKE)
300
-          MSG_SNAKE, snake.enter_game
301
-        #elif ENABLED(MARLIN_MAZE)
302
-          MSG_MAZE, maze.enter_game
303
-        #endif
304
-      );
305
-    }
285
+    SUBMENU(
286
+      #if HAS_GAME_MENU
287
+        MSG_GAMES, menu_game
288
+      #elif ENABLED(MARLIN_BRICKOUT)
289
+        MSG_BRICKOUT, brickout.enter_game
290
+      #elif ENABLED(MARLIN_INVADERS)
291
+        MSG_INVADERS, invaders.enter_game
292
+      #elif ENABLED(MARLIN_SNAKE)
293
+        MSG_SNAKE, snake.enter_game
294
+      #elif ENABLED(MARLIN_MAZE)
295
+        MSG_MAZE, maze.enter_game
296
+      #endif
297
+    );
298
+  }
306 299
   #endif
307 300
 
308 301
   END_MENU();

+ 4
- 2
Marlin/src/lcd/menu/menu_led.cpp View File

@@ -70,8 +70,10 @@ void menu_led_custom() {
70 70
 void menu_led() {
71 71
   START_MENU();
72 72
   BACK_ITEM(MSG_MAIN);
73
-  bool led_on = leds.lights_on;
74
-  EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
73
+  MENU_ITEM_IF(1) {
74
+    bool led_on = leds.lights_on;
75
+    EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
76
+  }
75 77
   ACTION_ITEM(MSG_SET_LEDS_DEFAULT, leds.set_default);
76 78
   #if ENABLED(LED_COLOR_PRESETS)
77 79
     SUBMENU(MSG_LED_PRESETS, menu_led_presets);

+ 36
- 33
Marlin/src/lcd/menu/menu_main.cpp View File

@@ -84,9 +84,6 @@ void menu_configuration();
84 84
 extern const char M21_STR[];
85 85
 
86 86
 void menu_main() {
87
-  START_MENU();
88
-  BACK_ITEM(MSG_INFO_SCREEN);
89
-
90 87
   const bool busy = printingIsActive()
91 88
     #if ENABLED(SDSUPPORT)
92 89
       , card_detected = card.isMounted()
@@ -94,6 +91,9 @@ void menu_main() {
94 91
     #endif
95 92
   ;
96 93
 
94
+  START_MENU();
95
+  BACK_ITEM(MSG_INFO_SCREEN);
96
+
97 97
   if (busy) {
98 98
     #if MACHINE_CAN_PAUSE
99 99
       ACTION_ITEM(MSG_PAUSE_PRINT, ui.pause_print);
@@ -119,7 +119,7 @@ void menu_main() {
119 119
       // Autostart
120 120
       //
121 121
       #if ENABLED(MENU_ADDAUTOSTART)
122
-        if (!busy) ACTION_ITEM(MSG_AUTOSTART, card.beginautostart);
122
+        ACTION_ITEM(MSG_AUTOSTART, card.beginautostart);
123 123
       #endif
124 124
 
125 125
       if (card_detected) {
@@ -144,7 +144,7 @@ void menu_main() {
144 144
 
145 145
     #endif // !HAS_ENCODER_WHEEL && SDSUPPORT
146 146
 
147
-    if (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
147
+    MENU_ITEM_IF (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
148 148
       ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);
149 149
 
150 150
     SUBMENU(MSG_MOTION, menu_motion);
@@ -176,9 +176,9 @@ void menu_main() {
176 176
 
177 177
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
178 178
     #if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
179
-      if (thermalManager.targetHotEnoughToExtrude(active_extruder))
179
+      MENU_ITEM_IF (thermalManager.targetHotEnoughToExtrude(active_extruder))
180 180
         GCODES_ITEM(MSG_FILAMENTCHANGE, PSTR("M600 B0"));
181
-      else
181
+      MENU_ITEM_ELSE
182 182
         SUBMENU(MSG_FILAMENTCHANGE, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
183 183
     #else
184 184
       SUBMENU(MSG_FILAMENTCHANGE, menu_change_filament);
@@ -197,41 +197,44 @@ void menu_main() {
197 197
   // Switch power on/off
198 198
   //
199 199
   #if ENABLED(PSU_CONTROL)
200
-    if (powersupply_on)
200
+    MENU_ITEM_IF (powersupply_on)
201 201
       GCODES_ITEM(MSG_SWITCH_PS_OFF, PSTR("M81"));
202
-    else
202
+    MENU_ITEM_ELSE
203 203
       GCODES_ITEM(MSG_SWITCH_PS_ON, PSTR("M80"));
204 204
   #endif
205 205
 
206 206
   #if BOTH(HAS_ENCODER_WHEEL, SDSUPPORT)
207 207
 
208
-    // *** IF THIS SECTION IS CHANGED, REPRODUCE ABOVE ***
208
+    if (!busy) {
209 209
 
210
-    //
211
-    // Autostart
212
-    //
213
-    #if ENABLED(MENU_ADDAUTOSTART)
214
-      if (!busy) ACTION_ITEM(MSG_AUTOSTART, card.beginautostart);
215
-    #endif
210
+      // *** IF THIS SECTION IS CHANGED, REPRODUCE ABOVE ***
216 211
 
217
-    if (card_detected) {
218
-      if (!card_open) {
219
-        MENU_ITEM(gcode,
220
-          #if PIN_EXISTS(SD_DETECT)
221
-            MSG_CHANGE_MEDIA, M21_STR
222
-          #else
223
-            MSG_RELEASE_MEDIA, PSTR("M22")
224
-          #endif
225
-        );
226
-        SUBMENU(MSG_MEDIA_MENU, menu_media);
227
-      }
228
-    }
229
-    else {
230
-      #if PIN_EXISTS(SD_DETECT)
231
-        ACTION_ITEM(MSG_NO_MEDIA, nullptr);
232
-      #else
233
-        GCODES_ITEM(MSG_ATTACH_MEDIA, M21_STR);
212
+      //
213
+      // Autostart
214
+      //
215
+      #if ENABLED(MENU_ADDAUTOSTART)
216
+        ACTION_ITEM(MSG_AUTOSTART, card.beginautostart);
234 217
       #endif
218
+
219
+      if (card_detected) {
220
+        if (!card_open) {
221
+          MENU_ITEM(gcode,
222
+            #if PIN_EXISTS(SD_DETECT)
223
+              MSG_CHANGE_MEDIA, M21_STR
224
+            #else
225
+              MSG_RELEASE_MEDIA, PSTR("M22")
226
+            #endif
227
+          );
228
+          SUBMENU(MSG_MEDIA_MENU, menu_media);
229
+        }
230
+      }
231
+      else {
232
+        #if PIN_EXISTS(SD_DETECT)
233
+          ACTION_ITEM(MSG_NO_MEDIA, nullptr);
234
+        #else
235
+          GCODES_ITEM(MSG_ATTACH_MEDIA, M21_STR);
236
+        #endif
237
+      }
235 238
     }
236 239
 
237 240
   #endif // HAS_ENCODER_WHEEL && SDSUPPORT

+ 4
- 19
Marlin/src/lcd/menu/menu_media.cpp View File

@@ -45,25 +45,11 @@ void lcd_sd_updir() {
45 45
 
46 46
   void MarlinUI::reselect_last_file() {
47 47
     if (sd_encoder_position == 0xFFFF) return;
48
-    //#if HAS_GRAPHICAL_LCD
49
-    //  // This is a hack to force a screen update.
50
-    //  ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
51
-    //  ui.synchronize();
52
-    //  safe_delay(50);
53
-    //  ui.synchronize();
54
-    //  ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
55
-    //  ui.drawing_screen = ui.screen_changed = true;
56
-    //#endif
57
-
58 48
     goto_screen(menu_media, sd_encoder_position, sd_top_line, sd_items);
59 49
     sd_encoder_position = 0xFFFF;
60
-
61 50
     defer_status_screen();
62
-
63
-    //#if HAS_GRAPHICAL_LCD
64
-    //  update();
65
-    //#endif
66 51
   }
52
+
67 53
 #endif
68 54
 
69 55
 inline void sdcard_start_selected_file() {
@@ -141,14 +127,13 @@ void menu_media() {
141 127
   if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
142 128
     if (_menuLineNr == _thisItemNr) {
143 129
       card.getfilename_sorted(SD_ORDER(i, fileCnt));
144
-      if (card.flag.filenameIsDir)
130
+      MENU_ITEM_IF (card.flag.filenameIsDir)
145 131
         MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
146
-      else
132
+      MENU_ITEM_ELSE
147 133
         MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
148 134
     }
149
-    else {
135
+    else
150 136
       SKIP_ITEM();
151
-    }
152 137
   }
153 138
   END_MENU();
154 139
 }

+ 29
- 30
Marlin/src/lcd/menu/menu_motion.cpp View File

@@ -193,6 +193,11 @@ void _goto_manual_move(const float scale) {
193 193
 
194 194
 void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=-1) {
195 195
   _manual_move_func_ptr = func;
196
+  #if ENABLED(PREVENT_COLD_EXTRUSION)
197
+    const bool too_cold = axis == E_AXIS && thermalManager.tooColdToExtrude(eindex >= 0 ? eindex : active_extruder);
198
+  #else
199
+    constexpr bool too_cold = false;
200
+  #endif
196 201
   START_MENU();
197 202
   if (LCD_HEIGHT >= 4) {
198 203
     switch (axis) {
@@ -205,24 +210,17 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
205 210
         break;
206 211
     }
207 212
   }
208
-  #if ENABLED(PREVENT_COLD_EXTRUSION)
209
-    if (axis == E_AXIS && thermalManager.tooColdToExtrude(eindex >= 0 ? eindex : active_extruder))
210
-      BACK_ITEM(MSG_HOTEND_TOO_COLD);
211
-    else
212
-  #endif
213
-  {
213
+  if (too_cold)
214
+    BACK_ITEM(MSG_HOTEND_TOO_COLD);
215
+  else {
214 216
     BACK_ITEM(MSG_MOVE_AXIS);
215 217
     SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10);    });
216 218
     SUBMENU(MSG_MOVE_1MM,  []{ _goto_manual_move( 1);    });
217 219
     SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
218
-    if (axis == Z_AXIS && (SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
220
+    MENU_ITEM_IF (axis == Z_AXIS && (SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
219 221
       extern const char NUL_STR[];
220 222
       SUBMENU_P(NUL_STR, []{ _goto_manual_move(float(SHORT_MANUAL_Z_MOVE)); });
221
-      MENU_ITEM_ADDON_START(0
222
-        #if HAS_CHARACTER_LCD
223
-          + 1
224
-        #endif
225
-      );
223
+      MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
226 224
         char tmp[20], numstr[10];
227 225
         // Determine digits needed right of decimal
228 226
         const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
@@ -273,23 +271,23 @@ void menu_move() {
273 271
       }
274 272
     #elif EXTRUDERS == 3
275 273
       if (active_extruder < 2) {
276
-        if (active_extruder)
274
+        MENU_ITEM_IF (active_extruder)
277 275
           GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
278
-        else
276
+        MENU_ITEM_ELSE
279 277
           GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
280 278
       }
281 279
     #else
282
-      if (active_extruder)
280
+      MENU_ITEM_IF (active_extruder)
283 281
         GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
284
-      else
282
+      MENU_ITEM_ELSE
285 283
         GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
286 284
     #endif
287 285
 
288 286
   #elif ENABLED(DUAL_X_CARRIAGE)
289 287
 
290
-    if (active_extruder)
288
+    MENU_ITEM_IF (active_extruder)
291 289
       GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
292
-    else
290
+    MENU_ITEM_ELSE
293 291
       GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
294 292
 
295 293
   #endif
@@ -304,10 +302,8 @@ void menu_move() {
304 302
     #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
305 303
 
306 304
       // ...and the non-switching
307
-      #if E_MANUAL == 5
308
-        SUBMENU_MOVE_E(4);
309
-      #elif E_MANUAL == 3
310
-        SUBMENU_MOVE_E(2);
305
+      #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
306
+        SUBMENU_MOVE_E(E_MANUAL - 1);
311 307
       #endif
312 308
 
313 309
     #elif MULTI_MANUAL
@@ -339,10 +335,8 @@ void menu_motion() {
339 335
   //
340 336
   // Move Axis
341 337
   //
342
-  #if ENABLED(DELTA)
343
-    if (all_axes_homed())
344
-  #endif
345
-      SUBMENU(MSG_MOVE_AXIS, menu_move);
338
+  MENU_ITEM_IF (TERN1(DELTA, all_axes_homed()))
339
+    SUBMENU(MSG_MOVE_AXIS, menu_move);
346 340
 
347 341
   //
348 342
   // Auto Home
@@ -370,20 +364,25 @@ void menu_motion() {
370 364
 
371 365
   #elif ENABLED(LCD_BED_LEVELING)
372 366
 
373
-    if (!g29_in_progress) SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
367
+    MENU_ITEM_IF (!g29_in_progress)
368
+      SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
374 369
 
375 370
   #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
376 371
 
377 372
     #if DISABLED(PROBE_MANUALLY)
378 373
       GCODES_ITEM(MSG_LEVEL_BED, PSTR("G28\nG29"));
379 374
     #endif
380
-    if (all_axes_homed() && leveling_is_valid()) {
375
+
376
+    MENU_ITEM_IF (all_axes_homed() && leveling_is_valid()) {
381 377
       bool show_state = planner.leveling_active;
382 378
       EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
383 379
     }
380
+
384 381
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
385
-      editable.decimal = planner.z_fade_height;
386
-      EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
382
+      MENU_ITEM_IF(1) {
383
+        editable.decimal = planner.z_fade_height;
384
+        EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
385
+      }
387 386
     #endif
388 387
 
389 388
   #endif

+ 8
- 7
Marlin/src/lcd/menu/menu_spindle_laser.cpp View File

@@ -34,18 +34,19 @@
34 34
 
35 35
   void menu_spindle_laser() {
36 36
 
37
+    const bool can_disable = cutter.enabled() && cutter.isOn;
38
+
37 39
     START_MENU();
38 40
     BACK_ITEM(MSG_MAIN);
41
+
39 42
     #if ENABLED(SPINDLE_LASER_PWM)
40
-      EDIT_ITEM_FAST(CUTTER_MENU_POWER_TYPE, MSG_CUTTER(POWER), &cutter.setPower, cutter.interpret_power(SPEED_POWER_MIN), cutter.interpret_power(SPEED_POWER_MAX),
41
-      []{
42
-        if (cutter.isOn) {
43
-          cutter.power = cutter.setPower;
44
-        }
45
-      });
43
+      EDIT_ITEM_FAST( CUTTER_MENU_POWER_TYPE, MSG_CUTTER(POWER), &cutter.setPower
44
+                    , cutter.interpret_power(SPEED_POWER_MIN), cutter.interpret_power(SPEED_POWER_MAX)
45
+                    , []{ if (cutter.isOn) cutter.power = cutter.setPower; }
46
+      );
46 47
     #endif
47 48
 
48
-    if (cutter.enabled() && cutter.isOn)
49
+    if (can_disable)
49 50
       ACTION_ITEM(MSG_CUTTER(OFF), cutter.disable);
50 51
     else {
51 52
       ACTION_ITEM(MSG_CUTTER(ON), cutter.enable_forward);

+ 18
- 10
Marlin/src/lcd/menu/menu_temperature.cpp View File

@@ -197,8 +197,10 @@ void menu_temperature() {
197 197
 
198 198
     #if HAS_FAN1 || HAS_FAN2 || HAS_FAN3 || HAS_FAN4 || HAS_FAN5 || HAS_FAN6 || HAS_FAN7
199 199
       auto fan_edit_items = [&](const uint8_t f) {
200
-        editable.uint8 = thermalManager.fan_speed[f];
201
-        EDIT_ITEM_FAST_N(percent, f, MSG_FAN_SPEED_N, &editable.uint8, 0, 255, on_fan_update);
200
+        MENU_ITEM_IF(1) {
201
+          editable.uint8 = thermalManager.fan_speed[f];
202
+          EDIT_ITEM_FAST_N(percent, f, MSG_FAN_SPEED_N, &editable.uint8, 0, 255, on_fan_update);
203
+        }
202 204
         #if ENABLED(EXTRA_FAN_SPEED)
203 205
           EDIT_ITEM_FAST_N(percent, f, MSG_EXTRA_FAN_SPEED_N, &thermalManager.new_fan_speed[f], 3, 255);
204 206
         #endif
@@ -208,14 +210,18 @@ void menu_temperature() {
208 210
     #define SNFAN(N) (ENABLED(SINGLENOZZLE) && !HAS_FAN##N && EXTRUDERS > N)
209 211
     #if SNFAN(1) || SNFAN(2) || SNFAN(3) || SNFAN(4) || SNFAN(5) || SNFAN(6) || SNFAN(7)
210 212
       auto singlenozzle_item = [&](const uint8_t f) {
211
-        editable.uint8 = thermalManager.fan_speed[f];
212
-        EDIT_ITEM_FAST_N(percent, f, MSG_STORED_FAN_N, &editable.uint8, 0, 255, on_fan_update);
213
+        MENU_ITEM_IF(1) {
214
+          editable.uint8 = thermalManager.fan_speed[f];
215
+          EDIT_ITEM_FAST_N(percent, f, MSG_STORED_FAN_N, &editable.uint8, 0, 255, on_fan_update);
216
+        }
213 217
       };
214 218
     #endif
215 219
 
216 220
     #if HAS_FAN0
217
-      editable.uint8 = thermalManager.fan_speed[0];
218
-      EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_FAN_SPEED, &editable.uint8, 0, 255, on_fan_update);
221
+      MENU_ITEM_IF(1) {
222
+        editable.uint8 = thermalManager.fan_speed[0];
223
+        EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_FAN_SPEED, &editable.uint8, 0, 255, on_fan_update);
224
+      }
219 225
       #if ENABLED(EXTRA_FAN_SPEED)
220 226
         EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_EXTRA_FAN_SPEED, &thermalManager.new_fan_speed[0], 3, 255);
221 227
       #endif
@@ -274,10 +280,12 @@ void menu_temperature() {
274 280
     //
275 281
     // Cooldown
276 282
     //
277
-    bool has_heat = false;
278
-    HOTEND_LOOP() if (thermalManager.temp_hotend[HOTEND_INDEX].target) { has_heat = true; break; }
279
-    if (TERN0(HAS_HEATED_BED, thermalManager.temp_bed.target)) has_heat = true;
280
-    if (has_heat) ACTION_ITEM(MSG_COOLDOWN, lcd_cooldown);
283
+    MENU_ITEM_IF(1) {
284
+      bool has_heat = false;
285
+      HOTEND_LOOP() if (thermalManager.temp_hotend[HOTEND_INDEX].target) { has_heat = true; break; }
286
+      if (TERN0(HAS_HEATED_BED, thermalManager.temp_bed.target)) has_heat = true;
287
+      if (has_heat) ACTION_ITEM(MSG_COOLDOWN, lcd_cooldown);
288
+    }
281 289
 
282 290
   #endif // HAS_TEMP_HOTEND
283 291
 

+ 12
- 6
Marlin/src/lcd/menu/menu_tune.cpp View File

@@ -146,8 +146,10 @@ void menu_tune() {
146 146
 
147 147
     #if HAS_FAN1 || HAS_FAN2 || HAS_FAN3 || HAS_FAN4 || HAS_FAN5 || HAS_FAN6 || HAS_FAN7
148 148
       auto fan_edit_items = [&](const uint8_t f) {
149
-        editable.uint8 = thermalManager.fan_speed[f];
150
-        EDIT_ITEM_FAST_N(percent, f, MSG_FAN_SPEED_N, &editable.uint8, 0, 255, on_fan_update);
149
+        MENU_ITEM_IF(1) {
150
+          editable.uint8 = thermalManager.fan_speed[f];
151
+          EDIT_ITEM_FAST_N(percent, f, MSG_FAN_SPEED_N, &editable.uint8, 0, 255, on_fan_update);
152
+        }
151 153
         #if ENABLED(EXTRA_FAN_SPEED)
152 154
           EDIT_ITEM_FAST_N(percent, f, MSG_EXTRA_FAN_SPEED_N, &thermalManager.new_fan_speed[f], 3, 255);
153 155
         #endif
@@ -157,14 +159,18 @@ void menu_tune() {
157 159
     #define SNFAN(N) (ENABLED(SINGLENOZZLE) && !HAS_FAN##N && EXTRUDERS > N)
158 160
     #if SNFAN(1) || SNFAN(2) || SNFAN(3) || SNFAN(4) || SNFAN(5) || SNFAN(6) || SNFAN(7)
159 161
       auto singlenozzle_item = [&](const uint8_t f) {
160
-        editable.uint8 = thermalManager.fan_speed[f];
161
-        EDIT_ITEM_FAST_N(percent, f, MSG_STORED_FAN_N, &editable.uint8, 0, 255, on_fan_update);
162
+        MENU_ITEM_IF(1) {
163
+          editable.uint8 = thermalManager.fan_speed[f];
164
+          EDIT_ITEM_FAST_N(percent, f, MSG_STORED_FAN_N, &editable.uint8, 0, 255, on_fan_update);
165
+        }
162 166
       };
163 167
     #endif
164 168
 
165 169
     #if HAS_FAN0
166
-      editable.uint8 = thermalManager.fan_speed[0];
167
-      EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_FAN_SPEED, &editable.uint8, 0, 255, on_fan_update);
170
+      MENU_ITEM_IF(1) {
171
+        editable.uint8 = thermalManager.fan_speed[0];
172
+        EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_FAN_SPEED, &editable.uint8, 0, 255, on_fan_update);
173
+      }
168 174
       #if ENABLED(EXTRA_FAN_SPEED)
169 175
         EDIT_ITEM_FAST_N(percent, 0, MSG_FIRST_EXTRA_FAN_SPEED, &thermalManager.new_fan_speed[0], 3, 255);
170 176
       #endif

+ 3
- 4
Marlin/src/lcd/menu/menu_ubl.cpp View File

@@ -376,9 +376,8 @@ void _lcd_ubl_storage_mesh() {
376 376
   int16_t a = settings.calc_num_meshes();
377 377
   START_MENU();
378 378
   BACK_ITEM(MSG_UBL_LEVEL_BED);
379
-  if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
379
+  if (!WITHIN(ubl_storage_slot, 0, a - 1))
380 380
     STATIC_ITEM(MSG_UBL_NO_STORAGE);
381
-  }
382 381
   else {
383 382
     EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
384 383
     ACTION_ITEM(MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
@@ -580,9 +579,9 @@ void _lcd_ubl_step_by_step() {
580 579
 void _lcd_ubl_level_bed() {
581 580
   START_MENU();
582 581
   BACK_ITEM(MSG_MOTION);
583
-  if (planner.leveling_active)
582
+  MENU_ITEM_IF (planner.leveling_active)
584 583
     GCODES_ITEM(MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
585
-  else
584
+  MENU_ITEM_ELSE
586 585
     GCODES_ITEM(MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
587 586
   SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
588 587
   ACTION_ITEM(MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);

Loading…
Cancel
Save