From 9fa5119333e47bf56075eae09f4972ca06f0ce3f Mon Sep 17 00:00:00 2001
From: FilippoR <filippo.rossoni@gmail.com>
Date: Tue, 28 Apr 2020 06:35:10 +0200
Subject: [PATCH] Block during move in UBL mesh edit (#17670)

---
 Marlin/src/lcd/menu/menu_ubl.cpp | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp
index b3579d3538..683470c782 100644
--- a/Marlin/src/lcd/menu/menu_ubl.cpp
+++ b/Marlin/src/lcd/menu/menu_ubl.cpp
@@ -437,16 +437,10 @@ void ubl_map_move_to_xy() {
 void set_current_from_steppers_for_axis(const AxisEnum axis);
 void sync_plan_position();
 
-void _lcd_hard_stop() {
-  const screenFunc_t old_screen = ui.currentScreen;
-  lcd_limbo();
-  planner.quick_stop();
-  ui.currentScreen = old_screen;
-  set_current_from_steppers_for_axis(ALL_AXES);
-  sync_plan_position();
-}
-
 void _lcd_ubl_output_map_lcd() {
+
+  if (planner.movesplanned()) return;
+
   static int16_t step_scaler = 0;
 
   if (ui.use_click()) return _lcd_ubl_map_lcd_edit_cmd();
@@ -458,11 +452,7 @@ void _lcd_ubl_output_map_lcd() {
     ui.refresh(LCDVIEW_REDRAW_NOW);
   }
 
-  #if IS_KINEMATIC
-    #define KEEP_LOOPING true   // Loop until a valid point is found
-  #else
-    #define KEEP_LOOPING false
-  #endif
+  #define KEEP_LOOPING ENABLED(IS_KINEMATIC) // Loop until a valid point is found
 
   do {
     // Encoder to the right (++)
@@ -495,10 +485,6 @@ void _lcd_ubl_output_map_lcd() {
 
   if (ui.should_draw()) {
     ui.ubl_plot(x_plot, y_plot);
-
-    if (planner.movesplanned()) // If the nozzle is already moving, cancel the move.
-      _lcd_hard_stop();
-
     ubl_map_move_to_xy();       // Move to new location
   }
 }
@@ -511,6 +497,7 @@ void _lcd_ubl_output_map_lcd_cmd() {
     set_all_unhomed();
     queue.inject_P(G28_STR);
   }
+  if (planner.movesplanned()) return;
   ui.goto_screen(_lcd_ubl_map_homing);
 }
 
-- 
GitLab