Skip to content

Commit

Permalink
Revert menu_item_if ahead of refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 29, 2020
1 parent c26725c commit e8b0796
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 115 deletions.
15 changes: 2 additions & 13 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ class MenuItem_bool : public MenuEditItemBase {
* menu item that exists in two screen segments is drawn and processed twice per screen
* update. With each item processed 5, 10, 20, or 40 times the logic has to be simple.
*
* To keep performance optimal, use the MENU_ITEM_IF/ELSE/ELIF macros. If function calls
* are needed to test conditions, they should come before START_MENU / START_SCREEN.
* To avoid repetition and side-effects, function calls for testing menu item conditions
* should be done before the menu loop (START_MENU / START_SCREEN).
*/

/**
Expand Down Expand Up @@ -536,17 +536,6 @@ class MenuItem_bool : public MenuEditItemBase {
#define YESNO_ITEM_N_P(N,PLABEL, V...) _CONFIRM_ITEM_N_P(N, PLABEL, ##V)
#define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_P(N, GET_TEXT(LABEL), ##V)

/**
* MENU_ITEM_IF/ELSE/ELIF
*
* Apply a condition for a menu item to exist.
* When the condition passes, NEXT_ITEM updates _thisItemNr.
* This cannot be used to wrap multiple menu items.
*/
#define MENU_ITEM_IF(COND) if ((_menuLineNr == _thisItemNr) && (COND))
#define MENU_ITEM_ELIF(COND) else if ((_menuLineNr == _thisItemNr) && (COND))
#define MENU_ITEM_ELSE else if (_menuLineNr == _thisItemNr)

////////////////////////////////////////////
/////////////// Menu Screens ///////////////
////////////////////////////////////////////
Expand Down
43 changes: 20 additions & 23 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ void menu_cancelobject();
#endif

#if ENABLED(FILAMENT_RUNOUT_SENSOR) && FILAMENT_RUNOUT_DISTANCE_MM
MENU_ITEM_IF(1) {
editable.decimal = runout.runout_distance();
EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
[]{ runout.set_runout_distance(editable.decimal); }, true
);
}
editable.decimal = runout.runout_distance();
EDIT_ITEM(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 30,
[]{ runout.set_runout_distance(editable.decimal); }, true
);
#endif

END_MENU();
Expand Down Expand Up @@ -417,10 +415,8 @@ void menu_cancelobject();

#ifdef XY_FREQUENCY_LIMIT
EDIT_ITEM(int8, MSG_XY_FREQUENCY_LIMIT, &planner.xy_freq_limit_hz, 0, 100, planner.refresh_frequency_limit, true);
MENU_ITEM_IF(1) {
editable.uint8 = uint8_t(LROUND(planner.xy_freq_min_speed_factor * 255 * 100)); // percent to u8
EDIT_ITEM(percent, MSG_XY_FREQUENCY_FEEDRATE, &editable.uint8, 3, 255, []{ planner.set_min_speed_factor_u8(editable.uint8); }, true);
}
editable.uint8 = uint8_t(LROUND(planner.xy_freq_min_speed_factor * 255 * 100)); // percent to u8
EDIT_ITEM(percent, MSG_XY_FREQUENCY_FEEDRATE, &editable.uint8, 3, 255, []{ planner.set_min_speed_factor_u8(editable.uint8); }, true);
#endif

END_MENU();
Expand Down Expand Up @@ -504,6 +500,10 @@ void menu_advanced_steps_per_mm() {
void menu_advanced_settings() {
const bool is_busy = printer_busy();

#if ENABLED(SD_FIRMWARE_UPDATE)
bool sd_update_state = settings.sd_update_status();
#endif

START_MENU();
BACK_ITEM(MSG_CONFIGURATION);

Expand Down Expand Up @@ -576,19 +576,16 @@ void menu_advanced_settings() {
#endif

#if ENABLED(SD_FIRMWARE_UPDATE)
MENU_ITEM_IF (1) {
bool sd_update_state = settings.sd_update_status();
EDIT_ITEM(bool, MSG_MEDIA_UPDATE, &sd_update_state, []{
//
// Toggle the SD Firmware Update state in EEPROM
//
const bool new_state = !settings.sd_update_status(),
didset = settings.set_sd_update_status(new_state);
ui.completion_feedback(didset);
ui.return_to_status();
if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
});
}
EDIT_ITEM(bool, MSG_MEDIA_UPDATE, &sd_update_state, []{
//
// Toggle the SD Firmware Update state in EEPROM
//
const bool new_state = !settings.sd_update_status(),
didset = settings.set_sd_update_status(new_state);
ui.completion_feedback(didset);
ui.return_to_status();
if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
});
#endif

#if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)
Expand Down
8 changes: 3 additions & 5 deletions Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ void menu_bed_leveling() {

// Z Fade Height
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
MENU_ITEM_IF (1) {
// Shadow for editing the fade height
editable.decimal = planner.z_fade_height;
EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
}
// Shadow for editing the fade height
editable.decimal = planner.z_fade_height;
EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
#endif

//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_cancelobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void menu_cancelobject() {
for (int8_t i = -1; i < cancelable.object_count; i++) {
if (i == ao) continue; // Active is drawn on -1 index
const int8_t j = i < 0 ? ao : i; // Active or index item
MENU_ITEM_IF (!cancelable.is_canceled(j)) { // Not canceled already?
if (!cancelable.is_canceled(j)) { // Not canceled already?
SUBMENU_N(j, MSG_CANCEL_OBJECT_N, lcd_cancel_object_confirm); // Offer the option.
if (i < 0) SKIP_ITEM(); // Extra line after active
}
Expand Down
32 changes: 16 additions & 16 deletions Marlin/src/lcd/menu/menu_filament.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
// Change filament
#if E_STEPPERS == 1
PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE);
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
if (thermalManager.targetTooColdToExtrude(active_extruder))
SUBMENU_P(msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
MENU_ITEM_ELSE
else
GCODES_ITEM_P(msg, PSTR("M600 B0"));
#else
PGM_P const msg = GET_TEXT(MSG_FILAMENTCHANGE_E);
LOOP_L_N(s, E_STEPPERS) {
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, MenuItemBase::itemIndex); });
MENU_ITEM_ELSE {
else {
ACTION_ITEM_N_P(s, msg, []{
char cmd[13];
sprintf_P(cmd, PSTR("M600 B0 T%i"), int(MenuItemBase::itemIndex));
Expand All @@ -140,16 +140,16 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
// Load filament
#if E_STEPPERS == 1
PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD);
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
if (thermalManager.targetTooColdToExtrude(active_extruder))
SUBMENU_P(msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, 0); });
MENU_ITEM_ELSE
else
GCODES_ITEM_P(msg_load, PSTR("M701"));
#else
PGM_P const msg_load = GET_TEXT(MSG_FILAMENTLOAD_E);
LOOP_L_N(s, E_STEPPERS) {
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_load, []{ _menu_temp_filament_op(PAUSE_MODE_LOAD_FILAMENT, MenuItemBase::itemIndex); });
MENU_ITEM_ELSE {
else {
ACTION_ITEM_N_P(s, msg_load, []{
char cmd[12];
sprintf_P(cmd, PSTR("M701 T%i"), int(MenuItemBase::itemIndex));
Expand All @@ -162,22 +162,22 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) {
// Unload filament
#if E_STEPPERS == 1
PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD);
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(active_extruder))
if (thermalManager.targetTooColdToExtrude(active_extruder))
SUBMENU_P(msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, 0); });
MENU_ITEM_ELSE
else
GCODES_ITEM_P(msg_unload, PSTR("M702"));
#else
#if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
MENU_ITEM_IF (too_cold)
if (too_cold)
SUBMENU(MSG_FILAMENTUNLOAD_ALL, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, -1); });
MENU_ITEM_ELSE
else
GCODES_ITEM(MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
#endif
PGM_P const msg_unload = GET_TEXT(MSG_FILAMENTUNLOAD_E);
LOOP_L_N(s, E_STEPPERS) {
MENU_ITEM_IF (thermalManager.targetTooColdToExtrude(s))
if (thermalManager.targetTooColdToExtrude(s))
SUBMENU_N_P(s, msg_unload, []{ _menu_temp_filament_op(PAUSE_MODE_UNLOAD_FILAMENT, MenuItemBase::itemIndex); });
MENU_ITEM_ELSE {
else {
ACTION_ITEM_N_P(s, msg_unload, []{
char cmd[12];
sprintf_P(cmd, PSTR("M702 T%i"), int(MenuItemBase::itemIndex));
Expand Down Expand Up @@ -230,13 +230,13 @@ void menu_pause_option() {

#if HAS_FILAMENT_SENSOR
const bool still_out = runout.filament_ran_out;
MENU_ITEM_IF (still_out)
if (still_out)
EDIT_ITEM(bool, MSG_RUNOUT_SENSOR, &runout.enabled, runout.reset);
#else
constexpr bool still_out = false;
#endif

MENU_ITEM_IF (!still_out)
if (!still_out)
ACTION_ITEM(MSG_FILAMENT_CHANGE_OPTION_RESUME, []{ pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; });

END_MENU();
Expand Down
6 changes: 2 additions & 4 deletions Marlin/src/lcd/menu/menu_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ void menu_led_custom() {
void menu_led() {
START_MENU();
BACK_ITEM(MSG_MAIN);
MENU_ITEM_IF(1) {
bool led_on = leds.lights_on;
EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
}
bool led_on = leds.lights_on;
EDIT_ITEM(bool, MSG_LEDS, &led_on, leds.toggle);
ACTION_ITEM(MSG_SET_LEDS_DEFAULT, leds.set_default);
#if ENABLED(LED_COLOR_PRESETS)
SUBMENU(MSG_LED_PRESETS, menu_led_presets);
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void menu_main() {

#endif // !HAS_ENCODER_WHEEL && SDSUPPORT

MENU_ITEM_IF (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
if (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);

SUBMENU(MSG_MOTION, menu_motion);
Expand Down Expand Up @@ -176,9 +176,9 @@ void menu_main() {

#if ENABLED(ADVANCED_PAUSE_FEATURE)
#if E_STEPPERS == 1 && DISABLED(FILAMENT_LOAD_UNLOAD_GCODES)
MENU_ITEM_IF (thermalManager.targetHotEnoughToExtrude(active_extruder))
if (thermalManager.targetHotEnoughToExtrude(active_extruder))
GCODES_ITEM(MSG_FILAMENTCHANGE, PSTR("M600 B0"));
MENU_ITEM_ELSE
else
SUBMENU(MSG_FILAMENTCHANGE, []{ _menu_temp_filament_op(PAUSE_MODE_CHANGE_FILAMENT, 0); });
#else
SUBMENU(MSG_FILAMENTCHANGE, menu_change_filament);
Expand All @@ -197,9 +197,9 @@ void menu_main() {
// Switch power on/off
//
#if ENABLED(PSU_CONTROL)
MENU_ITEM_IF (powersupply_on)
if (powersupply_on)
GCODES_ITEM(MSG_SWITCH_PS_OFF, PSTR("M81"));
MENU_ITEM_ELSE
else
GCODES_ITEM(MSG_SWITCH_PS_ON, PSTR("M80"));
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ void menu_media() {
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
if (_menuLineNr == _thisItemNr) {
card.getfilename_sorted(SD_ORDER(i, fileCnt));
MENU_ITEM_IF (card.flag.filenameIsDir)
if (card.flag.filenameIsDir)
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
MENU_ITEM_ELSE
else
MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
}
else
Expand Down
26 changes: 12 additions & 14 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10); });
SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
MENU_ITEM_IF (axis == Z_AXIS && (SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
if (axis == Z_AXIS && (SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
extern const char NUL_STR[];
SUBMENU_P(NUL_STR, []{ _goto_manual_move(float(SHORT_MANUAL_Z_MOVE)); });
MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
Expand Down Expand Up @@ -271,23 +271,23 @@ void menu_move() {
}
#elif EXTRUDERS == 3
if (active_extruder < 2) {
MENU_ITEM_IF (active_extruder)
if (active_extruder)
GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
MENU_ITEM_ELSE
else
GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
}
#else
MENU_ITEM_IF (active_extruder)
if (active_extruder)
GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
MENU_ITEM_ELSE
else
GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
#endif

#elif ENABLED(DUAL_X_CARRIAGE)

MENU_ITEM_IF (active_extruder)
if (active_extruder)
GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
MENU_ITEM_ELSE
else
GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));

#endif
Expand Down Expand Up @@ -335,7 +335,7 @@ void menu_motion() {
//
// Move Axis
//
MENU_ITEM_IF (TERN1(DELTA, all_axes_homed()))
if (TERN1(DELTA, all_axes_homed()))
SUBMENU(MSG_MOVE_AXIS, menu_move);

//
Expand Down Expand Up @@ -364,7 +364,7 @@ void menu_motion() {

#elif ENABLED(LCD_BED_LEVELING)

MENU_ITEM_IF (!g29_in_progress)
if (!g29_in_progress)
SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);

#elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
Expand All @@ -373,16 +373,14 @@ void menu_motion() {
GCODES_ITEM(MSG_LEVEL_BED, PSTR("G28\nG29"));
#endif

MENU_ITEM_IF (all_axes_homed() && leveling_is_valid()) {
if (all_axes_homed() && leveling_is_valid()) {
bool show_state = planner.leveling_active;
EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
}

#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
MENU_ITEM_IF(1) {
editable.decimal = planner.z_fade_height;
EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
}
editable.decimal = planner.z_fade_height;
EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
#endif

#endif
Expand Down
Loading

0 comments on commit e8b0796

Please sign in to comment.