Browse Source

Fix M109 so it won't wait for cooling

Addressing issue #2767
Scott Lahteine 8 years ago
parent
commit
ea9fd1200b
1 changed files with 32 additions and 41 deletions
  1. 32
    41
      Marlin/Marlin_main.cpp

+ 32
- 41
Marlin/Marlin_main.cpp View File

@@ -289,7 +289,6 @@ static millis_t stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME * 1000L;
289 289
 millis_t print_job_start_ms = 0; ///< Print job start time
290 290
 millis_t print_job_stop_ms = 0;  ///< Print job stop time
291 291
 static uint8_t target_extruder;
292
-bool target_direction;
293 292
 
294 293
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
295 294
   int xy_travel_speed = XY_TRAVEL_SPEED;
@@ -3925,7 +3924,8 @@ inline void gcode_M105() {
3925 3924
 #endif // HAS_FAN
3926 3925
 
3927 3926
 /**
3928
- * M109: Wait for extruder(s) to reach temperature
3927
+ * M109: Sxxx Wait for extruder(s) to reach temperature. Waits only when heating.
3928
+ *       Rxxx Wait for extruder(s) to reach temperature. Waits when heating and cooling.
3929 3929
  */
3930 3930
 inline void gcode_M109() {
3931 3931
   bool no_wait_for_cooling = true;
@@ -3952,33 +3952,32 @@ inline void gcode_M109() {
3952 3952
     if (code_seen('B')) autotemp_max = code_value();
3953 3953
   #endif
3954 3954
 
3955
-  millis_t temp_ms = millis();
3956
-
3957
-  /* See if we are heating up or cooling down */
3958
-  target_direction = isHeatingHotend(target_extruder); // true if heating, false if cooling
3959
-
3960
-  cancel_heatup = false;
3955
+  // Exit if the temperature is above target and not waiting for cooling
3956
+  if (no_wait_for_cooling && !isHeatingHotend(target_extruder)) return;
3961 3957
 
3962 3958
   #ifdef TEMP_RESIDENCY_TIME
3963 3959
     long residency_start_ms = -1;
3964
-    /* continue to loop until we have reached the target temp
3965
-      _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
3966
-    while ((!cancel_heatup) && ((residency_start_ms == -1) ||
3967
-                                (residency_start_ms >= 0 && (((unsigned int)(millis() - residency_start_ms)) < (TEMP_RESIDENCY_TIME * 1000UL)))))
3960
+    // Loop until the temperature has stabilized
3961
+    #define TEMP_CONDITIONS (residency_start_ms < 0 || now < residency_start_ms + TEMP_RESIDENCY_TIME * 1000UL)
3968 3962
   #else
3969
-    while (target_direction ? (isHeatingHotend(target_extruder)) : (isCoolingHotend(target_extruder) && (no_wait_for_cooling == false)))
3963
+    // Loop until the temperature is exactly on target
3964
+    #define TEMP_CONDITIONS (degHotend(target_extruder) != degTargetHotend(target_extruder))
3970 3965
   #endif //TEMP_RESIDENCY_TIME
3971 3966
 
3972
-  { // while loop
3973
-    if (millis() > temp_ms + 1000UL) { //Print temp & remaining time every 1s while waiting
3967
+  cancel_heatup = false;
3968
+  millis_t now = millis(), next_temp_ms = now + 1000UL;
3969
+  while (!cancel_heatup && TEMP_CONDITIONS) {
3970
+    now = millis();
3971
+    if (now > next_temp_ms) { //Print temp & remaining time every 1s while waiting
3972
+      next_temp_ms = now + 1000UL;
3974 3973
       #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
3975 3974
         print_heaterstates();
3976 3975
       #endif
3977 3976
       #ifdef TEMP_RESIDENCY_TIME
3978 3977
         SERIAL_PROTOCOLPGM(" W:");
3979
-        if (residency_start_ms > -1) {
3980
-          temp_ms = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residency_start_ms)) / 1000UL;
3981
-          SERIAL_PROTOCOLLN(temp_ms);
3978
+        if (residency_start_ms >= 0) {
3979
+          long rem = ((TEMP_RESIDENCY_TIME * 1000UL) - (now - residency_start_ms)) / 1000UL;
3980
+          SERIAL_PROTOCOLLN(rem);
3982 3981
         }
3983 3982
         else {
3984 3983
           SERIAL_PROTOCOLLNPGM("?");
@@ -3986,23 +3985,19 @@ inline void gcode_M109() {
3986 3985
       #else
3987 3986
         SERIAL_EOL;
3988 3987
       #endif
3989
-      temp_ms = millis();
3990 3988
     }
3991 3989
 
3992 3990
     idle();
3993 3991
     refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
3994 3992
 
3995 3993
     #ifdef TEMP_RESIDENCY_TIME
3996
-      // start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
3997
-      // or when current temp falls outside the hysteresis after target temp was reached
3998
-      if ((residency_start_ms == -1 &&  target_direction && (degHotend(target_extruder) >= (degTargetHotend(target_extruder) - TEMP_WINDOW))) ||
3999
-          (residency_start_ms == -1 && !target_direction && (degHotend(target_extruder) <= (degTargetHotend(target_extruder) + TEMP_WINDOW))) ||
4000
-          (residency_start_ms > -1 && labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > TEMP_HYSTERESIS) )
4001
-      {
3994
+      // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
3995
+      // Restart the timer whenever the temperature falls outside the hysteresis.
3996
+      if (labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > ((residency_start_ms < 0) ? TEMP_WINDOW : TEMP_HYSTERESIS))
4002 3997
         residency_start_ms = millis();
4003
-      }
4004 3998
     #endif //TEMP_RESIDENCY_TIME
4005
-  }
3999
+
4000
+  } // while(!cancel_heatup && TEMP_CONDITIONS)
4006 4001
 
4007 4002
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4008 4003
   print_job_start_ms = previous_cmd_ms;
@@ -4015,28 +4010,24 @@ inline void gcode_M109() {
4015 4010
    *       Rxxx Wait for bed current temp to reach target temp. Waits when heating and cooling
4016 4011
    */
4017 4012
   inline void gcode_M190() {
4018
-    bool no_wait_for_cooling = true;
4019
-
4020 4013
     if (marlin_debug_flags & DEBUG_DRYRUN) return;
4021 4014
 
4022 4015
     LCD_MESSAGEPGM(MSG_BED_HEATING);
4023
-    no_wait_for_cooling = code_seen('S');
4016
+    bool no_wait_for_cooling = code_seen('S');
4024 4017
     if (no_wait_for_cooling || code_seen('R'))
4025 4018
       setTargetBed(code_value());
4026 4019
 
4027
-    millis_t temp_ms = millis();
4020
+    // Exit if the temperature is above target and not waiting for cooling
4021
+    if (no_wait_for_cooling && !isHeatingBed()) return;
4028 4022
 
4029 4023
     cancel_heatup = false;
4030
-    target_direction = isHeatingBed(); // true if heating, false if cooling
4031
-
4032
-    while ((target_direction && !cancel_heatup) ? isHeatingBed() : isCoolingBed() && !no_wait_for_cooling) {
4033
-      millis_t ms = millis();
4034
-      if (ms > temp_ms + 1000UL) { //Print Temp Reading every 1 second while heating up.
4035
-        temp_ms = ms;
4036
-        #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
4037
-          print_heaterstates();
4038
-          SERIAL_EOL;
4039
-        #endif
4024
+    millis_t now = millis(), next_temp_ms = now + 1000UL;
4025
+    while (!cancel_heatup && degTargetBed() != degBed()) {
4026
+      millis_t now = millis();
4027
+      if (now > next_temp_ms) { //Print Temp Reading every 1 second while heating up.
4028
+        next_temp_ms = now + 1000UL;
4029
+        print_heaterstates();
4030
+        SERIAL_EOL;
4040 4031
       }
4041 4032
       idle();
4042 4033
       refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out

Loading…
Cancel
Save