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

@ -165,9 +165,7 @@ int8_t g26_prime_flag;
bool user_canceled() {
if (!ui.button_pressed()) return false; // Return if the button isn't pressed
ui.set_status_P(GET_TEXT(MSG_G26_CANCELED), 99);
#if HAS_LCD_MENU
ui.quick_feedback();
#endif
TERN_(HAS_LCD_MENU, ui.quick_feedback());
ui.wait_for_release();
return true;
}
@ -301,9 +299,7 @@ inline bool look_for_lines_to_connect() {
GRID_LOOP(i, j) {
#if HAS_LCD_MENU
if (user_canceled()) return true;
#endif
if (TERN0(HAS_LCD_MENU, user_canceled())) return true;
if (i < (GRID_MAX_POINTS_X)) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
// Already a half circle at the edge of the bed.
@ -364,9 +360,7 @@ inline bool turn_on_heaters() {
#if HAS_SPI_LCD
ui.set_status_P(GET_TEXT(MSG_G26_HEATING_BED), 99);
ui.quick_feedback();
#if HAS_LCD_MENU
ui.capture();
#endif
TERN_(HAS_LCD_MENU, ui.capture());
#endif
thermalManager.setTargetBed(g26_bed_temp);
@ -390,11 +384,10 @@ inline bool turn_on_heaters() {
// Wait for the temperature to stabilize
if (!thermalManager.wait_for_hotend(active_extruder, true
#if G26_CLICK_CAN_CANCEL
, true
#endif
)
) return G26_ERR;
#if G26_CLICK_CAN_CANCEL
, true
#endif
)) return G26_ERR;
#if HAS_SPI_LCD
ui.reset_status();
@ -665,9 +658,7 @@ void GcodeSuite::G26() {
move_to(destination, 0.0);
move_to(destination, g26_ooze_amount);
#if HAS_LCD_MENU
ui.capture();
#endif
TERN_(HAS_LCD_MENU, ui.capture());
#if DISABLED(ARC_SUPPORT)
@ -762,9 +753,7 @@ void GcodeSuite::G26() {
feedrate_mm_s = old_feedrate;
destination = current_position;
#if HAS_LCD_MENU
if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif
if (TERN0(HAS_LCD_MENU, user_canceled())) goto LEAVE; // Check if the user wants to stop the Mesh Validation
#else // !ARC_SUPPORT
@ -788,9 +777,7 @@ void GcodeSuite::G26() {
for (int8_t ind = start_ind; ind <= end_ind; ind++) {
#if HAS_LCD_MENU
if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif
if (TERN0(HAS_LCD_MENU, user_canceled())) goto LEAVE; // Check if the user wants to stop the Mesh Validation
xyz_float_t p = { circle.x + _COS(ind ), circle.y + _SIN(ind ), g26_layer_height },
q = { circle.x + _COS(ind + 1), circle.y + _SIN(ind + 1), g26_layer_height };
@ -833,14 +820,10 @@ void GcodeSuite::G26() {
planner.calculate_volumetric_multipliers();
#endif
#if HAS_LCD_MENU
ui.release(); // Give back control of the LCD
#endif
TERN_(HAS_LCD_MENU, ui.release()); // Give back control of the LCD
if (!g26_keep_heaters_on) {
#if HAS_HEATED_BED
thermalManager.setTargetBed(0);
#endif
TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(0));
thermalManager.setTargetHotend(active_extruder, 0);
}
}

View File

@ -73,9 +73,7 @@ void GcodeSuite::M420() {
#endif
GRID_LOOP(x, y) {
Z_VALUES(x, y) = 0.001 * random(-200, 200);
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
}
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
SERIAL_ECHOPAIR(" (", x_min);
@ -178,13 +176,9 @@ void GcodeSuite::M420() {
// Subtract the mean from all values
GRID_LOOP(x, y) {
Z_VALUES(x, y) -= zmean;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
}
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
bed_level_virt_interpolate();
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
}
#endif
@ -206,9 +200,7 @@ void GcodeSuite::M420() {
if (leveling_is_valid()) {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
print_bilinear_leveling_grid();
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
print_bilinear_leveling_grid_virt();
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, print_bilinear_leveling_grid_virt());
#elif ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOLNPGM("Mesh Bed Level data:");
mbl.report_mesh();

View File

@ -283,9 +283,7 @@ G29_TYPE GcodeSuite::G29() {
*/
if (!g29_in_progress) {
#if HAS_MULTI_HOTEND
if (active_extruder != 0) tool_change(0);
#endif
TERN_(HAS_MULTI_HOTEND, if (active_extruder) tool_change(0));
#if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
abl_probe_index = -1;
@ -322,12 +320,8 @@ G29_TYPE GcodeSuite::G29() {
if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
set_bed_leveling_enabled(false);
z_values[i][j] = rz;
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
bed_level_virt_interpolate();
#endif
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(i, j, rz);
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
set_bed_leveling_enabled(abl_should_enable);
if (abl_should_enable) report_current_position();
}
@ -492,14 +486,10 @@ G29_TYPE GcodeSuite::G29() {
// Abort current G29 procedure, go back to idle state
if (seenA && g29_in_progress) {
SERIAL_ECHOLNPGM("Manual G29 aborted");
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = saved_soft_endstops_state;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
set_bed_leveling_enabled(abl_should_enable);
g29_in_progress = false;
#if ENABLED(LCD_BED_LEVELING)
ui.wait_for_move = false;
#endif
TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
}
// Query G29 status
@ -517,9 +507,7 @@ G29_TYPE GcodeSuite::G29() {
if (abl_probe_index == 0) {
// For the initial G29 S2 save software endstop state
#if HAS_SOFTWARE_ENDSTOPS
saved_soft_endstops_state = soft_endstops_enabled;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, saved_soft_endstops_state = soft_endstops_enabled);
// Move close to the bed before the first point
do_blocking_move_to_z(0);
}
@ -551,9 +539,7 @@ G29_TYPE GcodeSuite::G29() {
const float newz = measured_z + zoffset;
z_values[meshCount.x][meshCount.y] = newz;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(meshCount, newz);
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(meshCount, newz));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_P(PSTR("Save X"), meshCount.x, SP_Y_STR, meshCount.y, SP_Z_STR, measured_z + zoffset);
@ -580,9 +566,7 @@ G29_TYPE GcodeSuite::G29() {
probePos = probe_position_lf + gridSpacing * meshCount.asFloat();
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[meshCount.x][meshCount.y] = abl_probe_index;
#endif
TERN_(AUTO_BED_LEVELING_LINEAR, indexIntoAB[meshCount.x][meshCount.y] = abl_probe_index);
// Keep looping till a reachable point is found
if (position_is_reachable(probePos)) break;
@ -606,9 +590,7 @@ G29_TYPE GcodeSuite::G29() {
SERIAL_ECHOLNPGM("Grid probing done.");
// Re-enable software endstops, if needed
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = saved_soft_endstops_state;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
}
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
@ -629,9 +611,7 @@ G29_TYPE GcodeSuite::G29() {
SERIAL_ECHOLNPGM("3-point probing done.");
// Re-enable software endstops, if needed
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = saved_soft_endstops_state;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
if (!dryrun) {
vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
@ -688,9 +668,7 @@ G29_TYPE GcodeSuite::G29() {
probePos = probe_position_lf + gridSpacing * meshCount.asFloat();
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[meshCount.x][meshCount.y] = ++abl_probe_index; // 0...
#endif
TERN_(AUTO_BED_LEVELING_LINEAR, indexIntoAB[meshCount.x][meshCount.y] = ++abl_probe_index); // 0...
#if IS_KINEMATIC
// Avoid probing outside the round or hexagonal area
@ -698,9 +676,7 @@ G29_TYPE GcodeSuite::G29() {
#endif
if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), ".");
#if HAS_DISPLAY
ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS));
#endif
TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS)));
measured_z = faux ? 0.001f * random(-100, 101) : probe.probe_at_point(probePos, raise_after, verbose_level);
@ -712,9 +688,7 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(PROBE_TEMP_COMPENSATION)
temp_comp.compensate_measurement(TSI_BED, thermalManager.degBed(), measured_z);
temp_comp.compensate_measurement(TSI_PROBE, thermalManager.degProbe(), measured_z);
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
temp_comp.compensate_measurement(TSI_EXT, thermalManager.degHotend(), measured_z);
#endif
TERN_(USE_TEMP_EXT_COMPENSATION, temp_comp.compensate_measurement(TSI_EXT, thermalManager.degHotend(), measured_z));
#endif
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
@ -730,9 +704,7 @@ G29_TYPE GcodeSuite::G29() {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
z_values[meshCount.x][meshCount.y] = measured_z + zoffset;
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(meshCount, z_values[meshCount.x][meshCount.y]);
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(meshCount, z_values[meshCount.x][meshCount.y]));
#endif
@ -748,9 +720,7 @@ G29_TYPE GcodeSuite::G29() {
LOOP_L_N(i, 3) {
if (verbose_level) SERIAL_ECHOLNPAIR("Probing point ", int(i), "/3.");
#if HAS_DISPLAY
ui.status_printf_P(0, PSTR(S_FMT " %i/3"), GET_TEXT(MSG_PROBING_MESH), int(i));
#endif
TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/3"), GET_TEXT(MSG_PROBING_MESH), int(i)));
// Retain the last probe position
probePos = points[i];
@ -773,9 +743,7 @@ G29_TYPE GcodeSuite::G29() {
#endif // AUTO_BED_LEVELING_3POINT
#if HAS_DISPLAY
ui.reset_status();
#endif
TERN_(HAS_DISPLAY, ui.reset_status());
// Stow the probe. No raise for FIX_MOUNTED_PROBE.
if (probe.stow()) {
@ -799,9 +767,7 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(PROBE_MANUALLY)
g29_in_progress = false;
#if ENABLED(LCD_BED_LEVELING)
ui.wait_for_move = false;
#endif
TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
#endif
// Calculate leveling, print reports, correct the position
@ -813,9 +779,7 @@ G29_TYPE GcodeSuite::G29() {
refresh_bed_level();
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
print_bilinear_leveling_grid_virt();
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, print_bilinear_leveling_grid_virt());
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)

View File

@ -55,12 +55,8 @@ void GcodeSuite::M421() {
SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
else {
z_values[ix][iy] = parser.value_linear_units() + (hasQ ? z_values[ix][iy] : 0);
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
bed_level_virt_interpolate();
#endif
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]);
#endif
TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]));
}
}

View File

@ -62,9 +62,7 @@ inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM("
void GcodeSuite::G29() {
static int mbl_probe_index = -1;
#if HAS_SOFTWARE_ENDSTOPS
static bool saved_soft_endstops_state;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state);
MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
if (!WITHIN(state, 0, 5)) {
@ -111,9 +109,7 @@ void GcodeSuite::G29() {
else {
// Save Z for the previous mesh position
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = saved_soft_endstops_state;
#endif
TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
}
// If there's another point to sample, move there with optional lift.
if (mbl_probe_index < GRID_MAX_POINTS) {
@ -147,9 +143,7 @@ void GcodeSuite::G29() {
planner.synchronize();
#endif
#if ENABLED(LCD_BED_LEVELING)
ui.wait_for_move = false;
#endif
TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
}
break;
@ -178,9 +172,7 @@ void GcodeSuite::G29() {
if (parser.seenval('Z')) {
mbl.z_values[ix][iy] = parser.value_linear_units();
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]);
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]));
}
else
return echo_not_entered('Z');

View File

@ -63,9 +63,7 @@ void GcodeSuite::M421() {
else {
float &zval = ubl.z_values[ij.x][ij.y];
zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0);
#if ENABLED(EXTENSIBLE_UI)
ExtUI::onMeshUpdate(ij.x, ij.y, zval);
#endif
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval));
}
}