Apply TERN to compact code (#17619)

This commit is contained in:
Scott Lahteine
2020-04-22 16:35:03 -05:00
committed by GitHub
parent 88bdd26c99
commit 6d90d1e1f5
162 changed files with 1493 additions and 3530 deletions

View File

@ -53,18 +53,10 @@
// Pool game data to save SRAM
union MarlinGameData {
#if ENABLED(MARLIN_BRICKOUT)
brickout_data_t brickout;
#endif
#if ENABLED(MARLIN_INVADERS)
invaders_data_t invaders;
#endif
#if ENABLED(MARLIN_SNAKE)
snake_data_t snake;
#endif
#if ENABLED(MARLIN_MAZE)
maze_data_t maze;
#endif
TERN_(MARLIN_BRICKOUT, brickout_data_t brickout);
TERN_(MARLIN_INVADERS, invaders_data_t invaders);
TERN_(MARLIN_SNAKE, snake_data_t snake);
TERN_(MARLIN_MAZE, maze_data_t maze);
};
extern MarlinGameData marlin_game_data;

View File

@ -141,9 +141,7 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg
* MenuItem_int3::draw(encoderLine == _thisItemNr, _lcdLineNr, plabel, &feedrate_percentage, 10, 999)
*/
void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) {
#if ENABLED(TOUCH_BUTTONS)
ui.repeat_delay = BUTTON_DELAY_EDIT;
#endif
TERN_(TOUCH_BUTTONS, ui.repeat_delay = BUTTON_DELAY_EDIT);
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
if (int32_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue;
if (ui.should_draw())
@ -222,13 +220,9 @@ bool printer_busy() {
void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
if (currentScreen != screen) {
#if ENABLED(TOUCH_BUTTONS)
repeat_delay = BUTTON_DELAY_MENU;
#endif
TERN_(TOUCH_BUTTONS, repeat_delay = BUTTON_DELAY_MENU);
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
progress_reset();
#endif
TERN_(LCD_SET_PROGRESS_MANUALLY, progress_reset());
#if BOTH(DOUBLECLICK_FOR_Z_BABYSTEPPING, BABYSTEPPING)
static millis_t doubleclick_expire_ms = 0;
@ -275,9 +269,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
screen_items = items;
if (screen == status_screen) {
defer_status_screen(false);
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.lcd_map_control = false;
#endif
TERN_(AUTO_BED_LEVELING_UBL, ubl.lcd_map_control = false);
screen_history_depth = 0;
}
@ -294,13 +286,9 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
refresh(LCDVIEW_CALL_REDRAW_NEXT);
screen_changed = true;
#if HAS_GRAPHICAL_LCD
drawing_screen = false;
#endif
TERN_(HAS_GRAPHICAL_LCD, drawing_screen = false);
#if HAS_LCD_MENU
encoder_direction_normal();
#endif
TERN_(HAS_LCD_MENU, encoder_direction_normal());
set_selection(false);
}
@ -400,10 +388,10 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
babystep.add_steps(Z_AXIS, babystep_increment);
if (do_probe) probe.offset.z = new_offs;
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
else hotend_offset[active_extruder].z = new_offs;
#endif
if (do_probe)
probe.offset.z = new_offs;
else
TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP);
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
}
@ -415,9 +403,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
#endif
if (do_probe) {
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), BABYSTEP_TO_STR(probe.offset.z));
#if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
_lcd_zoffset_overlay_gfx(probe.offset.z);
#endif
TERN_(BABYSTEP_ZPROBE_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(probe.offset.z));
}
}
}
@ -427,16 +413,12 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
#if ENABLED(EEPROM_SETTINGS)
void lcd_store_settings() {
const bool saved = settings.save();
#if HAS_BUZZER
ui.completion_feedback(saved);
#endif
TERN_(HAS_BUZZER, ui.completion_feedback(saved));
UNUSED(saved);
}
void lcd_load_settings() {
const bool loaded = settings.load();
#if HAS_BUZZER
ui.completion_feedback(loaded);
#endif
TERN_(HAS_BUZZER, ui.completion_feedback(loaded));
UNUSED(loaded);
}
#endif

View File

@ -576,9 +576,7 @@ void menu_advanced_settings() {
//
const bool new_state = !settings.sd_update_status(),
didset = settings.set_sd_update_status(new_state);
#if HAS_BUZZER
ui.completion_feedback(didset);
#endif
TERN_(HAS_BUZZER, ui.completion_feedback(didset));
ui.return_to_status();
if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
});
@ -589,9 +587,7 @@ void menu_advanced_settings() {
MSG_BUTTON_INIT, MSG_BUTTON_CANCEL,
[]{
const bool inited = settings.init_eeprom();
#if HAS_BUZZER
ui.completion_feedback(inited);
#endif
TERN_(HAS_BUZZER, ui.completion_feedback(inited));
UNUSED(inited);
},
ui.goto_previous_screen,

View File

@ -70,11 +70,7 @@ static inline void _lcd_goto_next_corner() {
}
line_to_current_position(manual_feedrate_mm_s.x);
line_to_z(LEVEL_CORNERS_HEIGHT);
if (++bed_corner > (3
#if ENABLED(LEVEL_CENTER_TOO)
+ 1
#endif
)) bed_corner = 0;
if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0;
}
static inline void _lcd_level_bed_corners_homing() {
@ -86,9 +82,7 @@ static inline void _lcd_level_bed_corners_homing() {
GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE),
_lcd_goto_next_corner,
[]{
#if HAS_LEVELING
set_bed_leveling_enabled(leveling_was_active);
#endif
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
ui.goto_previous_screen_no_defer();
},
GET_TEXT(

View File

@ -75,9 +75,7 @@
ui.synchronize(GET_TEXT(MSG_LEVEL_BED_DONE));
#endif
ui.goto_previous_screen_no_defer();
#if HAS_BUZZER
ui.completion_feedback();
#endif
TERN_(HAS_BUZZER, ui.completion_feedback());
}
if (ui.should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, GET_TEXT(MSG_LEVEL_BED_DONE));
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);

View File

@ -44,9 +44,7 @@ static void lcd_cancel_object_confirm() {
MenuItem_confirm::confirm_screen(
[]{
cancelable.cancel_object(MenuItemBase::itemIndex - 1);
#if HAS_BUZZER
ui.completion_feedback();
#endif
TERN_(HAS_BUZZER, ui.completion_feedback());
ui.goto_previous_screen();
},
ui.goto_previous_screen,

View File

@ -421,9 +421,7 @@ void menu_configuration() {
if (!busy)
ACTION_ITEM(MSG_RESTORE_DEFAULTS, []{
settings.reset();
#if HAS_BUZZER
ui.completion_feedback();
#endif
TERN_(HAS_BUZZER, ui.completion_feedback());
});
END_MENU();

View File

@ -42,9 +42,7 @@ void _lcd_user_gcode(PGM_P const cmd) {
#if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK) && HAS_BUZZER
ui.completion_feedback();
#endif
#if ENABLED(USER_SCRIPT_RETURN)
ui.return_to_status();
#endif
TERN_(USER_SCRIPT_RETURN, ui.return_to_status());
}
void menu_user() {

View File

@ -62,12 +62,8 @@ void _man_probe_pt(const xy_pos_t &xy) {
float lcd_probe_pt(const xy_pos_t &xy) {
_man_probe_pt(xy);
ui.defer_status_screen();
#if ENABLED(HOST_PROMPT_SUPPORT)
host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Delta Calibration in progress"), CONTINUE_STR);
#endif
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onUserConfirmRequired_P(PSTR("Delta Calibration in progress"));
#endif
TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Delta Calibration in progress"), CONTINUE_STR));
TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Delta Calibration in progress")));
wait_for_user_response();
ui.goto_previous_screen_no_defer();
return current_position.z;
@ -102,9 +98,7 @@ void _man_probe_pt(const xy_pos_t &xy) {
void lcd_delta_settings() {
auto _recalc_delta_settings = []{
#if HAS_LEVELING
reset_bed_level(); // After changing kinematics bed-level data is no longer valid
#endif
TERN_(HAS_LEVELING, reset_bed_level()); // After changing kinematics bed-level data is no longer valid
recalc_delta_settings();
};
START_MENU();

View File

@ -39,8 +39,12 @@
#include "game/game.h"
#endif
#define MACHINE_CAN_STOP (EITHER(SDSUPPORT, HOST_PROMPT_SUPPORT) || defined(ACTION_ON_CANCEL))
#define MACHINE_CAN_PAUSE (ANY(SDSUPPORT, HOST_PROMPT_SUPPORT, PARK_HEAD_ON_PAUSE) || defined(ACTION_ON_PAUSE))
#if EITHER(SDSUPPORT, HOST_PROMPT_SUPPORT) || defined(ACTION_ON_CANCEL)
#define MACHINE_CAN_STOP 1
#endif
#if ANY(SDSUPPORT, HOST_PROMPT_SUPPORT, PARK_HEAD_ON_PAUSE) || defined(ACTION_ON_PAUSE)
#define MACHINE_CAN_PAUSE 1
#endif
#if ENABLED(PRUSA_MMU2)
#include "../../lcd/menu/menu_mmu2.h"
@ -140,9 +144,8 @@ void menu_main() {
#endif // !HAS_ENCODER_WHEEL && SDSUPPORT
#if MACHINE_CAN_PAUSE
if (printingIsPaused()) ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);
#endif
if (TERN0(MACHINE_CAN_PAUSE, printingIsPaused()))
ACTION_ITEM(MSG_RESUME_PRINT, ui.resume_print);
SUBMENU(MSG_MOTION, menu_motion);
}
@ -236,9 +239,7 @@ void menu_main() {
#if HAS_SERVICE_INTERVALS
static auto _service_reset = [](const int index) {
print_job_timer.resetServiceInterval(index);
#if HAS_BUZZER
ui.completion_feedback();
#endif
TERN_(HAS_BUZZER, ui.completion_feedback());
ui.reset_status();
ui.return_to_status();
};

View File

@ -113,9 +113,7 @@ class MenuItem_sdfolder : public MenuItem_sdbase {
encoderTopLine = 0;
ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
ui.screen_changed = true;
#if HAS_GRAPHICAL_LCD
ui.drawing_screen = false;
#endif
TERN_(HAS_GRAPHICAL_LCD, ui.drawing_screen = false);
ui.refresh();
}
};

View File

@ -33,7 +33,7 @@
#include "../../feature/mixing.h"
#define CHANNEL_MIX_EDITING !DUAL_MIXING_EXTRUDER
#define CHANNEL_MIX_EDITING !HAS_DUAL_MIXING
#if ENABLED(GRADIENT_MIX)
@ -120,7 +120,7 @@
static uint8_t v_index;
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
void _lcd_draw_mix(const uint8_t y) {
char tmp[20]; // "100%_100%"
sprintf_P(tmp, PSTR("%3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
@ -131,9 +131,7 @@ static uint8_t v_index;
void _lcd_mixer_select_vtool() {
mixer.T(v_index);
#if DUAL_MIXING_EXTRUDER
_lcd_draw_mix(LCD_HEIGHT - 1);
#endif
TERN_(HAS_DUAL_MIXING, _lcd_draw_mix(LCD_HEIGHT - 1));
}
#if CHANNEL_MIX_EDITING
@ -156,7 +154,7 @@ void _lcd_mixer_select_vtool() {
void lcd_mixer_mix_edit() {
#if DUAL_MIXING_EXTRUDER && !CHANNEL_MIX_EDITING
#if HAS_DUAL_MIXING && !CHANNEL_MIX_EDITING
// Adjust 2-channel mix from the encoder
if (ui.encoderPosition != 0) {
@ -194,7 +192,7 @@ void lcd_mixer_mix_edit() {
#endif
}
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
//
// Toggle Dual-Mix
@ -240,12 +238,12 @@ void menu_mixer() {
v_index = mixer.get_current_vtool();
EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
, true
#endif
);
#if DUAL_MIXING_EXTRUDER
#if HAS_DUAL_MIXING
{
char tmp[10];
SUBMENU(MSG_MIX, lcd_mixer_mix_edit);

View File

@ -86,28 +86,16 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
#if HAS_SOFTWARE_ENDSTOPS
if (soft_endstops_enabled) switch (axis) {
case X_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
min = soft_endstop.min.x;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
max = soft_endstop.max.x;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
break;
case Y_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
min = soft_endstop.min.y;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
max = soft_endstop.max.y;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
break;
case Z_AXIS:
#if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
min = soft_endstop.min.z;
#endif
#if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
max = soft_endstop.max.z;
#endif
TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
default: break;
}
#endif // HAS_SOFTWARE_ENDSTOPS
@ -230,9 +218,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
case Y_AXIS: STATIC_ITEM(MSG_MOVE_Y, SS_CENTER|SS_INVERT); break;
case Z_AXIS: STATIC_ITEM(MSG_MOVE_Z, SS_CENTER|SS_INVERT); break;
default:
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
manual_move_e_origin = current_position.e;
#endif
TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e);
STATIC_ITEM(MSG_MOVE_E, SS_CENTER|SS_INVERT);
break;
}
@ -275,20 +261,12 @@ void menu_move() {
EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
#endif
if (
if (true
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
all_axes_homed()
#else
true
&& all_axes_homed()
#endif
) {
if (
#if ENABLED(DELTA)
current_position.z <= delta_clip_start_height
#else
true
#endif
) {
if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
SUBMENU(MSG_MOVE_X, []{ _menu_move_distance(X_AXIS, lcd_move_x); });
SUBMENU(MSG_MOVE_Y, []{ _menu_move_distance(Y_AXIS, lcd_move_y); });
}

View File

@ -113,9 +113,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#endif
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(1,n);
ACTION_ITEM(MSG_PREHEAT_1_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(0);
#endif
TERN_(HAS_HEATED_BED, _preheat_bed(0));
HOTEND_LOOP() thermalManager.setTargetHotend(ui.preheat_hotend_temp[0], e);
});
#endif // HAS_MULTI_HOTEND
@ -141,9 +139,7 @@ void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb
#endif
LOOP_S_L_N(n, 1, HOTENDS) PREHEAT_ITEMS(2,n);
ACTION_ITEM(MSG_PREHEAT_2_ALL, []() {
#if HAS_HEATED_BED
_preheat_bed(1);
#endif
TERN_(HAS_HEATED_BED, _preheat_bed(1));
HOTEND_LOOP() thermalManager.setTargetHotend(ui.preheat_hotend_temp[1], e);
});
#endif // HAS_MULTI_HOTEND
@ -284,9 +280,7 @@ void menu_temperature() {
//
bool has_heat = false;
HOTEND_LOOP() if (thermalManager.temp_hotend[HOTEND_INDEX].target) { has_heat = true; break; }
#if HAS_HEATED_BED
if (thermalManager.temp_bed.target) has_heat = true;
#endif
if (TERN0(HAS_HEATED_BED, thermalManager.temp_bed.target)) has_heat = true;
if (has_heat) ACTION_ITEM(MSG_COOLDOWN, lcd_cooldown);
#endif // HAS_TEMP_HOTEND

View File

@ -67,18 +67,10 @@
const float spm = planner.steps_to_mm[axis];
MenuEditItemBase::draw_edit_screen(msg, BABYSTEP_TO_STR(spm * babystep.accum));
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
const bool in_view = (true
#if HAS_GRAPHICAL_LCD
&& PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1)
#endif
);
const bool in_view = TERN1(HAS_GRAPHICAL_LCD, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1));
if (in_view) {
#if HAS_GRAPHICAL_LCD
ui.set_font(FONT_MENU);
lcd_moveto(0, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT);
#else
lcd_moveto(0, LCD_HEIGHT - 1);
#endif
TERN_(HAS_GRAPHICAL_LCD, ui.set_font(FONT_MENU));
lcd_moveto(0, TERN(HAS_GRAPHICAL_LCD, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)]));

View File

@ -68,9 +68,7 @@ static void _lcd_mesh_fine_tune(PGM_P const msg) {
if (ui.should_draw()) {
MenuEditItemBase::draw_edit_screen(msg, ftostr43sign(mesh_edit_value));
#if ENABLED(MESH_EDIT_GFX_OVERLAY)
_lcd_zoffset_overlay_gfx(mesh_edit_value);
#endif
TERN_(MESH_EDIT_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(mesh_edit_value));
}
}