From 8555816a11a27730c9785606c97b8412777eeba1 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Wed, 6 Jul 2016 03:56:17 +0200 Subject: [PATCH] Generalize and simplify 'triggered when stowed test` The `PROBE_IS_TRIGGERED_WHEN_STOWED_TEST` is able to detect if a probe is successfully deployed/stowed. It was part of the Allen Key probes code only. Now the function is generally available. Currently this test is compulsory for Allen Key probes to not alter the used behaviour If you want to add the test for an other type of probe simply add ``` #define PROBE_IS_TRIGGERED_WHEN_STOWED_TEST ``` to your config. --- Marlin/Conditionals.h | 4 ++ Marlin/Marlin_main.cpp | 99 ++++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h index e3c72d76f..734b644be 100644 --- a/Marlin/Conditionals.h +++ b/Marlin/Conditionals.h @@ -753,6 +753,10 @@ #define HAS_BED_PROBE (PROBE_SELECTED && PROBE_PIN_CONFIGURED) + #if ENABLED(Z_PROBE_ALLEN_KEY) + #define PROBE_IS_TRIGGERED_WHEN_STOWED_TEST + #endif + /** * Bed Probe dependencies */ diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 2aebe2fad..7fb99d6da 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1955,6 +1955,15 @@ static void clean_up_after_endstop_or_probe_move() { #if HAS_BED_PROBE + // TRIGGERED_WHEN_STOWED_TEST can easily be extended to servo probes, ... if needed. + #if ENABLED(PROBE_IS_TRIGGERED_WHEN_STOWED_TEST) + #if ENABLED(Z_MIN_PROBE_ENDSTOP) + #define _TRIGGERED_WHEN_STOWED_TEST (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING) + #else + #define _TRIGGERED_WHEN_STOWED_TEST (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) + #endif + #endif + static void deploy_z_probe() { #if ENABLED(DEBUG_LEVELING_FEATURE) @@ -1966,6 +1975,14 @@ static void clean_up_after_endstop_or_probe_move() { // Make room for probe do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW); + #ifdef _TRIGGERED_WHEN_STOWED_TEST + // If endstop is already false, the Z probe is deployed + if (_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions. + // Would a goto be less ugly? + //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity + // for a triggered when stowed manual probe. + #endif + #if ENABLED(Z_PROBE_SLED) dock_sled(false); @@ -1976,37 +1993,8 @@ static void clean_up_after_endstop_or_probe_move() { DEPLOY_Z_SERVO(); #elif ENABLED(Z_PROBE_ALLEN_KEY) - float old_feedrate = feedrate; - feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE; - - // If endstop is already false, the Z probe is deployed - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (z_probe_endstop) - #else - bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (z_min_endstop) - #endif - { - run_deploy_moves_script(); - } - - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (z_probe_endstop) - #else - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (z_min_endstop) - #endif - { - if (IsRunning()) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Z-Probe failed to engage!"); - LCD_ALERTMESSAGEPGM("Err: ZPROBE"); - } - stop(); - } + run_deploy_moves_script(); #else @@ -2014,6 +2002,19 @@ static void clean_up_after_endstop_or_probe_move() { #endif + #ifdef _TRIGGERED_WHEN_STOWED_TEST + }; // opened before the probe specific actions + + if (_TRIGGERED_WHEN_STOWED_TEST) { + if (IsRunning()) { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM("Z-Probe failed"); + LCD_ALERTMESSAGEPGM("Err: ZPROBE"); + } + stop(); + } + #endif + endstops.enable_z_probe(); } @@ -2027,7 +2028,14 @@ static void clean_up_after_endstop_or_probe_move() { // Make more room for the servo do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW); - #if ENABLED(Z_PROBE_SLED) + #ifdef _TRIGGERED_WHEN_STOWED_TEST + // If endstop is already false, the Z probe is deployed + if (!_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions. + // Would a goto be less ugly? + //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity + // for a triggered when stowed manual probe. + + #if ENABLED(Z_PROBE_SLED) dock_sled(true); @@ -2040,28 +2048,25 @@ static void clean_up_after_endstop_or_probe_move() { run_stow_moves_script(); - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (!z_probe_endstop) - #else - bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (!z_min_endstop) - #endif - { - if (IsRunning()) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Z-Probe failed to retract!"); - LCD_ALERTMESSAGEPGM("Err: ZPROBE"); - } - stop(); - } - #else // Nothing to do here. Just clear endstops.z_probe_enabled #endif + #ifdef _TRIGGERED_WHEN_STOWED_TEST + }; // opened before the probe specific actions + if (!_TRIGGERED_WHEN_STOWED_TEST) { + if (IsRunning()) { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM("Z-Probe failed!"); + LCD_ALERTMESSAGEPGM("Err: ZPROBE"); + } + stop(); + return true; + } + #endif + endstops.enable_z_probe(false); }