From 5ce5ff8e9befae837d583527b591445936fbb7da Mon Sep 17 00:00:00 2001
From: Giuliano <3684609+GMagician@users.noreply.github.com>
Date: Sat, 28 Jul 2018 01:30:08 +0200
Subject: [PATCH] [2.0.x] fix bltouch homing (#11379)

Partially revert. Seems to solve the issue, but one report says G29 still fails.
---
 Marlin/src/module/motion.cpp | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp
index 1cb57688e9..d7cfd2a479 100644
--- a/Marlin/src/module/motion.cpp
+++ b/Marlin/src/module/motion.cpp
@@ -1297,7 +1297,12 @@ void homeaxis(const AxisEnum axis) {
 
   // Homing Z towards the bed? Deploy the Z probe or endstop.
   #if HOMING_Z_WITH_PROBE
-    if (axis == Z_AXIS && DEPLOY_PROBE()) return;
+    if (axis == Z_AXIS) {
+      if (DEPLOY_PROBE()) return;
+      #if ENABLED(BLTOUCH)
+        if (set_bltouch_deployed(true)) return;
+      #endif
+    }
   #endif
 
   // Set flags for X, Y, Z motor locking
@@ -1322,8 +1327,9 @@ void homeaxis(const AxisEnum axis) {
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 1 Fast:");
   #endif
   do_homing_move(axis, 1.5f * max_length(axis) * axis_home_dir);
+
   #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
-    // BLTOUCH needs to be stowed after trigger to let rearm itself
+    // BLTOUCH needs to be stowed after trigger to rearm itself
     if (axis == Z_AXIS) set_bltouch_deployed(false);
   #endif
 
@@ -1353,17 +1359,13 @@ void homeaxis(const AxisEnum axis) {
     #endif
 
     #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
-      // BLTOUCH needs to deploy everytime
+      // BLTOUCH needs to be deployed every time
       if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
     #endif
+
     do_homing_move(axis, 2 * bump, get_homing_bump_feedrate(axis));
   }
 
-  // Put away the Z probe
-  #if HOMING_Z_WITH_PROBE
-    if (axis == Z_AXIS && STOW_PROBE()) return;
-  #endif
-
   #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
     const bool pos_dir = axis_home_dir > 0;
     #if ENABLED(X_DUAL_ENDSTOPS)
@@ -1436,6 +1438,16 @@ void homeaxis(const AxisEnum axis) {
 
   #endif
 
+  // Put away the Z probe
+  #if HOMING_Z_WITH_PROBE
+    if (axis == Z_AXIS) {
+      #if ENABLED(BLTOUCH)
+        if (set_bltouch_deployed(false)) return;
+      #endif
+      if (STOW_PROBE()) return;
+    }
+  #endif
+
   // Clear retracted status if homing the Z axis
   #if ENABLED(FWRETRACT)
     if (axis == Z_AXIS) fwretract.hop_amount = 0.0;