From 3763d4565674577125c198f4109f123d74efb2f0 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <sourcetree@thinkyhead.com>
Date: Wed, 22 Jun 2016 16:52:32 -0700
Subject: [PATCH] Return Z position in run_z_probe

---
 Marlin/Marlin_main.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 519215287b..dc8b651ed5 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -1993,7 +1993,7 @@ static void clean_up_after_endstop_or_probe_move() {
 
   // Do a single Z probe and return with current_position[Z_AXIS]
   // at the height where the probe triggered.
-  static void run_z_probe() {
+  static float run_z_probe() {
 
     float old_feedrate = feedrate;
 
@@ -2076,6 +2076,8 @@ static void clean_up_after_endstop_or_probe_move() {
     #endif // !DELTA
 
     feedrate = old_feedrate;
+
+    return current_position[Z_AXIS];
   }
 
 #endif // HAS_BED_PROBE
@@ -2134,8 +2136,7 @@ static void clean_up_after_endstop_or_probe_move() {
       deploy_z_probe();
     }
 
-    run_z_probe();
-    float measured_z = current_position[Z_AXIS];
+    float measured_z = run_z_probe();
 
     if (probe_action & ProbeStow) {
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3851,14 +3852,14 @@ inline void gcode_G28() {
     stepper.synchronize();
 
     // TODO: clear the leveling matrix or the planner will be set incorrectly
-    run_z_probe(); // clears the ABL non-delta matrix only
+    float measured_z = run_z_probe(); // clears the ABL non-delta matrix only
 
     SERIAL_PROTOCOLPGM("Bed X: ");
     SERIAL_PROTOCOL(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER + 0.0001);
     SERIAL_PROTOCOLPGM(" Y: ");
     SERIAL_PROTOCOL(current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER + 0.0001);
     SERIAL_PROTOCOLPGM(" Z: ");
-    SERIAL_PROTOCOL(current_position[Z_AXIS] + 0.0001);
+    SERIAL_PROTOCOL(measured_z + 0.0001);
     SERIAL_EOL;
 
     stow_z_probe();
-- 
GitLab