From 57d63f19091b1f2f1ca0a6716a849284ebe54547 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 13 Jun 2018 00:36:47 -0500 Subject: [PATCH] Extra insurance against endstop false positives --- Marlin/endstops.cpp | 27 ++++++++++++--------------- Marlin/endstops.h | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Marlin/endstops.cpp b/Marlin/endstops.cpp index 06846f9b5d97..1da463296b9f 100644 --- a/Marlin/endstops.cpp +++ b/Marlin/endstops.cpp @@ -238,7 +238,7 @@ void Endstops::not_homing() { // Enable / disable endstop z-probe checking #if HAS_BED_PROBE - void Endstops::enable_z_probe(bool onoff) { + void Endstops::enable_z_probe(const bool onoff) { z_probe_enabled = onoff; #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) @@ -412,7 +412,7 @@ void Endstops::update() { if (stepper.axis_is_moving(X_AXIS)) { if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction #if HAS_X_MIN - #if ENABLED(X_DUAL_ENDSTOPS) + #if ENABLED(X_DUAL_ENDSTOPS) && X_HOME_DIR < 0 UPDATE_ENDSTOP_BIT(X, MIN); #if HAS_X2_MIN UPDATE_ENDSTOP_BIT(X2, MIN); @@ -426,7 +426,7 @@ void Endstops::update() { } else { // +direction #if HAS_X_MAX - #if ENABLED(X_DUAL_ENDSTOPS) + #if ENABLED(X_DUAL_ENDSTOPS) && X_HOME_DIR > 0 UPDATE_ENDSTOP_BIT(X, MAX); #if HAS_X2_MAX UPDATE_ENDSTOP_BIT(X2, MAX); @@ -442,7 +442,7 @@ void Endstops::update() { if (stepper.axis_is_moving(Y_AXIS)) { if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction - #if HAS_Y_MIN + #if HAS_Y_MIN && Y_HOME_DIR < 0 #if ENABLED(Y_DUAL_ENDSTOPS) UPDATE_ENDSTOP_BIT(Y, MIN); #if HAS_Y2_MIN @@ -456,7 +456,7 @@ void Endstops::update() { #endif } else { // +direction - #if HAS_Y_MAX + #if HAS_Y_MAX && Y_HOME_DIR > 0 #if ENABLED(Y_DUAL_ENDSTOPS) UPDATE_ENDSTOP_BIT(Y, MAX); #if HAS_Y2_MAX @@ -474,19 +474,17 @@ void Endstops::update() { if (stepper.axis_is_moving(Z_AXIS)) { if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up. #if HAS_Z_MIN - #if ENABLED(Z_DUAL_ENDSTOPS) + #if ENABLED(Z_DUAL_ENDSTOPS) && Z_HOME_DIR < 0 UPDATE_ENDSTOP_BIT(Z, MIN); #if HAS_Z2_MIN UPDATE_ENDSTOP_BIT(Z2, MIN); #else COPY_BIT(live_state, Z_MIN, Z2_MIN); #endif - #else - #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) - if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN); - #else - UPDATE_ENDSTOP_BIT(Z, MIN); - #endif + #elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN); + #elif Z_HOME_DIR < 0 + UPDATE_ENDSTOP_BIT(Z, MIN); #endif #endif @@ -496,7 +494,7 @@ void Endstops::update() { #endif } else { // Z +direction. Gantry up, bed down. - #if HAS_Z_MAX + #if HAS_Z_MAX && Z_HOME_DIR > 0 // Check both Z dual endstops #if ENABLED(Z_DUAL_ENDSTOPS) UPDATE_ENDSTOP_BIT(Z, MAX); @@ -505,9 +503,8 @@ void Endstops::update() { #else COPY_BIT(live_state, Z_MAX, Z2_MAX); #endif - // If this pin is not hijacked for the bed probe - // then it belongs to the Z endstop #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN + // If this pin isn't the bed probe it's the Z endstop UPDATE_ENDSTOP_BIT(Z, MAX); #endif #endif diff --git a/Marlin/endstops.h b/Marlin/endstops.h index a784d613fad9..8cdb1e6a8d6a 100644 --- a/Marlin/endstops.h +++ b/Marlin/endstops.h @@ -142,7 +142,7 @@ class Endstops { // Enable / disable endstop z-probe checking #if HAS_BED_PROBE static volatile bool z_probe_enabled; - static void enable_z_probe(bool onoff=true); + static void enable_z_probe(const bool onoff=true); #endif // Debugging of endstops