Browse Source

Simplify `homeaxis` with some macros

Scott Lahteine 8 years ago
parent
commit
bc86ee0271
1 changed files with 42 additions and 45 deletions
  1. 42
    45
      Marlin/Marlin_main.cpp

+ 42
- 45
Marlin/Marlin_main.cpp View File

@@ -1999,24 +1999,33 @@ static void homeaxis(AxisEnum axis) {
1999 1999
     sync_plan_position();
2000 2000
 
2001 2001
     #if ENABLED(Z_PROBE_SLED)
2002
-      // Get Probe
2003
-      if (axis == Z_AXIS) {
2004
-        if (axis_home_dir < 0) dock_sled(false);
2005
-      }
2002
+      #define _Z_SERVO_TEST       (axis != Z_AXIS)      // deploy Z, servo.move XY
2003
+      #define _Z_PROBE_SUBTEST    false                 // Z will never be invoked
2004
+      #define _Z_DEPLOY           (dock_sled(false))
2005
+      #define _Z_STOW             (dock_sled(true))
2006 2006
     #elif SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
2007
-
2008
-      // Deploy a Z probe if there is one, and homing towards the bed
2009
-      if (axis == Z_AXIS) {
2010
-        if (axis_home_dir < 0) deploy_z_probe();
2011
-      }
2012
-
2007
+      #define _Z_SERVO_TEST       (axis != Z_AXIS)      // servo.move XY
2008
+      #define _Z_PROBE_SUBTEST    false                 // Z will never be invoked
2009
+      #define _Z_DEPLOY           (deploy_z_probe())
2010
+      #define _Z_STOW             (stow_z_probe())
2011
+    #elif HAS_SERVO_ENDSTOPS
2012
+      #define _Z_SERVO_TEST       true                  // servo.move X, Y, Z
2013
+      #define _Z_PROBE_SUBTEST    (axis == Z_AXIS)      // Z is a probe
2013 2014
     #endif
2014 2015
 
2016
+    if (axis == Z_AXIS) {
2017
+      // If there's a Z probe that needs deployment...
2018
+      #if ENABLED(Z_PROBE_SLED) || SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
2019
+        // ...and homing Z towards the bed? Deploy it.
2020
+        if (axis_home_dir < 0) _Z_DEPLOY;
2021
+      #endif
2022
+    }
2023
+
2015 2024
     #if HAS_SERVO_ENDSTOPS
2016
-      // Engage Servo endstop if enabled
2017
-      if (axis != Z_AXIS && servo_endstop_id[axis] >= 0) {
2025
+      // Engage an X or Y Servo endstop if enabled
2026
+      if (_Z_SERVO_TEST && servo_endstop_id[axis] >= 0) {
2018 2027
         servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][0]);
2019
-        z_probe_is_active = true;
2028
+        if (_Z_PROBE_SUBTEST) z_probe_is_active = true;
2020 2029
       }
2021 2030
     #endif
2022 2031
 
@@ -2145,43 +2154,31 @@ static void homeaxis(AxisEnum axis) {
2145 2154
     axis_known_position[axis] = true;
2146 2155
     axis_homed[axis] = true;
2147 2156
 
2148
-    #if ENABLED(Z_PROBE_SLED)
2149
-      // bring Z probe back
2150
-      if (axis == Z_AXIS) {
2151
-        if (axis_home_dir < 0) dock_sled(true);
2157
+    // Put away the Z probe
2158
+    #if ENABLED(Z_PROBE_SLED) || SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
2159
+      if (axis == Z_AXIS && axis_home_dir < 0) {
2160
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
2161
+          if (DEBUGGING(LEVELING)) {
2162
+            SERIAL_ECHOLNPGM("> SERVO_LEVELING > " STRINGIFY(_Z_STOW));
2163
+          }
2164
+        #endif
2165
+        _Z_STOW;
2152 2166
       }
2153
-    #elif SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
2167
+    #endif
2154 2168
 
2155
-      // Deploy a Z probe if there is one, and homing towards the bed
2156
-      if (axis == Z_AXIS) {
2157
-        if (axis_home_dir < 0) {
2158
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
2159
-            if (DEBUGGING(LEVELING)) {
2160
-              SERIAL_ECHOLNPGM("> SERVO_LEVELING > stow_z_probe");
2161
-            }
2162
-          #endif
2163
-          stow_z_probe();
2164
-        }
2169
+    // Retract Servo endstop if enabled
2170
+    #if HAS_SERVO_ENDSTOPS
2171
+      if (_Z_SERVO_TEST && servo_endstop_id[axis] >= 0) {
2172
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
2173
+          if (DEBUGGING(LEVELING)) {
2174
+            SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
2175
+          }
2176
+        #endif
2177
+        servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
2178
+        if (_Z_PROBE_SUBTEST) z_probe_is_active = false;
2165 2179
       }
2166
-      else
2167
-
2168 2180
     #endif
2169 2181
 
2170
-    {
2171
-      #if HAS_SERVO_ENDSTOPS
2172
-        // Retract Servo endstop if enabled
2173
-        if (servo_endstop_id[axis] >= 0) {
2174
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
2175
-            if (DEBUGGING(LEVELING)) {
2176
-              SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
2177
-            }
2178
-          #endif
2179
-          servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
2180
-          z_probe_is_active = false;
2181
-        }
2182
-      #endif
2183
-    }
2184
-
2185 2182
   }
2186 2183
 
2187 2184
   #if ENABLED(DEBUG_LEVELING_FEATURE)

Loading…
Cancel
Save