Browse Source

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.
AnHardt 8 years ago
parent
commit
8555816a11
2 changed files with 56 additions and 47 deletions
  1. 4
    0
      Marlin/Conditionals.h
  2. 52
    47
      Marlin/Marlin_main.cpp

+ 4
- 0
Marlin/Conditionals.h View File

@@ -753,6 +753,10 @@
753 753
 
754 754
   #define HAS_BED_PROBE (PROBE_SELECTED && PROBE_PIN_CONFIGURED)
755 755
 
756
+  #if ENABLED(Z_PROBE_ALLEN_KEY)
757
+    #define PROBE_IS_TRIGGERED_WHEN_STOWED_TEST
758
+  #endif
759
+
756 760
   /**
757 761
    * Bed Probe dependencies
758 762
    */

+ 52
- 47
Marlin/Marlin_main.cpp View File

@@ -1955,6 +1955,15 @@ static void clean_up_after_endstop_or_probe_move() {
1955 1955
 
1956 1956
 #if HAS_BED_PROBE
1957 1957
 
1958
+ // TRIGGERED_WHEN_STOWED_TEST can easily be extended to servo probes, ... if needed.
1959
+  #if ENABLED(PROBE_IS_TRIGGERED_WHEN_STOWED_TEST)
1960
+    #if ENABLED(Z_MIN_PROBE_ENDSTOP)
1961
+      #define _TRIGGERED_WHEN_STOWED_TEST (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING)
1962
+    #else
1963
+      #define _TRIGGERED_WHEN_STOWED_TEST (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)
1964
+    #endif
1965
+  #endif
1966
+
1958 1967
   static void deploy_z_probe() {
1959 1968
 
1960 1969
     #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -1966,6 +1975,14 @@ static void clean_up_after_endstop_or_probe_move() {
1966 1975
     // Make room for probe
1967 1976
     do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW);
1968 1977
 
1978
+    #ifdef _TRIGGERED_WHEN_STOWED_TEST
1979
+      // If endstop is already false, the Z probe is deployed
1980
+      if (_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions.
1981
+                                        // Would a goto be less ugly?
1982
+      //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity
1983
+      // for a triggered when stowed manual probe.
1984
+    #endif
1985
+
1969 1986
     #if ENABLED(Z_PROBE_SLED)
1970 1987
 
1971 1988
       dock_sled(false);
@@ -1976,37 +1993,8 @@ static void clean_up_after_endstop_or_probe_move() {
1976 1993
       DEPLOY_Z_SERVO();
1977 1994
 
1978 1995
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1979
-      float old_feedrate = feedrate;
1980
-
1981
-      feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE;
1982
-
1983
-      // If endstop is already false, the Z probe is deployed
1984
-      #if ENABLED(Z_MIN_PROBE_ENDSTOP)
1985
-        bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING);
1986
-        if (z_probe_endstop)
1987
-      #else
1988
-        bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
1989
-        if (z_min_endstop)
1990
-      #endif
1991
-        {
1992
-          run_deploy_moves_script();
1993
-        }
1994 1996
 
1995
-      #if ENABLED(Z_MIN_PROBE_ENDSTOP)
1996
-        z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING);
1997
-        if (z_probe_endstop)
1998
-      #else
1999
-        z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
2000
-        if (z_min_endstop)
2001
-      #endif
2002
-        {
2003
-          if (IsRunning()) {
2004
-            SERIAL_ERROR_START;
2005
-            SERIAL_ERRORLNPGM("Z-Probe failed to engage!");
2006
-            LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2007
-          }
2008
-          stop();
2009
-        }
1997
+      run_deploy_moves_script();
2010 1998
 
2011 1999
     #else
2012 2000
 
@@ -2014,6 +2002,19 @@ static void clean_up_after_endstop_or_probe_move() {
2014 2002
 
2015 2003
     #endif
2016 2004
 
2005
+    #ifdef _TRIGGERED_WHEN_STOWED_TEST
2006
+      }; // opened before the probe specific actions
2007
+
2008
+      if (_TRIGGERED_WHEN_STOWED_TEST) {
2009
+        if (IsRunning()) {
2010
+          SERIAL_ERROR_START;
2011
+          SERIAL_ERRORLNPGM("Z-Probe failed");
2012
+          LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2013
+        }
2014
+        stop();
2015
+      }
2016
+    #endif
2017
+
2017 2018
     endstops.enable_z_probe();
2018 2019
   }
2019 2020
 
@@ -2027,7 +2028,14 @@ static void clean_up_after_endstop_or_probe_move() {
2027 2028
     // Make more room for the servo
2028 2029
     do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW);
2029 2030
 
2030
-    #if ENABLED(Z_PROBE_SLED)
2031
+    #ifdef _TRIGGERED_WHEN_STOWED_TEST
2032
+      // If endstop is already false, the Z probe is deployed
2033
+      if (!_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions.
2034
+                                        // Would a goto be less ugly?
2035
+      //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity
2036
+      // for a triggered when stowed manual probe.
2037
+
2038
+      #if ENABLED(Z_PROBE_SLED)
2031 2039
 
2032 2040
       dock_sled(true);
2033 2041
 
@@ -2040,28 +2048,25 @@ static void clean_up_after_endstop_or_probe_move() {
2040 2048
 
2041 2049
       run_stow_moves_script();
2042 2050
 
2043
-      #if ENABLED(Z_MIN_PROBE_ENDSTOP)
2044
-        bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING);
2045
-        if (!z_probe_endstop)
2046
-      #else
2047
-        bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
2048
-        if (!z_min_endstop)
2049
-      #endif
2050
-        {
2051
-          if (IsRunning()) {
2052
-            SERIAL_ERROR_START;
2053
-            SERIAL_ERRORLNPGM("Z-Probe failed to retract!");
2054
-            LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2055
-          }
2056
-          stop();
2057
-        }
2058
-
2059 2051
     #else
2060 2052
 
2061 2053
       // Nothing to do here. Just clear endstops.z_probe_enabled
2062 2054
 
2063 2055
     #endif
2064 2056
 
2057
+    #ifdef _TRIGGERED_WHEN_STOWED_TEST
2058
+      }; // opened before the probe specific actions
2059
+      if (!_TRIGGERED_WHEN_STOWED_TEST) {
2060
+        if (IsRunning()) {
2061
+          SERIAL_ERROR_START;
2062
+          SERIAL_ERRORLNPGM("Z-Probe failed!");
2063
+          LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2064
+        }
2065
+        stop();
2066
+        return true;
2067
+      }
2068
+    #endif
2069
+
2065 2070
     endstops.enable_z_probe(false);
2066 2071
   }
2067 2072
 

Loading…
Cancel
Save