From 55e9b85ad65b29215b353fa6d5dd5c9ce8c41fb5 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Thu, 29 Mar 2018 17:41:04 -0500
Subject: [PATCH] Clear the "Wait for user" message set by M0/M1

See https://github.com/MarlinFirmware/Marlin/issues/10246#issuecomment-377146936
---
 Marlin/src/gcode/lcd/M0_M1.cpp | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/Marlin/src/gcode/lcd/M0_M1.cpp b/Marlin/src/gcode/lcd/M0_M1.cpp
index 8d1354e6ec..31ae41892c 100644
--- a/Marlin/src/gcode/lcd/M0_M1.cpp
+++ b/Marlin/src/gcode/lcd/M0_M1.cpp
@@ -56,9 +56,11 @@ void GcodeSuite::M0_M1() {
     hasS = ms > 0;
   }
 
+  const bool has_message = !hasP && !hasS && args && *args;
+
   #if ENABLED(ULTIPANEL)
 
-    if (!hasP && !hasS && args && *args)
+    if (has_message)
       lcd_setstatus(args, true);
     else {
       LCD_MESSAGEPGM(MSG_USERWAIT);
@@ -69,7 +71,7 @@ void GcodeSuite::M0_M1() {
 
   #else
 
-    if (!hasP && !hasS && args && *args) {
+    if (has_message) {
       SERIAL_ECHO_START();
       SERIAL_ECHOLN(args);
     }
@@ -82,18 +84,14 @@ void GcodeSuite::M0_M1() {
   stepper.synchronize();
 
   if (ms > 0) {
-    ms += previous_move_ms;  // wait until this time for a click
+    ms += millis();  // wait until this time for a click
     while (PENDING(millis(), ms) && wait_for_user) idle();
   }
   else {
     #if ENABLED(ULTIPANEL)
-      if (lcd_detected()) {
-        while (wait_for_user) idle();
-        IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);
-      }
-    #else
-      while (wait_for_user) idle();
+      if (lcd_detected())
     #endif
+        while (wait_for_user) idle();
   }
 
   #if ENABLED(PRINTER_EVENT_LEDS) && ENABLED(SDSUPPORT)
@@ -103,6 +101,12 @@ void GcodeSuite::M0_M1() {
     }
   #endif
 
+  #if ENABLED(ULTIPANEL)
+    if (lcd_detected()) {
+      IS_SD_PRINTING ? LCD_MESSAGEPGM(MSG_RESUMING) : LCD_MESSAGEPGM(WELCOME_MSG);
+    }
+  #endif
+
   wait_for_user = false;
   KEEPALIVE_STATE(IN_HANDLER);
 }
-- 
GitLab