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

@ -276,27 +276,17 @@ void Endstops::init() {
#endif
#endif
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
setup_endstop_interrupts();
#endif
TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());
// Enable endstops
enable_globally(
#if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
true
#else
false
#endif
);
enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
} // Endstops::init
// Called at ~1KHz from Temperature ISR: Poll endstop state if required
void Endstops::poll() {
#if ENABLED(PINS_DEBUGGING)
run_monitor(); // report changes in endstop status
#endif
TERN_(PINS_DEBUGGING, run_monitor()); // Report changes in endstop status
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE)
update();
@ -341,14 +331,9 @@ void Endstops::not_homing() {
void Endstops::resync() {
if (!abort_enabled()) return; // If endstops/probes are disabled the loop below can hang
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
update();
#else
safe_delay(2); // Wait for Temperature ISR to run at least once (runs at 1KHz)
#endif
#if ENDSTOP_NOISE_THRESHOLD
while (endstop_poll_count) safe_delay(1);
#endif
// Wait for Temperature ISR to run at least once (runs at 1KHz)
TERN(ENDSTOP_INTERRUPTS_FEATURE, update(), safe_delay(2));
while (TERN0(ENDSTOP_NOISE_THRESHOLD, endstop_poll_count)) safe_delay(1);
}
#if ENABLED(PINS_DEBUGGING)
@ -397,9 +382,7 @@ void Endstops::event_handler() {
#endif
SERIAL_EOL();
#if HAS_SPI_LCD
ui.status_printf_P(0, PSTR(S_FMT " %c %c %c %c"), GET_TEXT(MSG_LCD_ENDSTOPS), chrX, chrY, chrZ, chrP);
#endif
TERN_(HAS_SPI_LCD, ui.status_printf_P(0, PSTR(S_FMT " %c %c %c %c"), GET_TEXT(MSG_LCD_ENDSTOPS), chrX, chrY, chrZ, chrP));
#if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
if (planner.abort_on_endstop_hit) {
@ -420,9 +403,7 @@ static void print_es_state(const bool is_hit, PGM_P const label=nullptr) {
}
void _O2 Endstops::report_states() {
#if ENABLED(BLTOUCH)
bltouch._set_SW_mode();
#endif
TERN_(BLTOUCH, bltouch._set_SW_mode());
SERIAL_ECHOLNPGM(STR_M119_REPORT);
#define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, PSTR(STR_##S))
#if HAS_X_MIN
@ -494,13 +475,9 @@ void _O2 Endstops::report_states() {
#undef _CASE_RUNOUT
#endif
#endif
#if ENABLED(BLTOUCH)
bltouch._reset_SW_mode();
#endif
#if ENABLED(JOYSTICK_DEBUG)
joystick.report();
#endif
TERN_(BLTOUCH, bltouch._reset_SW_mode());
TERN_(JOYSTICK_DEBUG, joystick.report());
} // Endstops::report_states
@ -796,12 +773,8 @@ void Endstops::update() {
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
#if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
if (true
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
&& z_probe_enabled
#elif HAS_CUSTOM_PROBE_PIN
&& !z_probe_enabled
#endif
if ( TERN1(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, z_probe_enabled)
&& TERN1(HAS_CUSTOM_PROBE_PIN, !z_probe_enabled)
) PROCESS_ENDSTOP_Z(MIN);
#endif
@ -852,15 +825,9 @@ void Endstops::update() {
}
void Endstops::clear_endstop_state() {
#if X_SPI_SENSORLESS
CBI(live_state, X_STOP);
#endif
#if Y_SPI_SENSORLESS
CBI(live_state, Y_STOP);
#endif
#if Z_SPI_SENSORLESS
CBI(live_state, Z_STOP);
#endif
TERN_(X_SPI_SENSORLESS, CBI(live_state, X_STOP));
TERN_(Y_SPI_SENSORLESS, CBI(live_state, Y_STOP));
TERN_(Z_SPI_SENSORLESS, CBI(live_state, Z_STOP));
}
#endif // SPI_ENDSTOPS