Browse Source

Merge pull request #4169 from thinkyhead/rc_wait_but_break

Allow wait-for-cooling, break at threshold or if cooling stalls
Scott Lahteine 8 years ago
parent
commit
725fde8b26
1 changed files with 34 additions and 15 deletions
  1. 34
    15
      Marlin/Marlin_main.cpp

+ 34
- 15
Marlin/Marlin_main.cpp View File

@@ -4550,7 +4550,7 @@ inline void gcode_M109() {
4550 4550
       else print_job_timer.start();
4551 4551
     #endif
4552 4552
 
4553
-    if (temp > thermalManager.degHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4553
+    if (thermalManager.isHeatingHotend(target_extruder)) LCD_MESSAGEPGM(MSG_HEATING);
4554 4554
   }
4555 4555
 
4556 4556
   #if ENABLED(AUTOTEMP)
@@ -4566,10 +4566,10 @@ inline void gcode_M109() {
4566 4566
     #define TEMP_CONDITIONS (wants_to_cool ? thermalManager.isCoolingHotend(target_extruder) : thermalManager.isHeatingHotend(target_extruder))
4567 4567
   #endif //TEMP_RESIDENCY_TIME > 0
4568 4568
 
4569
-  float theTarget = -1;
4569
+  float theTarget = -1.0, old_temp = 9999.0;
4570 4570
   bool wants_to_cool;
4571 4571
   cancel_heatup = false;
4572
-  millis_t now, next_temp_ms = 0;
4572
+  millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
4573 4573
 
4574 4574
   KEEPALIVE_STATE(NOT_BUSY);
4575 4575
 
@@ -4581,10 +4581,6 @@ inline void gcode_M109() {
4581 4581
 
4582 4582
       // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4583 4583
       if (no_wait_for_cooling && wants_to_cool) break;
4584
-
4585
-      // Prevent a wait-forever situation if R is misused i.e. M109 R0
4586
-      // Try to calculate a ballpark safe margin by halving EXTRUDE_MINTEMP
4587
-      if (wants_to_cool && theTarget < (EXTRUDE_MINTEMP)/2) break;
4588 4584
     }
4589 4585
 
4590 4586
     now = millis();
@@ -4608,9 +4604,11 @@ inline void gcode_M109() {
4608 4604
     idle();
4609 4605
     refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4610 4606
 
4607
+    float temp = thermalManager.degHotend(target_extruder);
4608
+
4611 4609
     #if TEMP_RESIDENCY_TIME > 0
4612 4610
 
4613
-      float temp_diff = fabs(theTarget - thermalManager.degHotend(target_extruder));
4611
+      float temp_diff = fabs(theTarget - temp);
4614 4612
 
4615 4613
       if (!residency_start_ms) {
4616 4614
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -4623,6 +4621,17 @@ inline void gcode_M109() {
4623 4621
 
4624 4622
     #endif //TEMP_RESIDENCY_TIME > 0
4625 4623
 
4624
+    // Prevent a wait-forever situation if R is misused i.e. M109 R0
4625
+    if (wants_to_cool) {
4626
+      if (temp < (EXTRUDE_MINTEMP) / 2) break; // always break at (default) 85°
4627
+      // break after 20 seconds if cooling stalls
4628
+      if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
4629
+        if (old_temp - temp < 1.0) break;
4630
+        next_cool_check_ms = now + 20000;
4631
+        old_temp = temp;
4632
+      }
4633
+    }
4634
+
4626 4635
   } while (!cancel_heatup && TEMP_CONDITIONS);
4627 4636
 
4628 4637
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
@@ -4651,10 +4660,10 @@ inline void gcode_M109() {
4651 4660
       #define TEMP_BED_CONDITIONS (wants_to_cool ? thermalManager.isCoolingBed() : thermalManager.isHeatingBed())
4652 4661
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4653 4662
 
4654
-    float theTarget = -1;
4663
+    float theTarget = -1.0, old_temp = 9999.0;
4655 4664
     bool wants_to_cool;
4656 4665
     cancel_heatup = false;
4657
-    millis_t now, next_temp_ms = 0;
4666
+    millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
4658 4667
 
4659 4668
     KEEPALIVE_STATE(NOT_BUSY);
4660 4669
 
@@ -4666,10 +4675,6 @@ inline void gcode_M109() {
4666 4675
 
4667 4676
         // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4668 4677
         if (no_wait_for_cooling && wants_to_cool) break;
4669
-
4670
-        // Prevent a wait-forever situation if R is misused i.e. M190 R0
4671
-        // Simply don't wait to cool a bed under 30C
4672
-        if (wants_to_cool && theTarget < 30) break;
4673 4678
       }
4674 4679
 
4675 4680
       now = millis();
@@ -4693,9 +4698,11 @@ inline void gcode_M109() {
4693 4698
       idle();
4694 4699
       refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4695 4700
 
4701
+      float temp = thermalManager.degBed();
4702
+
4696 4703
       #if TEMP_BED_RESIDENCY_TIME > 0
4697 4704
 
4698
-        float temp_diff = fabs(theTarget - thermalManager.degBed());
4705
+        float temp_diff = fabs(theTarget - temp);
4699 4706
 
4700 4707
         if (!residency_start_ms) {
4701 4708
           // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -4708,7 +4715,19 @@ inline void gcode_M109() {
4708 4715
 
4709 4716
       #endif //TEMP_BED_RESIDENCY_TIME > 0
4710 4717
 
4718
+      // Prevent a wait-forever situation if R is misused i.e. M190 R0
4719
+      if (wants_to_cool) {
4720
+        if (temp < 30.0) break; // always break at 30°
4721
+        // break after 20 seconds if cooling stalls
4722
+        if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
4723
+          if (old_temp - temp < 1.0) break;
4724
+          next_cool_check_ms = now + 20000;
4725
+          old_temp = temp;
4726
+        }
4727
+      }
4728
+
4711 4729
     } while (!cancel_heatup && TEMP_BED_CONDITIONS);
4730
+
4712 4731
     LCD_MESSAGEPGM(MSG_BED_DONE);
4713 4732
     KEEPALIVE_STATE(IN_HANDLER);
4714 4733
   }

Loading…
Cancel
Save