Browse Source

Merge pull request #3438 from thinkyhead/rc_M109_residency_loop_fix

Fix bug which can cause an infinite M109 loop
Scott Lahteine 8 years ago
parent
commit
6bd20371f0
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      Marlin/Marlin_main.cpp

+ 13
- 5
Marlin/Marlin_main.cpp View File

@@ -4290,7 +4290,7 @@ inline void gcode_M109() {
4290 4290
   #ifdef TEMP_RESIDENCY_TIME
4291 4291
     long residency_start_ms = -1;
4292 4292
     // Loop until the temperature has stabilized
4293
-    #define TEMP_CONDITIONS (residency_start_ms < 0 || now < residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL)
4293
+    #define TEMP_CONDITIONS (residency_start_ms == -1 || now < residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL)
4294 4294
   #else
4295 4295
     // Loop until the temperature is very close target
4296 4296
     #define TEMP_CONDITIONS (isHeatingHotend(target_extruder))
@@ -4307,7 +4307,7 @@ inline void gcode_M109() {
4307 4307
       #endif
4308 4308
       #ifdef TEMP_RESIDENCY_TIME
4309 4309
         SERIAL_PROTOCOLPGM(" W:");
4310
-        if (residency_start_ms >= 0) {
4310
+        if (residency_start_ms != -1) {
4311 4311
           long rem = (((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL;
4312 4312
           SERIAL_PROTOCOLLN(rem);
4313 4313
         }
@@ -4323,10 +4323,18 @@ inline void gcode_M109() {
4323 4323
     refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4324 4324
 
4325 4325
     #ifdef TEMP_RESIDENCY_TIME
4326
-      // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4327
-      // Restart the timer whenever the temperature falls outside the hysteresis.
4328
-      if (labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > ((residency_start_ms < 0) ? TEMP_WINDOW : TEMP_HYSTERESIS))
4326
+
4327
+      float temp_diff = labs(degHotend(target_extruder) - degTargetHotend(target_extruder));
4328
+
4329
+      if (residency_start_ms == -1) {
4330
+        // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4331
+        if (temp_diff < TEMP_WINDOW) residency_start_ms = millis();
4332
+      }
4333
+      else if (temp_diff > TEMP_HYSTERESIS) {
4334
+        // Restart the timer whenever the temperature falls outside the hysteresis.
4329 4335
         residency_start_ms = millis();
4336
+      }
4337
+
4330 4338
     #endif //TEMP_RESIDENCY_TIME
4331 4339
 
4332 4340
   } // while(!cancel_heatup && TEMP_CONDITIONS)

Loading…
Cancel
Save