From be00e421a76cc82a3e68cf801e211b0f450ea393 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Sat, 25 Nov 2017 14:00:39 -0600
Subject: [PATCH] Patch up M290, M851

---
 Marlin/src/core/language.h       |  1 +
 Marlin/src/gcode/motion/M290.cpp | 10 +++++++++-
 Marlin/src/gcode/probe/M851.cpp  | 16 ++++++----------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h
index 983cc1dd38..354971ce23 100644
--- a/Marlin/src/core/language.h
+++ b/Marlin/src/core/language.h
@@ -162,6 +162,7 @@
 #define MSG_Z2_MIN                          "z2_min: "
 #define MSG_Z2_MAX                          "z2_max: "
 #define MSG_Z_PROBE                         "z_probe: "
+#define MSG_PROBE_Z_OFFSET                  "Probe Z Offset"
 #define MSG_FILAMENT_RUNOUT_SENSOR          "filament: "
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
 #define MSG_ERR_M355_NONE                   "No case light"
diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp
index 35f291ada3..a0fcb504bf 100644
--- a/Marlin/src/gcode/motion/M290.cpp
+++ b/Marlin/src/gcode/motion/M290.cpp
@@ -29,6 +29,10 @@
 #include "../../module/temperature.h"
 #include "../../module/planner.h"
 
+#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
+  #include "../../core/serial.h"
+#endif
+
 /**
  * M290: Babystepping
  */
@@ -39,7 +43,7 @@ void GcodeSuite::M290() {
         const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2);
         thermalManager.babystep_axis((AxisEnum)a, offs * planner.axis_steps_per_mm[a]);
         #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
-          zprobe_zoffset += offs;
+          if (a == Z_AXIS) zprobe_zoffset += offs;
         #endif
       }
   #else
@@ -51,6 +55,10 @@ void GcodeSuite::M290() {
       #endif
     }
   #endif
+  #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
+    SERIAL_ECHO_START();
+    SERIAL_ECHOLNPAIR(MSG_PROBE_Z_OFFSET ": ", zprobe_zoffset);
+  #endif
 }
 
 #endif // BABYSTEPPING
diff --git a/Marlin/src/gcode/probe/M851.cpp b/Marlin/src/gcode/probe/M851.cpp
index 5a84b634bc..3f252f3042 100644
--- a/Marlin/src/gcode/probe/M851.cpp
+++ b/Marlin/src/gcode/probe/M851.cpp
@@ -30,20 +30,16 @@
 
 void GcodeSuite::M851() {
   SERIAL_ECHO_START();
-  SERIAL_ECHOPGM(MSG_ZPROBE_ZOFFSET " ");
+  SERIAL_ECHOPGM(MSG_PROBE_Z_OFFSET);
   if (parser.seen('Z')) {
     const float value = parser.value_linear_units();
-    if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
-      zprobe_zoffset = value;
-      SERIAL_ECHO(zprobe_zoffset);
+    if (!WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
+      SERIAL_ECHOLNPGM(" " MSG_Z_MIN " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " " MSG_Z_MAX " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX));
+      return;
     }
-    else
-      SERIAL_ECHOPGM(MSG_Z_MIN " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " " MSG_Z_MAX " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX));
+    zprobe_zoffset = value;
   }
-  else
-    SERIAL_ECHOPAIR(": ", zprobe_zoffset);
-
-  SERIAL_EOL();
+  SERIAL_ECHOLNPAIR(": ", zprobe_zoffset);
 }
 
 #endif // HAS_BED_PROBE
-- 
GitLab