From 307721dd536d51c54f8c47f3e1bede83c485d88f Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sun, 16 Apr 2023 15:11:39 +1000 Subject: [PATCH 01/12] G38 added check for USE_ZMIN_PLUG --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 6719925f15fa..d2d68812eca0 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -920,7 +920,7 @@ void Endstops::update() { #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } #endif - #if HAS_Z_AXIS + #if HAS_Z_AXIS && USE_ZMIN_PLUG else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } #endif G38_did_trigger = true; From 49c831d227a70b95ad5f6e70261641139814b7fb Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sun, 16 Apr 2023 16:00:22 +1000 Subject: [PATCH 02/12] fix for "operator '&&' has no right operand" --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index d2d68812eca0..4fa97dd6f814 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -920,7 +920,7 @@ void Endstops::update() { #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } #endif - #if HAS_Z_AXIS && USE_ZMIN_PLUG + #if (HAS_Z_AXIS && USE_ZMIN_PLUG) else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } #endif G38_did_trigger = true; From 8aeaf784fd06f5d126387c045f835145e77e1a89 Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sun, 16 Apr 2023 16:26:27 +1000 Subject: [PATCH 03/12] macro fix for "operator '&&' has no right operand" --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 4fa97dd6f814..925db04ddfff 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -920,7 +920,7 @@ void Endstops::update() { #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } #endif - #if (HAS_Z_AXIS && USE_ZMIN_PLUG) + #if BOTH(HAS_Z_AXIS, USE_ZMIN_PLUG) else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } #endif G38_did_trigger = true; From 60363644cf1c9d4690996fd29bbef39f6f3ffdfd Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sun, 16 Apr 2023 16:35:32 +1000 Subject: [PATCH 04/12] use HAS_Z_MIN instead since it's more broad --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 925db04ddfff..7e525d72b198 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -920,7 +920,7 @@ void Endstops::update() { #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } #endif - #if BOTH(HAS_Z_AXIS, USE_ZMIN_PLUG) + #if BOTH(HAS_Z_AXIS, HAS_Z_MIN) else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } #endif G38_did_trigger = true; From b010af5c5ab5d8db3eb2b96aca486c178a36bc93 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 20:40:52 -0500 Subject: [PATCH 05/12] HAS_Z_MIN is only set if HAS_Z_AXIS --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 7e525d72b198..17fd35e89d6e 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -920,7 +920,7 @@ void Endstops::update() { #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } #endif - #if BOTH(HAS_Z_AXIS, HAS_Z_MIN) + #if HAS_Z_MIN else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } #endif G38_did_trigger = true; From 8eff6dd6d4a147bfb8ce67f3b7a5c5aefa552cf6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 20:44:31 -0500 Subject: [PATCH 06/12] compare to hit instead of open --- Marlin/src/module/endstops.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 17fd35e89d6e..c3804a9ec974 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -913,9 +913,8 @@ void Endstops::update() { #endif #if HAS_G38_PROBE // TODO (DerAndere): Add support for HAS_I_AXIS - #define _G38_OPEN_STATE TERN(G38_PROBE_AWAY, (G38_move >= 4), LOW) // For G38 moves check the probe's pin for ALL movement - if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) != _G38_OPEN_STATE) { + if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, TERN(X_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(X_AXIS); } #if HAS_Y_AXIS else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } From 84316b81d5641fff13adc850a06c657967f064c3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 21:08:50 -0500 Subject: [PATCH 07/12] Update endstops_trigsteps for all moving axes --- Marlin/src/module/endstops.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index c3804a9ec974..b4193aa83f0e 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -915,14 +915,22 @@ void Endstops::update() { #if HAS_G38_PROBE // TODO (DerAndere): Add support for HAS_I_AXIS // For G38 moves check the probe's pin for ALL movement if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { - if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, TERN(X_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(X_AXIS); } + G38_did_trigger = true; + #if HAS_X_AXIS + const bool xmoving = stepper.axis_is_moving(X_AXIS); + #endif #if HAS_Y_AXIS - else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); } + const bool ymoving = stepper.axis_is_moving(Y_AXIS); #endif #if HAS_Z_MIN - else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); } + const bool zmoving = stepper.axis_is_moving(Z_AXIS); #endif - G38_did_trigger = true; + TERN_(HAS_X_AXIS, if (xmoving) _ENDSTOP_HIT(X, TERN(X_HOME_TO_MIN, MIN, MAX))); + TERN_(HAS_Y_AXIS, if (ymoving) _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX))); + TERN_(HAS_Z_MIN, if (zmoving) _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX))); + TERN_(HAS_X_AXIS, if (xmoving) planner.endstop_triggered(X_AXIS)); + TERN_(HAS_Y_AXIS, if (ymoving) planner.endstop_triggered(Y_AXIS)); + TERN_(HAS_Z_MIN, if (zmoving) planner.endstop_triggered(Z_AXIS)); } #endif From 302fc17b5c913cb78e602cbc70ccce021d8c6122 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 21:19:06 -0500 Subject: [PATCH 08/12] just use _ENDSTOP_HIT(Z, ENDSTOP) --- Marlin/src/module/endstops.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index b4193aa83f0e..74fa897eb7ce 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -922,15 +922,18 @@ void Endstops::update() { #if HAS_Y_AXIS const bool ymoving = stepper.axis_is_moving(Y_AXIS); #endif - #if HAS_Z_MIN + #if HAS_Z_AXIS const bool zmoving = stepper.axis_is_moving(Z_AXIS); #endif - TERN_(HAS_X_AXIS, if (xmoving) _ENDSTOP_HIT(X, TERN(X_HOME_TO_MIN, MIN, MAX))); - TERN_(HAS_Y_AXIS, if (ymoving) _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX))); - TERN_(HAS_Z_MIN, if (zmoving) _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX))); - TERN_(HAS_X_AXIS, if (xmoving) planner.endstop_triggered(X_AXIS)); - TERN_(HAS_Y_AXIS, if (ymoving) planner.endstop_triggered(Y_AXIS)); - TERN_(HAS_Z_MIN, if (zmoving) planner.endstop_triggered(Z_AXIS)); + #if HAS_X_AXIS + if (xmoving) { _ENDSTOP_HIT(X, ENDSTOP); planner.endstop_triggered(X_AXIS); } + #endif + #if HAS_Y_AXIS + if (ymoving) { _ENDSTOP_HIT(Y, ENDSTOP); planner.endstop_triggered(Y_AXIS); } + #endif + #if HAS_Z_AXIS + if (zmoving) { _ENDSTOP_HIT(Z, ENDSTOP); planner.endstop_triggered(Z_AXIS); } + #endif } #endif From 6939bcb68d9968d41cbc2feea4f197877d17aba6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 21:32:37 -0500 Subject: [PATCH 09/12] support up to 9 axes --- Marlin/src/module/endstops.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 74fa897eb7ce..ccad00062e2a 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -916,24 +916,10 @@ void Endstops::update() { // For G38 moves check the probe's pin for ALL movement if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { G38_did_trigger = true; - #if HAS_X_AXIS - const bool xmoving = stepper.axis_is_moving(X_AXIS); - #endif - #if HAS_Y_AXIS - const bool ymoving = stepper.axis_is_moving(Y_AXIS); - #endif - #if HAS_Z_AXIS - const bool zmoving = stepper.axis_is_moving(Z_AXIS); - #endif - #if HAS_X_AXIS - if (xmoving) { _ENDSTOP_HIT(X, ENDSTOP); planner.endstop_triggered(X_AXIS); } - #endif - #if HAS_Y_AXIS - if (ymoving) { _ENDSTOP_HIT(Y, ENDSTOP); planner.endstop_triggered(Y_AXIS); } - #endif - #if HAS_Z_AXIS - if (zmoving) { _ENDSTOP_HIT(Z, ENDSTOP); planner.endstop_triggered(Z_AXIS); } - #endif + #define _G38_SET(Q) | (stepper.axis_is_moving(_AXIS(Q)) << _AXIS(Q)) + #define _G38_RESP(Q) if (moving[_AXIS(Q)]) { _ENDSTOP_HIT(Q, ENDSTOP); planner.endstop_triggered(_AXIS(Q)); } + const Flags moving = { value_t(NUM_AXES)(0 MAIN_AXIS_MAP(_G38_SET)) }; + MAIN_AXIS_MAP(_G38_RESP); } #endif From 0a02f62efb780f96aefd14723cc3a71f83159d0b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 18 Apr 2023 22:10:35 -0500 Subject: [PATCH 10/12] update some home pos --- Marlin/src/inc/Conditionals_post.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 4bbb43a2169d..f12865f6faf9 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -341,21 +341,21 @@ #ifdef MANUAL_U_HOME_POS #define U_HOME_POS MANUAL_U_HOME_POS #else - #define U_HOME_POS (U_HOME_DIR < 0 ? U_MIN_POS : U_MAX_POS) + #define U_HOME_POS TERN(U_HOME_TO_MIN, U_MIN_POS, U_MAX_POS) #endif #endif #if HAS_V_AXIS #ifdef MANUAL_V_HOME_POS #define V_HOME_POS MANUAL_V_HOME_POS #else - #define V_HOME_POS (V_HOME_DIR < 0 ? V_MIN_POS : V_MAX_POS) + #define V_HOME_POS TERN(V_HOME_TO_MIN, V_MIN_POS, V_MAX_POS) #endif #endif #if HAS_W_AXIS #ifdef MANUAL_W_HOME_POS #define W_HOME_POS MANUAL_W_HOME_POS #else - #define W_HOME_POS (W_HOME_DIR < 0 ? W_MIN_POS : W_MAX_POS) + #define W_HOME_POS TERN(W_HOME_TO_MIN, W_MIN_POS, W_MAX_POS) #endif #endif From ab1e136bc1c8cea061c55742cd9491ba0c288f7f Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Wed, 19 Apr 2023 17:59:40 +1000 Subject: [PATCH 11/12] spelling mistake :) --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index ccad00062e2a..e14d10d0ab0c 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -913,7 +913,7 @@ void Endstops::update() { #endif #if HAS_G38_PROBE // TODO (DerAndere): Add support for HAS_I_AXIS - // For G38 moves check the probe's pin for ALL movement + // For G38 moves check the probes pin for ALL movement if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { G38_did_trigger = true; #define _G38_SET(Q) | (stepper.axis_is_moving(_AXIS(Q)) << _AXIS(Q)) From aa16460c6474e6deb012a4306c26274df3c6921e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 19 Apr 2023 15:53:20 -0500 Subject: [PATCH 12/12] not a spelling mistake --- Marlin/src/module/endstops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index e14d10d0ab0c..ccad00062e2a 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -913,7 +913,7 @@ void Endstops::update() { #endif #if HAS_G38_PROBE // TODO (DerAndere): Add support for HAS_I_AXIS - // For G38 moves check the probes pin for ALL movement + // For G38 moves check the probe's pin for ALL movement if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) == TERN1(G38_PROBE_AWAY, (G38_move < 4))) { G38_did_trigger = true; #define _G38_SET(Q) | (stepper.axis_is_moving(_AXIS(Q)) << _AXIS(Q))