From 946f6bdeaa4d2e497d482e3625754fcd7ee3b5a9 Mon Sep 17 00:00:00 2001
From: Darsey Litzenberger <dlitz@dlitz.net>
Date: Fri, 28 Jun 2019 17:23:42 -0700
Subject: [PATCH] Disable leveling during G12 (#14385)

---
 Marlin/src/gcode/feature/clean/G12.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp
index c9d2a4e5cb..d0aa0c16ed 100644
--- a/Marlin/src/gcode/feature/clean/G12.cpp
+++ b/Marlin/src/gcode/feature/clean/G12.cpp
@@ -30,6 +30,11 @@
 #include "../../parser.h"
 #include "../../../module/motion.h"
 
+#if HAS_LEVELING
+  #include "../../../module/planner.h"
+  #include "../../../feature/bedlevel/bedlevel.h"
+#endif
+
 /**
  * G12: Clean the nozzle
  */
@@ -42,7 +47,17 @@ void GcodeSuite::G12() {
                 objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
   const float radius = parser.floatval('R', NOZZLE_CLEAN_CIRCLE_RADIUS);
 
+  #if HAS_LEVELING
+    const bool was_enabled = planner.leveling_active;
+    set_bed_leveling_enabled(false);
+  #endif
+
   Nozzle::clean(pattern, strokes, radius, objects);
+
+  // Re-enable bed level correction if it had been on
+  #if HAS_LEVELING
+    set_bed_leveling_enabled(was_enabled);
+  #endif
 }
 
 #endif // NOZZLE_CLEAN_FEATURE
-- 
GitLab