From 74900f7a70f339071fd1e03176260f61f668d4cd Mon Sep 17 00:00:00 2001
From: Giuliano <3684609+GMagician@users.noreply.github.com>
Date: Sun, 29 Jul 2018 02:30:14 +0200
Subject: [PATCH] [2.0.x] bltouch home refinements (#11397)

Just create  a better functions call logic flow
---
 Marlin/src/module/motion.cpp | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp
index d7cfd2a479..de94ccd788 100644
--- a/Marlin/src/module/motion.cpp
+++ b/Marlin/src/module/motion.cpp
@@ -1297,12 +1297,7 @@ 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) {
-      if (DEPLOY_PROBE()) return;
-      #if ENABLED(BLTOUCH)
-        if (set_bltouch_deployed(true)) return;
-      #endif
-    }
+    if (axis == Z_AXIS && DEPLOY_PROBE()) return;
   #endif
 
   // Set flags for X, Y, Z motor locking
@@ -1326,6 +1321,12 @@ void homeaxis(const AxisEnum axis) {
   #if ENABLED(DEBUG_LEVELING_FEATURE)
     if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 1 Fast:");
   #endif
+
+  #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
+    // BLTOUCH needs to be deployed every time
+    if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
+  #endif
+
   do_homing_move(axis, 1.5f * max_length(axis) * axis_home_dir);
 
   #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
@@ -1364,6 +1365,11 @@ void homeaxis(const AxisEnum axis) {
     #endif
 
     do_homing_move(axis, 2 * bump, get_homing_bump_feedrate(axis));
+
+    #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
+      // BLTOUCH needs to be stowed after trigger to rearm itself
+      if (axis == Z_AXIS) set_bltouch_deployed(false);
+    #endif
   }
 
   #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
@@ -1440,12 +1446,7 @@ void homeaxis(const AxisEnum axis) {
 
   // 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;
-    }
+    if (axis == Z_AXIS && STOW_PROBE()) return;
   #endif
 
   // Clear retracted status if homing the Z axis
-- 
GitLab