From 59205ac5fcf9fb00ca2748ffe0bddd1a47b239fe Mon Sep 17 00:00:00 2001
From: Bernhard <bkubicek@x201.(none)>
Date: Wed, 30 Nov 2011 08:51:46 +0100
Subject: [PATCH] preliminiary implementation for the early heating finish.
 Might be replaced by something more clever, e.g. by erik, and does not yet
 support the second extruder or the bed. its kind of not so cool, because you
 need 6 more ints. Maybe isheating() should use the degrees directly, as it is
 not used in time-critical anyways. Then it would be much easier. to have the
 offsets without additional variables.

---
 Marlin/Configuration.h | 2 ++
 Marlin/temperature.cpp | 2 ++
 Marlin/temperature.h   | 6 ++++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 558044e280e..483b8cf8378 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -91,6 +91,8 @@
 // if CooldownNoWait is defined M109 will not wait for the cooldown to finish
 #define CooldownNoWait true
 
+// Heating is finished if a temperature close to this degree shift is reached
+#define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
 // PID settings:
 // Uncomment the following line to enable PID support.
   
diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp
index 77aa6485bac..93364f8cb00 100644
--- a/Marlin/temperature.cpp
+++ b/Marlin/temperature.cpp
@@ -43,6 +43,8 @@
 //===========================================================================
 int target_raw[3] = {0, 0, 0};
 int current_raw[3] = {0, 0, 0};
+int heatingtarget_raw[3]= {0, 0, 0};
+
 
 #ifdef PIDTEMP
   
diff --git a/Marlin/temperature.h b/Marlin/temperature.h
index a12ef03109e..ba1043b6dac 100644
--- a/Marlin/temperature.h
+++ b/Marlin/temperature.h
@@ -41,6 +41,7 @@ int temp2analogBed(int celsius);
 float analog2temp(int raw);
 float analog2tempBed(int raw);
 extern int target_raw[3];  
+extern int heatingtarget_raw[3];
 extern int current_raw[3];
 extern float Kp,Ki,Kd,Kc;
 
@@ -79,6 +80,7 @@ FORCE_INLINE float degTargetBed() {   return analog2tempBed(target_raw[TEMPSENSO
 FORCE_INLINE void setTargetHotend0(const float &celsius) 
 {  
   target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
+  heatingtarget_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius-HEATING_EARLY_FINISH_DEG_OFFSET);
   #ifdef PIDTEMP
     pid_setpoint = celsius;
   #endif //PIDTEMP
@@ -90,10 +92,10 @@ FORCE_INLINE float setTargetHotend(const float &celcius, uint8_t extruder){
 };
 FORCE_INLINE void setTargetBed(const float &celsius)     {  target_raw[TEMPSENSOR_BED     ]=temp2analogBed(celsius);};
 
-FORCE_INLINE bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
+FORCE_INLINE bool isHeatingHotend0() {return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
 FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
 FORCE_INLINE float isHeatingHotend(uint8_t extruder){  
-  if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];
+  if(extruder == 0) return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];
   if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];
 };
 FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};