Apply TERN to compact code (#17619)
This commit is contained in:
@ -126,22 +126,16 @@
|
||||
*/
|
||||
destination.set(safe_homing_xy, current_position.z);
|
||||
|
||||
#if HOMING_Z_WITH_PROBE
|
||||
destination -= probe.offset_xy;
|
||||
#endif
|
||||
TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy);
|
||||
|
||||
if (position_is_reachable(destination)) {
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("home_z_safely", destination);
|
||||
|
||||
// This causes the carriage on Dual X to unpark
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
active_extruder_parked = false;
|
||||
#endif
|
||||
TERN_(DUAL_X_CARRIAGE, active_extruder_parked = false);
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
safe_delay(500); // Short delay needed to settle
|
||||
#endif
|
||||
TERN_(SENSORLESS_HOMING, safe_delay(500)); // Short delay needed to settle
|
||||
|
||||
do_blocking_move_to_xy(destination);
|
||||
homeaxis(Z_AXIS);
|
||||
@ -175,9 +169,7 @@
|
||||
void end_slow_homing(const slow_homing_t &slow_homing) {
|
||||
planner.settings.max_acceleration_mm_per_s2[X_AXIS] = slow_homing.acceleration.x;
|
||||
planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = slow_homing.acceleration.y;
|
||||
#if HAS_CLASSIC_JERK
|
||||
planner.max_jerk = slow_homing.jerk_xy;
|
||||
#endif
|
||||
TERN_(HAS_CLASSIC_JERK, planner.max_jerk = slow_homing.jerk_xy);
|
||||
planner.reset_acceleration_rates();
|
||||
}
|
||||
|
||||
@ -237,22 +229,18 @@ void GcodeSuite::G28() {
|
||||
#if HAS_LEVELING
|
||||
|
||||
// Cancel the active G29 session
|
||||
#if ENABLED(PROBE_MANUALLY)
|
||||
g29_in_progress = false;
|
||||
#endif
|
||||
TERN_(PROBE_MANUALLY, g29_in_progress = false);
|
||||
|
||||
#if ENABLED(RESTORE_LEVELING_AFTER_G28)
|
||||
const bool leveling_was_active = planner.leveling_active;
|
||||
#endif
|
||||
TERN_(RESTORE_LEVELING_AFTER_G28, const bool leveling_was_active = planner.leveling_active);
|
||||
set_bed_leveling_enabled(false);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CNC_WORKSPACE_PLANES)
|
||||
workspace_plane = PLANE_XY;
|
||||
#endif
|
||||
TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);
|
||||
|
||||
#define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
|
||||
#define HAS_HOMING_CURRENT (HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2))
|
||||
#if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2)
|
||||
#define HAS_HOMING_CURRENT 1
|
||||
#endif
|
||||
|
||||
#if HAS_HOMING_CURRENT
|
||||
auto debug_current = [](PGM_P const s, const int16_t a, const int16_t b){
|
||||
@ -280,9 +268,7 @@ void GcodeSuite::G28() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
slow_homing_t slow_homing = begin_slow_homing();
|
||||
#endif
|
||||
TERN_(IMPROVE_HOMING_RELIABILITY, slow_homing_t slow_homing = begin_slow_homing());
|
||||
|
||||
// Always home with tool 0 active
|
||||
#if HAS_MULTI_HOTEND
|
||||
@ -292,9 +278,7 @@ void GcodeSuite::G28() {
|
||||
tool_change(0, true);
|
||||
#endif
|
||||
|
||||
#if HAS_DUPLICATION_MODE
|
||||
extruder_duplication_enabled = false;
|
||||
#endif
|
||||
TERN_(HAS_DUPLICATION_MODE, extruder_duplication_enabled = false);
|
||||
|
||||
remember_feedrate_scaling_off();
|
||||
|
||||
@ -306,9 +290,7 @@ void GcodeSuite::G28() {
|
||||
|
||||
home_delta();
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
end_slow_homing(slow_homing);
|
||||
#endif
|
||||
TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
|
||||
|
||||
#else // NOT DELTA
|
||||
|
||||
@ -380,17 +362,13 @@ void GcodeSuite::G28() {
|
||||
if (DISABLED(HOME_Y_BEFORE_X) && doY)
|
||||
homeaxis(Y_AXIS);
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
end_slow_homing(slow_homing);
|
||||
#endif
|
||||
TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
|
||||
|
||||
// Home Z last if homing towards the bed
|
||||
#if Z_HOME_DIR < 0
|
||||
|
||||
if (doZ) {
|
||||
#if ENABLED(BLTOUCH)
|
||||
bltouch.init();
|
||||
#endif
|
||||
TERN_(BLTOUCH, bltouch.init());
|
||||
#if ENABLED(Z_SAFE_HOMING)
|
||||
home_z_safely();
|
||||
#else
|
||||
@ -425,9 +403,7 @@ void GcodeSuite::G28() {
|
||||
|
||||
if (dxc_is_duplicating()) {
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
slow_homing = begin_slow_homing();
|
||||
#endif
|
||||
TERN_(IMPROVE_HOMING_RELIABILITY, slow_homing = begin_slow_homing());
|
||||
|
||||
// Always home the 2nd (right) extruder first
|
||||
active_extruder = 1;
|
||||
@ -448,9 +424,7 @@ void GcodeSuite::G28() {
|
||||
dual_x_carriage_mode = IDEX_saved_mode;
|
||||
stepper.set_directions();
|
||||
|
||||
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
||||
end_slow_homing(slow_homing);
|
||||
#endif
|
||||
TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
|
||||
}
|
||||
|
||||
#endif // DUAL_X_CARRIAGE
|
||||
@ -458,18 +432,14 @@ void GcodeSuite::G28() {
|
||||
endstops.not_homing();
|
||||
|
||||
// Clear endstop state for polled stallGuard endstops
|
||||
#if ENABLED(SPI_ENDSTOPS)
|
||||
endstops.clear_endstop_state();
|
||||
#endif
|
||||
TERN_(SPI_ENDSTOPS, endstops.clear_endstop_state());
|
||||
|
||||
#if BOTH(DELTA, DELTA_HOME_TO_SAFE_ZONE)
|
||||
// move to a height where we can use the full xy-area
|
||||
do_blocking_move_to_z(delta_clip_start_height);
|
||||
#endif
|
||||
|
||||
#if ENABLED(RESTORE_LEVELING_AFTER_G28)
|
||||
set_bed_leveling_enabled(leveling_was_active);
|
||||
#endif
|
||||
TERN_(RESTORE_LEVELING_AFTER_G28, set_bed_leveling_enabled(leveling_was_active));
|
||||
|
||||
restore_feedrate_and_scaling();
|
||||
|
||||
|
@ -63,12 +63,7 @@ enum CalEnum : char { // the 7 main calibration points -
|
||||
#define LOOP_CAL_RAD(VAR) LOOP_CAL_PT(VAR, __A, _7P_STEP)
|
||||
#define LOOP_CAL_ACT(VAR, _4P, _OP) LOOP_CAL_PT(VAR, _OP ? _AB : __A, _4P ? _4P_STEP : _7P_STEP)
|
||||
|
||||
#if HOTENDS > 1
|
||||
const uint8_t old_tool_index = active_extruder;
|
||||
#define AC_CLEANUP() ac_cleanup(old_tool_index)
|
||||
#else
|
||||
#define AC_CLEANUP() ac_cleanup()
|
||||
#endif
|
||||
TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index = active_extruder);
|
||||
|
||||
float lcd_probe_pt(const xy_pos_t &xy);
|
||||
|
||||
@ -79,9 +74,7 @@ void ac_home() {
|
||||
}
|
||||
|
||||
void ac_setup(const bool reset_bed) {
|
||||
#if HOTENDS > 1
|
||||
tool_change(0, true);
|
||||
#endif
|
||||
TERN_(HAS_MULTI_HOTEND, tool_change(0, true));
|
||||
|
||||
planner.synchronize();
|
||||
remember_feedrate_scaling_off();
|
||||
@ -91,21 +84,11 @@ void ac_setup(const bool reset_bed) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void ac_cleanup(
|
||||
#if HOTENDS > 1
|
||||
const uint8_t old_tool_index
|
||||
#endif
|
||||
) {
|
||||
#if ENABLED(DELTA_HOME_TO_SAFE_ZONE)
|
||||
do_blocking_move_to_z(delta_clip_start_height);
|
||||
#endif
|
||||
#if HAS_BED_PROBE
|
||||
probe.stow();
|
||||
#endif
|
||||
void ac_cleanup(TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index)) {
|
||||
TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height));
|
||||
TERN_(HAS_BED_PROBE, probe.stow());
|
||||
restore_feedrate_and_scaling();
|
||||
#if HOTENDS > 1
|
||||
tool_change(old_tool_index, true);
|
||||
#endif
|
||||
TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index, true));
|
||||
}
|
||||
|
||||
void print_signed_float(PGM_P const prefix, const float &f) {
|
||||
@ -488,7 +471,7 @@ void GcodeSuite::G33() {
|
||||
zero_std_dev_old = zero_std_dev;
|
||||
if (!probe_calibration_points(z_at_pt, probe_points, towers_set, stow_after_each)) {
|
||||
SERIAL_ECHOLNPGM("Correct delta settings with M665 and M666");
|
||||
return AC_CLEANUP();
|
||||
return ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
|
||||
}
|
||||
zero_std_dev = std_dev_points(z_at_pt, _0p_calibration, _1p_calibration, _4p_calibration, _4p_opposite_points);
|
||||
|
||||
@ -659,7 +642,7 @@ void GcodeSuite::G33() {
|
||||
}
|
||||
while (((zero_std_dev < test_precision && iterations < 31) || iterations <= force_iterations) && zero_std_dev > calibration_precision);
|
||||
|
||||
AC_CLEANUP();
|
||||
ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));
|
||||
}
|
||||
|
||||
#endif // DELTA_AUTO_CALIBRATION
|
||||
|
@ -113,15 +113,11 @@ void GcodeSuite::G34() {
|
||||
|
||||
// Disable the leveling matrix before auto-aligning
|
||||
#if HAS_LEVELING
|
||||
#if ENABLED(RESTORE_LEVELING_AFTER_G34)
|
||||
const bool leveling_was_active = planner.leveling_active;
|
||||
#endif
|
||||
TERN_(RESTORE_LEVELING_AFTER_G34, const bool leveling_was_active = planner.leveling_active);
|
||||
set_bed_leveling_enabled(false);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CNC_WORKSPACE_PLANES)
|
||||
workspace_plane = PLANE_XY;
|
||||
#endif
|
||||
TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);
|
||||
|
||||
// Always home with tool 0 active
|
||||
#if HAS_MULTI_HOTEND
|
||||
@ -129,18 +125,12 @@ void GcodeSuite::G34() {
|
||||
tool_change(0, true);
|
||||
#endif
|
||||
|
||||
#if HAS_DUPLICATION_MODE
|
||||
extruder_duplication_enabled = false;
|
||||
#endif
|
||||
TERN_(HAS_DUPLICATION_MODE, extruder_duplication_enabled = false);
|
||||
|
||||
#if BOTH(BLTOUCH, BLTOUCH_HS_MODE)
|
||||
// In BLTOUCH HS mode, the probe travels in a deployed state.
|
||||
// Users of G34 might have a badly misaligned bed, so raise Z by the
|
||||
// length of the deployed pin (BLTOUCH stroke < 7mm)
|
||||
#define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES + 7.0f
|
||||
#else
|
||||
#define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES
|
||||
#endif
|
||||
// In BLTOUCH HS mode, the probe travels in a deployed state.
|
||||
// Users of G34 might have a badly misaligned bed, so raise Z by the
|
||||
// length of the deployed pin (BLTOUCH stroke < 7mm)
|
||||
#define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE)
|
||||
|
||||
// Compute a worst-case clearance height to probe from. After the first
|
||||
// iteration this will be re-calculated based on the actual bed position
|
||||
@ -386,9 +376,7 @@ void GcodeSuite::G34() {
|
||||
#endif
|
||||
|
||||
// Restore the active tool after homing
|
||||
#if HAS_MULTI_HOTEND
|
||||
tool_change(old_tool_index, DISABLED(PARKING_EXTRUDER)); // Fetch previous tool for parking extruder
|
||||
#endif
|
||||
TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index, DISABLED(PARKING_EXTRUDER))); // Fetch previous tool for parking extruder
|
||||
|
||||
#if HAS_LEVELING && ENABLED(RESTORE_LEVELING_AFTER_G34)
|
||||
set_bed_leveling_enabled(leveling_was_active);
|
||||
|
@ -285,37 +285,19 @@ inline void probe_sides(measurements_t &m, const float uncertainty) {
|
||||
probe_side(m, uncertainty, TOP);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CALIBRATION_MEASURE_RIGHT)
|
||||
probe_side(m, uncertainty, RIGHT, probe_top_at_edge);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CALIBRATION_MEASURE_FRONT)
|
||||
probe_side(m, uncertainty, FRONT, probe_top_at_edge);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CALIBRATION_MEASURE_LEFT)
|
||||
probe_side(m, uncertainty, LEFT, probe_top_at_edge);
|
||||
#endif
|
||||
#if ENABLED(CALIBRATION_MEASURE_BACK)
|
||||
probe_side(m, uncertainty, BACK, probe_top_at_edge);
|
||||
#endif
|
||||
TERN_(CALIBRATION_MEASURE_RIGHT, probe_side(m, uncertainty, RIGHT, probe_top_at_edge));
|
||||
TERN_(CALIBRATION_MEASURE_FRONT, probe_side(m, uncertainty, FRONT, probe_top_at_edge));
|
||||
TERN_(CALIBRATION_MEASURE_LEFT, probe_side(m, uncertainty, LEFT, probe_top_at_edge));
|
||||
TERN_(CALIBRATION_MEASURE_BACK, probe_side(m, uncertainty, BACK, probe_top_at_edge));
|
||||
|
||||
// Compute the measured center of the calibration object.
|
||||
#if HAS_X_CENTER
|
||||
m.obj_center.x = (m.obj_side[LEFT] + m.obj_side[RIGHT]) / 2;
|
||||
#endif
|
||||
#if HAS_Y_CENTER
|
||||
m.obj_center.y = (m.obj_side[FRONT] + m.obj_side[BACK]) / 2;
|
||||
#endif
|
||||
TERN_(HAS_X_CENTER, m.obj_center.x = (m.obj_side[LEFT] + m.obj_side[RIGHT]) / 2);
|
||||
TERN_(HAS_Y_CENTER, m.obj_center.y = (m.obj_side[FRONT] + m.obj_side[BACK]) / 2);
|
||||
|
||||
// Compute the outside diameter of the nozzle at the height
|
||||
// at which it makes contact with the calibration object
|
||||
#if HAS_X_CENTER
|
||||
m.nozzle_outer_dimension.x = m.obj_side[RIGHT] - m.obj_side[LEFT] - dimensions.x;
|
||||
#endif
|
||||
#if HAS_Y_CENTER
|
||||
m.nozzle_outer_dimension.y = m.obj_side[BACK] - m.obj_side[FRONT] - dimensions.y;
|
||||
#endif
|
||||
TERN_(HAS_X_CENTER, m.nozzle_outer_dimension.x = m.obj_side[RIGHT] - m.obj_side[LEFT] - dimensions.x);
|
||||
TERN_(HAS_Y_CENTER, m.nozzle_outer_dimension.y = m.obj_side[BACK] - m.obj_side[FRONT] - dimensions.y);
|
||||
|
||||
park_above_object(m, uncertainty);
|
||||
|
||||
@ -544,13 +526,9 @@ inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty)
|
||||
|
||||
HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e);
|
||||
|
||||
#if HAS_HOTEND_OFFSET
|
||||
normalize_hotend_offsets();
|
||||
#endif
|
||||
TERN_(HAS_HOTEND_OFFSET, normalize_hotend_offsets());
|
||||
|
||||
#if HAS_MULTI_HOTEND
|
||||
set_nozzle(m, 0);
|
||||
#endif
|
||||
TERN_(HAS_MULTI_HOTEND, set_nozzle(m, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -567,9 +545,7 @@ inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty)
|
||||
inline void calibrate_all() {
|
||||
measurements_t m;
|
||||
|
||||
#if HAS_HOTEND_OFFSET
|
||||
reset_hotend_offsets();
|
||||
#endif
|
||||
TERN_(HAS_HOTEND_OFFSET, reset_hotend_offsets());
|
||||
|
||||
TEMPORARY_BACKLASH_CORRECTION(all_on);
|
||||
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
||||
@ -577,9 +553,7 @@ inline void calibrate_all() {
|
||||
// Do a fast and rough calibration of the toolheads
|
||||
calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNKNOWN);
|
||||
|
||||
#if ENABLED(BACKLASH_GCODE)
|
||||
calibrate_backlash(m, CALIBRATION_MEASUREMENT_UNCERTAIN);
|
||||
#endif
|
||||
TERN_(BACKLASH_GCODE, calibrate_backlash(m, CALIBRATION_MEASUREMENT_UNCERTAIN));
|
||||
|
||||
// Cycle the toolheads so the servos settle into their "natural" positions
|
||||
#if HAS_MULTI_HOTEND
|
||||
|
@ -178,9 +178,7 @@ void GcodeSuite::G76() {
|
||||
report_temps(next_temp_report);
|
||||
|
||||
// Disable leveling so it won't mess with us
|
||||
#if HAS_LEVELING
|
||||
set_bed_leveling_enabled(false);
|
||||
#endif
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(false));
|
||||
|
||||
for (;;) {
|
||||
thermalManager.setTargetBed(target_bed);
|
||||
@ -214,9 +212,7 @@ void GcodeSuite::G76() {
|
||||
|
||||
// Cleanup
|
||||
thermalManager.setTargetBed(0);
|
||||
#if HAS_LEVELING
|
||||
set_bed_leveling_enabled(true);
|
||||
#endif
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(true));
|
||||
} // do_bed_cal
|
||||
|
||||
/********************************************
|
||||
@ -240,9 +236,7 @@ void GcodeSuite::G76() {
|
||||
wait_for_temps(target_bed, target_probe, next_temp_report);
|
||||
|
||||
// Disable leveling so it won't mess with us
|
||||
#if HAS_LEVELING
|
||||
set_bed_leveling_enabled(false);
|
||||
#endif
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(false));
|
||||
|
||||
bool timeout = false;
|
||||
for (;;) {
|
||||
@ -273,9 +267,7 @@ void GcodeSuite::G76() {
|
||||
|
||||
// Cleanup
|
||||
thermalManager.setTargetBed(0);
|
||||
#if HAS_LEVELING
|
||||
set_bed_leveling_enabled(true);
|
||||
#endif
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(true));
|
||||
|
||||
SERIAL_ECHOLNPGM("Final compensation values:");
|
||||
temp_comp.print_offsets();
|
||||
|
@ -263,9 +263,7 @@ void GcodeSuite::M48() {
|
||||
restore_feedrate_and_scaling();
|
||||
|
||||
// Re-enable bed level correction if it had been on
|
||||
#if HAS_LEVELING
|
||||
set_bed_leveling_enabled(was_enabled);
|
||||
#endif
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled));
|
||||
|
||||
report_current_position();
|
||||
}
|
||||
|
Reference in New Issue
Block a user