Apply ternary macros

This commit is contained in:
Scott Lahteine 2020-04-25 17:53:06 -05:00
parent 967c1d8534
commit c536b8de62
13 changed files with 79 additions and 230 deletions

View file

@ -100,11 +100,9 @@ class TFilamentMonitor : public FilamentMonitorBase {
// Give the response a chance to update its counter.
static inline void run() {
if (enabled && !filament_ran_out && (printingIsActive()
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|| did_pause_print
#endif
)) {
if ( enabled && !filament_ran_out
&& (printingIsActive() || TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print))
) {
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
#endif
@ -153,11 +151,7 @@ class FilamentSensorBase {
// Return a bitmask of runout flag states (1 bits always indicates runout)
static inline uint8_t poll_runout_states() {
return (poll_runout_pins()
#if DISABLED(FIL_RUNOUT_INVERTING)
^ uint8_t(_BV(NUM_RUNOUT_SENSORS) - 1)
#endif
);
return poll_runout_pins() ^ uint8_t(TERN0(FIL_RUNOUT_INVERTING, _BV(NUM_RUNOUT_SENSORS) - 1));
}
#undef INIT_RUNOUT_PIN
@ -217,26 +211,14 @@ class FilamentSensorBase {
private:
static inline bool poll_runout_state(const uint8_t extruder) {
const uint8_t runout_states = poll_runout_states();
#if NUM_RUNOUT_SENSORS == 1
UNUSED(extruder);
#endif
if (true
#if NUM_RUNOUT_SENSORS > 1
#if ENABLED(DUAL_X_CARRIAGE)
&& (dual_x_carriage_mode == DXC_DUPLICATION_MODE || dual_x_carriage_mode == DXC_MIRRORED_MODE)
#elif ENABLED(MULTI_NOZZLE_DUPLICATION)
&& extruder_duplication_enabled
#else
&& false
#endif
#endif
) return runout_states; // Any extruder
#if NUM_RUNOUT_SENSORS > 1
return TEST(runout_states, extruder); // Specific extruder
if ( !TERN0(DUAL_X_CARRIAGE, dxc_is_duplicating())
&& !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled)
) return TEST(runout_states, extruder); // A specific extruder ran out
#endif
return !!runout_states; // Any extruder ran out
}
public:
@ -302,9 +284,7 @@ class FilamentSensorBase {
static inline void block_completed(const block_t* const b) {
if (b->steps.x || b->steps.y || b->steps.z
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|| did_pause_print // Allow pause purge move to re-trigger runout state
#endif
|| TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print) // Allow pause purge move to re-trigger runout state
) {
// Only trigger on extrusion with XYZ movement to allow filament change and retract/recover.
const uint8_t e = b->extruder;
@ -338,11 +318,7 @@ class FilamentSensorBase {
typedef TFilamentMonitor<
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
RunoutResponseDelayed,
#if ENABLED(FILAMENT_MOTION_SENSOR)
FilamentSensorEncoder
#else
FilamentSensorSwitch
#endif
TERN(FILAMENT_MOTION_SENSOR, FilamentSensorEncoder, FilamentSensorSwitch)
#else
RunoutResponseDebounced, FilamentSensorSwitch
#endif

View file

@ -103,12 +103,8 @@ void GcodeSuite::M600() {
#if EXTRUDERS > 1
// Change toolhead if specified
const uint8_t active_extruder_before_filament_change = active_extruder;
if (
active_extruder != target_extruder
#if ENABLED(DUAL_X_CARRIAGE)
&& dual_x_carriage_mode != DXC_DUPLICATION_MODE && dual_x_carriage_mode != DXC_MIRRORED_MODE
#endif
) tool_change(target_extruder, false);
if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !dxc_is_duplicating()))
tool_change(target_extruder, false);
#endif
// Initial retract before move to filament change position

View file

@ -87,11 +87,7 @@ void MarlinUI::save_previous_screen() {
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
}
void MarlinUI::_goto_previous_screen(
#if ENABLED(TURBO_BACK_MENU_ITEM)
const bool is_back/*=false*/
#endif
) {
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
#if DISABLED(TURBO_BACK_MENU_ITEM)
constexpr bool is_back = false;
#endif
@ -233,34 +229,16 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
}
else if (screen == status_screen && currentScreen == menu_main && PENDING(millis(), doubleclick_expire_ms)) {
#if ENABLED(BABYSTEP_WITHOUT_HOMING)
constexpr bool can_babystep = true;
#else
const bool can_babystep = all_axes_known();
#endif
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
constexpr bool should_babystep = true;
#else
const bool should_babystep = printer_busy();
#endif
if (should_babystep && can_babystep) {
screen =
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
lcd_babystep_zoffset
#else
lcd_babystep_z
#endif
;
}
#if ENABLED(MOVE_Z_WHEN_IDLE)
if ( (ENABLED(BABYSTEP_WITHOUT_HOMING) || all_axes_known())
&& (ENABLED(BABYSTEP_ALWAYS_AVAILABLE) || printer_busy()) )
screen = TERN(BABYSTEP_ZPROBE_OFFSET, lcd_babystep_zoffset, lcd_babystep_z);
else {
#if ENABLED(MOVE_Z_WHEN_IDLE)
move_menu_scale = MOVE_Z_IDLE_MULTIPLICATOR;
screen = lcd_move_z;
}
#endif
}
}
#endif
currentScreen = screen;
@ -277,11 +255,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
// Re-initialize custom characters that may be re-used
#if HAS_CHARACTER_LCD
if (true
#if ENABLED(AUTO_BED_LEVELING_UBL)
&& !ubl.lcd_map_control
#endif
) set_custom_characters(screen == status_screen ? CHARSET_INFO : CHARSET_MENU);
if (TERN1(AUTO_BED_LEVELING_UBL, !ubl.lcd_map_control))
set_custom_characters(screen == status_screen ? CHARSET_INFO : CHARSET_MENU);
#endif
refresh(LCDVIEW_CALL_REDRAW_NEXT);
@ -377,13 +352,10 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
new_probe_offset = probe.offset.z + diff,
new_offs =
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff
#else
new_probe_offset
#endif
;
new_offs = TERN(BABYSTEP_HOTEND_Z_OFFSET
, do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff
, new_probe_offset
);
if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
babystep.add_steps(Z_AXIS, babystep_increment);
@ -397,30 +369,23 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
}
}
if (ui.should_draw()) {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
if (!do_probe)
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
#endif
if (do_probe) {
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), BABYSTEP_TO_STR(probe.offset.z));
TERN_(BABYSTEP_ZPROBE_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(probe.offset.z));
}
else {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), ftostr54sign(hotend_offset[active_extruder].z));
#endif
}
}
}
#endif // BABYSTEP_ZPROBE_OFFSET
#if ENABLED(EEPROM_SETTINGS)
void lcd_store_settings() {
const bool saved = settings.save();
ui.completion_feedback(saved);
UNUSED(saved);
}
void lcd_load_settings() {
const bool loaded = settings.load();
ui.completion_feedback(loaded);
UNUSED(loaded);
}
void lcd_store_settings() { ui.completion_feedback(settings.save()); }
void lcd_load_settings() { ui.completion_feedback(settings.load()); }
#endif
void _lcd_draw_homing() {

View file

@ -132,13 +132,7 @@ void menu_cancelobject();
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
constexpr float extrude_maxlength =
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
EXTRUDE_MAXLENGTH
#else
999
#endif
;
constexpr float extrude_maxlength = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 999);
EDIT_ITEM_FAST(float3, MSG_FILAMENT_UNLOAD, &fc_settings[active_extruder].unload_length, 0, extrude_maxlength);
#if EXTRUDERS > 1

View file

@ -206,13 +206,7 @@ void menu_advanced_settings();
#if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
void bltouch_report() {
SERIAL_ECHOLNPAIR("EEPROM Last BLTouch Mode - ", (int)bltouch.last_written_mode);
SERIAL_ECHOLNPGM("Configuration BLTouch Mode - "
#if ENABLED(BLTOUCH_SET_5V_MODE)
"5V"
#else
"OD"
#endif
);
SERIAL_ECHOLNPGM("Configuration BLTouch Mode - " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD"));
char mess[21];
strcpy_P(mess, PSTR("BLTouch Mode - "));
strcpy_P(&mess[15], bltouch.last_written_mode ? PSTR("5V") : PSTR("OD"));
@ -411,11 +405,7 @@ void menu_configuration() {
//
#if ENABLED(CASE_LIGHT_MENU)
#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
if (true
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
&& PWM_PIN(CASE_LIGHT_PIN)
#endif
)
if (TERN1(CASE_LIGHT_USE_NEOPIXEL, PWM_PIN(CASE_LIGHT_PIN)))
SUBMENU(MSG_CASE_LIGHT, menu_case_light);
else
#endif

View file

@ -29,13 +29,7 @@
void menu_game() {
START_MENU();
BACK_ITEM(
#if ENABLED(LCD_INFO_MENU)
MSG_INFO_MENU
#else
MSG_MAIN
#endif
);
BACK_ITEM(TERN(LCD_INFO_MENU, MSG_INFO_MENU, MSG_MAIN));
#if ENABLED(MARLIN_BRICKOUT)
SUBMENU(MSG_BRICKOUT, brickout.enter_game);
#endif

View file

@ -51,6 +51,8 @@
printStatistics stats = print_job_timer.getStats();
char buffer[21];
START_SCREEN(); // 12345678901234567890
VALUE_ITEM(MSG_INFO_PRINT_COUNT, i16tostr3left(stats.totalPrints), SS_LEFT); // Print Count: 999
VALUE_ITEM(MSG_INFO_COMPLETED_PRINTS, i16tostr3left(stats.finishedPrints), SS_LEFT); // Completed : 666
@ -62,7 +64,10 @@
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.longestPrint).toString(buffer)); // > 99y 364d 23h 59m 59s
STATIC_ITEM(MSG_INFO_PRINT_FILAMENT, SS_LEFT); // Extruded total:
sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
sprintf_P(buffer, PSTR("%ld.%im")
, long(stats.filamentUsed / 1000)
, int16_t(stats.filamentUsed / 100) % 10
);
STATIC_ITEM_P(PSTR("> "), SS_LEFT, buffer); // > 125m
#if SERVICE_INTERVAL_1 > 0 || SERVICE_INTERVAL_2 > 0 || SERVICE_INTERVAL_3 > 0
@ -171,16 +176,7 @@ void menu_info_thermistors() {
#endif
#if EXTRUDERS
{
STATIC_ITEM(
#if WATCH_HOTENDS
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_HOTENDS, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif
#if HAS_HEATED_BED
@ -191,34 +187,17 @@ void menu_info_thermistors() {
STATIC_ITEM_P(PSTR("BED:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(BED_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(BED_MAXTEMP), SS_LEFT);
STATIC_ITEM(
#if WATCH_BED
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_BED, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif
#if HAS_HEATED_CHAMBER
{
#undef THERMISTOR_ID
#define THERMISTOR_ID TEMP_SENSOR_CHAMBER
#include "../thermistornames.h"
STATIC_ITEM_P(PSTR("CHAM:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(CHAMBER_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(CHAMBER_MAXTEMP), SS_LEFT);
STATIC_ITEM(
#if WATCH_CHAMBER
MSG_INFO_RUNAWAY_ON
#else
MSG_INFO_RUNAWAY_OFF
#endif
, SS_LEFT
);
}
STATIC_ITEM(TERN(WATCH_CHAMBER, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif
END_SCREEN();
@ -295,13 +274,7 @@ void menu_info() {
START_MENU();
BACK_ITEM(MSG_MAIN);
#if ENABLED(LCD_PRINTER_INFO_IS_BOOTSCREEN)
SUBMENU(MSG_INFO_PRINTER_MENU, (
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
menu_show_custom_bootscreen
#else
menu_show_marlin_bootscreen
#endif
));
SUBMENU(MSG_INFO_PRINTER_MENU, TERN(SHOW_CUSTOM_BOOTSCREEN, menu_show_custom_bootscreen, menu_show_marlin_bootscreen));
#else
SUBMENU(MSG_INFO_PRINTER_MENU, menu_info_printer); // Printer Info >
SUBMENU(MSG_INFO_BOARD_MENU, menu_info_board); // Board Info >

View file

@ -237,11 +237,7 @@ void menu_mixer() {
BACK_ITEM(MSG_MAIN);
v_index = mixer.get_current_vtool();
EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
#if HAS_DUAL_MIXING
, true
#endif
);
EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool, ENABLED(HAS_DUAL_MIXING));
#if HAS_DUAL_MIXING
{

View file

@ -54,8 +54,7 @@ void _mmu2_load_filament(uint8_t index) {
ui.reset_status();
}
void action_mmu2_load_all() {
LOOP_L_N(i, EXTRUDERS)
_mmu2_load_filament(i);
LOOP_L_N(i, EXTRUDERS) _mmu2_load_filament(i);
ui.return_to_status();
}

View file

@ -59,11 +59,11 @@ extern int8_t manual_move_axis;
// Tell ui.update() to start a move to current_position" after a short delay.
//
inline void manual_move_to_current(AxisEnum axis
#if E_MANUAL > 1
#if MULTI_MANUAL
, const int8_t eindex=-1
#endif
) {
#if E_MANUAL > 1
#if MULTI_MANUAL
if (axis == E_AXIS) ui.manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
#endif
manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
@ -144,22 +144,14 @@ void lcd_move_z() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Z), Z_AXIS); }
#if E_MANUAL
static void lcd_move_e(
#if E_MANUAL > 1
const int8_t eindex=-1
#endif
) {
static void lcd_move_e(TERN_(MULTI_MANUAL, const int8_t eindex=-1)) {
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
if (ui.encoderPosition) {
if (!ui.processing_manual_move) {
const float diff = float(int32_t(ui.encoderPosition)) * move_menu_scale;
#if IS_KINEMATIC
manual_move_offset += diff;
#else
current_position.e += diff;
#endif
TERN(IS_KINEMATIC, manual_move_offset, current_position.e) += diff;
manual_move_to_current(E_AXIS
#if E_MANUAL > 1
#if MULTI_MANUAL
, eindex
#endif
);
@ -168,24 +160,14 @@ void lcd_move_z() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Z), Z_AXIS); }
ui.encoderPosition = 0;
}
if (ui.should_draw()) {
#if E_MANUAL > 1
#if MULTI_MANUAL
MenuItemBase::init(eindex);
#endif
MenuEditItemBase::draw_edit_screen(
GET_TEXT(
#if E_MANUAL > 1
MSG_MOVE_EN
#else
MSG_MOVE_E
#endif
),
GET_TEXT(TERN(MULTI_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
ftostr41sign(current_position.e
#if IS_KINEMATIC
+ manual_move_offset
#endif
#if ENABLED(MANUAL_E_MOVES_RELATIVE)
- manual_move_e_origin
#endif
+ TERN0(IS_KINEMATIC, manual_move_offset)
- TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
)
);
} // should_draw
@ -261,11 +243,7 @@ void menu_move() {
EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
#endif
if (true
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
&& all_axes_homed()
#endif
) {
if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
SUBMENU(MSG_MOVE_X, []{ _menu_move_distance(X_AXIS, lcd_move_x); });
SUBMENU(MSG_MOVE_Y, []{ _menu_move_distance(Y_AXIS, lcd_move_y); });
@ -332,7 +310,7 @@ void menu_move() {
SUBMENU_MOVE_E(2);
#endif
#elif E_MANUAL > 1
#elif MULTI_MANUAL
// Independent extruders with one E-stepper per hotend
LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);

View file

@ -638,7 +638,7 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
float manual_move_offset = 0;
#endif
#if E_MANUAL > 1
#if MULTI_MANUAL
int8_t MarlinUI::manual_move_e_index = 0;
#endif

View file

@ -45,6 +45,10 @@
#define HAS_SLOW_BUTTONS 1
#endif
#if E_MANUAL > 1
#define MULTI_MANUAL 1
#endif
#if HAS_SPI_LCD
#include "../MarlinCore.h"
@ -491,15 +495,9 @@ public:
static void save_previous_screen();
// goto_previous_screen and go_back may also be used as menu item callbacks
#if ENABLED(TURBO_BACK_MENU_ITEM)
static void _goto_previous_screen(const bool is_back);
static inline void goto_previous_screen() { _goto_previous_screen(false); }
static inline void go_back() { _goto_previous_screen(true); }
#else
static void _goto_previous_screen();
FORCE_INLINE static void goto_previous_screen() { _goto_previous_screen(); }
FORCE_INLINE static void go_back() { _goto_previous_screen(); }
#endif
static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
static inline void goto_previous_screen() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, false)); }
static inline void go_back() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, true)); }
static void return_to_status();
static inline bool on_status_screen() { return currentScreen == status_screen; }
@ -510,11 +508,7 @@ public:
#endif
FORCE_INLINE static void defer_status_screen(const bool defer=true) {
#if LCD_TIMEOUT_TO_STATUS
defer_return_to_status = defer;
#else
UNUSED(defer);
#endif
TERN(LCD_TIMEOUT_TO_STATUS, defer_return_to_status = defer, UNUSED(defer));
}
static inline void goto_previous_screen_no_defer() {
@ -582,11 +576,7 @@ public:
static uint32_t encoderPosition;
#if ENABLED(REVERSE_ENCODER_DIRECTION)
#define ENCODERBASE -1
#else
#define ENCODERBASE +1
#endif
#define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1))
#if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
static int8_t encoderDirection;

View file

@ -137,9 +137,7 @@ typedef struct block_t {
static constexpr uint8_t extruder = 0;
#endif
#if ENABLED(MIXING_EXTRUDER)
MIXER_BLOCK_FIELD; // Normalized color for the mixing steppers
#endif
TERN_(MIXING_EXTRUDER, MIXER_BLOCK_FIELD); // Normalized color for the mixing steppers
// Settings for the trapezoid generator
uint32_t accelerate_until, // The index of the step event on which to stop acceleration