From f423edd938dcb593b58844cd7dc3b9164d792686 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 27 Dec 2020 16:21:01 -0600 Subject: [PATCH] Add probe_switch_activated --- Marlin/src/module/endstops.cpp | 9 +++------ Marlin/src/module/endstops.h | 8 ++++++++ Marlin/src/module/probe.cpp | 2 +- buildroot/tests/STM32F103RET6_creality-tests | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 1467e1b70d..b1c7c1c585 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -465,7 +465,7 @@ void _O2 Endstops::report_states() { ES_REPORT(Z4_MAX); #endif #if BOTH(MARLIN_DEV_MODE, PROBE_ACTIVATION_SWITCH) - print_es_state(READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE, PSTR(STR_PROBE_EN)); + print_es_state(probe_switch_activated(), PSTR(STR_PROBE_EN)); #endif #if HAS_CUSTOM_PROBE_PIN print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE)); @@ -618,11 +618,8 @@ void Endstops::update() { #if HAS_BED_PROBE // When closing the gap check the enabled probe - if (true - #if ENABLED(PROBE_ACTIVATION_SWITCH) - || READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE - #endif - ) UPDATE_ENDSTOP_BIT(Z, TERN(HAS_CUSTOM_PROBE_PIN, MIN_PROBE, MIN)); + if (probe_switch_activated()) + UPDATE_ENDSTOP_BIT(Z, TERN(HAS_CUSTOM_PROBE_PIN, MIN_PROBE, MIN)); #endif #if HAS_Z_MAX && !Z_SPI_SENSORLESS diff --git a/Marlin/src/module/endstops.h b/Marlin/src/module/endstops.h index 888d25a8bd..05936a6bf3 100644 --- a/Marlin/src/module/endstops.h +++ b/Marlin/src/module/endstops.h @@ -116,6 +116,14 @@ class Endstops { ; } + static inline bool probe_switch_activated() { + return (true + #if ENABLED(PROBE_ACTIVATION_SWITCH) + && READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE + #endif + ); + } + /** * Report endstop hits to serial. Called from loop(). */ diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index d93eda1303..df014bdc28 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -519,7 +519,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { */ bool Probe::tare() { #if BOTH(PROBE_ACTIVATION_SWITCH, PROBE_TARE_ONLY_WHILE_INACTIVE) - if (READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE) { + if (endstops.probe_switch_activated()) { SERIAL_ECHOLNPGM("Cannot tare an active probe"); return true; } diff --git a/buildroot/tests/STM32F103RET6_creality-tests b/buildroot/tests/STM32F103RET6_creality-tests index cc3275741b..199bd6a9c2 100755 --- a/buildroot/tests/STM32F103RET6_creality-tests +++ b/buildroot/tests/STM32F103RET6_creality-tests @@ -23,7 +23,7 @@ opt_set SERIAL_PORT 1 opt_set MOTHERBOARD BOARD_CREALITY_V452 opt_disable NOZZLE_TO_PROBE_OFFSET opt_enable NOZZLE_AS_PROBE Z_SAFE_HOMING Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN -opt_enable PROBE_ACTIVATION_SWITCH PROBE_ACTIVATION_SWITCH_PIN PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE +opt_enable PROBE_ACTIVATION_SWITCH PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE exec_test $1 $2 "Creality V4.5.2 PROBE_ACTIVATION_SWITCH, Probe Tare" "$3" # clean up