From 7d2e8505772e85bb42920fdf7efe63493c05b89f Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Sun, 10 Dec 2017 21:26:11 -0600
Subject: [PATCH] Have M420 report a changed position

---
 Marlin/src/gcode/bedlevel/M420.cpp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp
index 71bf7e2738..2625d047f9 100644
--- a/Marlin/src/gcode/bedlevel/M420.cpp
+++ b/Marlin/src/gcode/bedlevel/M420.cpp
@@ -45,6 +45,11 @@
  */
 void GcodeSuite::M420() {
 
+  const float oldpos[XYZE] = {
+    current_position[X_AXIS], current_position[Y_AXIS],
+    current_position[Z_AXIS], current_position[E_AXIS]
+  };
+
   #if ENABLED(AUTO_BED_LEVELING_UBL)
 
     // L to load a mesh from the EEPROM
@@ -104,13 +109,16 @@ void GcodeSuite::M420() {
     #endif
   }
 
-  const bool to_enable = parser.boolval('S');
-  if (parser.seen('S')) set_bed_leveling_enabled(to_enable);
-
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false);
   #endif
 
+  bool to_enable = false;
+  if (parser.seen('S')) {
+    to_enable = parser.value_bool();
+    set_bed_leveling_enabled(to_enable);
+  }
+
   const bool new_status = planner.leveling_active;
 
   if (to_enable && !new_status) {
@@ -129,6 +137,10 @@ void GcodeSuite::M420() {
     else
       SERIAL_ECHOLNPGM(MSG_OFF);
   #endif
+
+  // Report change in position
+  if (memcmp(oldpos, current_position, sizeof(oldpos)))
+    report_current_position();
 }
 
 #endif // HAS_LEVELING
\ No newline at end of file
-- 
GitLab