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

@ -152,11 +152,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
const float oldx = current_position.x,
grabpos = mpe_settings.parking_xpos[new_tool] + (new_tool ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
offsetcompensation = (0
#if HAS_HOTEND_OFFSET
+ hotend_offset[active_extruder].x * mpe_settings.compensation_factor
#endif
);
offsetcompensation = TERN0(HAS_HOTEND_OFFSET, hotend_offset[active_extruder].x * mpe_settings.compensation_factor);
if (axis_unhomed_error(_BV(X_AXIS))) return;
@ -322,9 +318,8 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
planner.synchronize();
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(4) Engage magnetic field");
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
#endif
// Just save power for inverted magnets
TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid(active_extruder));
pe_activate_solenoid(new_tool);
// STEP 5
@ -341,11 +336,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
// STEP 6
current_position.x = midpos
#if HAS_HOTEND_OFFSET
- hotend_offset[new_tool].x
#endif
;
current_position.x = midpos - TERN0(HAS_HOTEND_OFFSET, hotend_offset[new_tool].x);
if (DEBUGGING(LEVELING)) {
planner.synchronize();
DEBUG_POS("(6) Move midway between hotends", current_position);
@ -358,9 +349,8 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
else { // nomove == true
// Only engage magnetic field for new extruder
pe_activate_solenoid(new_tool);
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
#endif
// Just save power for inverted magnets
TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid(active_extruder));
}
}
@ -775,9 +765,8 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
*/
void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
if (new_tool == active_extruder) return;
#endif
if (TERN0(MAGNETIC_SWITCHING_TOOLHEAD, new_tool == active_extruder))
return;
#if ENABLED(MIXING_EXTRUDER)
@ -826,9 +815,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("No move (not homed)");
}
#if HAS_LCD_MENU
if (!no_move) ui.return_to_status();
#endif
TERN_(HAS_LCD_MENU, if (!no_move) ui.return_to_status());
#if ENABLED(DUAL_X_CARRIAGE)
const bool idex_full_control = dual_x_carriage_mode == DXC_FULL_CONTROL_MODE;
@ -873,9 +860,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (new_tool != old_tool) {
#if SWITCHING_NOZZLE_TWO_SERVOS
raise_nozzle(old_tool);
#endif
TERN_(SWITCHING_NOZZLE_TWO_SERVOS, raise_nozzle(old_tool));
REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S);
@ -902,9 +887,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
NOMORE(current_position.z, soft_endstop.max.z);
#endif
fast_line_to_current(Z_AXIS);
#if ENABLED(TOOLCHANGE_PARK)
current_position = toolchange_settings.change_point;
#endif
TERN_(TOOLCHANGE_PARK, current_position = toolchange_settings.change_point);
planner.buffer_line(current_position, feedrate_mm_s, old_tool);
planner.synchronize();
}
@ -912,9 +895,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if HAS_HOTEND_OFFSET
xyz_pos_t diff = hotend_offset[new_tool] - hotend_offset[old_tool];
#if ENABLED(DUAL_X_CARRIAGE)
diff.x = 0;
#endif
TERN_(DUAL_X_CARRIAGE, diff.x = 0);
#else
constexpr xyz_pos_t diff{0};
#endif
@ -981,9 +962,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
singlenozzle_temp[old_tool] = thermalManager.temp_hotend[0].target;
if (singlenozzle_temp[new_tool] && singlenozzle_temp[new_tool] != singlenozzle_temp[old_tool]) {
thermalManager.setTargetHotend(singlenozzle_temp[new_tool], 0);
#if HAS_DISPLAY
thermalManager.set_heating_message(0);
#endif
TERN_(HAS_DISPLAY, thermalManager.set_heating_message(0));
(void)thermalManager.wait_for_hotend(0, false); // Wait for heating or cooling
}
#endif
@ -1030,9 +1009,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
}
else if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Move back skipped");
#if ENABLED(DUAL_X_CARRIAGE)
active_extruder_parked = false;
#endif
TERN_(DUAL_X_CARRIAGE, active_extruder_parked = false);
}
#if ENABLED(SWITCHING_NOZZLE)
else {
@ -1041,13 +1018,9 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
}
#endif
#if ENABLED(PRUSA_MMU2)
mmu2.tool_change(new_tool);
#endif
TERN_(PRUSA_MMU2, mmu2.tool_change(new_tool));
#if SWITCHING_NOZZLE_TWO_SERVOS
lower_nozzle(new_tool);
#endif
TERN_(SWITCHING_NOZZLE_TWO_SERVOS, lower_nozzle(new_tool));
} // (new_tool != old_tool)
@ -1068,9 +1041,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
move_extruder_servo(active_extruder);
#endif
#if HAS_FANMUX
fanmux_switch(active_extruder);
#endif
TERN_(HAS_FANMUX, fanmux_switch(active_extruder));
#ifdef EVENT_GCODE_AFTER_TOOLCHANGE
if (!no_move && TERN1(DUAL_X_CARRIAGE, dual_x_carriage_mode == DXC_AUTO_PARK_MODE))