From 86b4b805d25c004e71733dea7d40099f218ef6b4 Mon Sep 17 00:00:00 2001
From: Pablo Clemente <pablo.clemente@bq.com>
Date: Thu, 12 Jun 2014 18:43:16 +0200
Subject: [PATCH] Fixed stop print LCD function on M104

---
 Marlin/Marlin_main.cpp | 6 ++++--
 Marlin/ultralcd.cpp    | 3 +++
 Marlin/ultralcd.h      | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index c4afca7f68..a9a29dde60 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -1945,14 +1945,16 @@ void process_commands()
 
       /* See if we are heating up or cooling down */
       target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
+      
+      forced_heating_stop = true;
 
       #ifdef TEMP_RESIDENCY_TIME
         long residencyStart;
         residencyStart = -1;
         /* continue to loop until we have reached the target temp
           _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
-        while((residencyStart == -1) ||
-              (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL))) ) {
+        while((forced_heating_stop == true)&&((residencyStart == -1) ||
+              (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL)))) ) {
       #else
         while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
       #endif //TEMP_RESIDENCY_TIME
diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp
index f09dd410d6..4f5aaac998 100644
--- a/Marlin/ultralcd.cpp
+++ b/Marlin/ultralcd.cpp
@@ -19,6 +19,7 @@ int absPreheatHotendTemp;
 int absPreheatHPBTemp;
 int absPreheatFanSpeed;
 
+boolean forced_heating_stop = true ;
 
 #ifdef ULTIPANEL
 static float manual_feedrate[] = MANUAL_FEEDRATE;
@@ -256,6 +257,8 @@ static void lcd_sdcard_stop()
         enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
     }
     autotempShutdown();
+    
+    forced_heating_stop = false;
 }
 
 /* Menu implementation */
diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h
index f4570f6a58..b4195f3975 100644
--- a/Marlin/ultralcd.h
+++ b/Marlin/ultralcd.h
@@ -42,6 +42,8 @@
   extern int absPreheatHotendTemp;
   extern int absPreheatHPBTemp;
   extern int absPreheatFanSpeed;
+  
+  extern boolean forced_heating_stop;
     
   void lcd_buzz(long duration,uint16_t freq);
   bool lcd_clicked();
-- 
GitLab