Browse Source

Prevent stuck M109/M190 when target is changed

Scott Lahteine 8 years ago
parent
commit
6d3e4e1f8f
1 changed files with 36 additions and 18 deletions
  1. 36
    18
      Marlin/Marlin_main.cpp

+ 36
- 18
Marlin/Marlin_main.cpp View File

4463
     if (code_seen('B')) autotemp_max = code_value();
4463
     if (code_seen('B')) autotemp_max = code_value();
4464
   #endif
4464
   #endif
4465
 
4465
 
4466
-  bool wants_to_cool = isCoolingHotend(target_extruder);
4467
-
4468
-  // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4469
-  if (no_wait_for_cooling && wants_to_cool) return;
4470
-
4471
-  // Prevents a wait-forever situation if R is misused i.e. M109 R0
4472
-  // Try to calculate a ballpark safe margin by halving EXTRUDE_MINTEMP
4473
-  if (wants_to_cool && degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return;
4474
-
4475
   #if TEMP_RESIDENCY_TIME > 0
4466
   #if TEMP_RESIDENCY_TIME > 0
4476
     millis_t residency_start_ms = 0;
4467
     millis_t residency_start_ms = 0;
4477
     // Loop until the temperature has stabilized
4468
     // Loop until the temperature has stabilized
4481
     #define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
4472
     #define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
4482
   #endif //TEMP_RESIDENCY_TIME > 0
4473
   #endif //TEMP_RESIDENCY_TIME > 0
4483
 
4474
 
4484
-  KEEPALIVE_STATE(NOT_BUSY);
4485
-
4475
+  float theTarget = -1;
4476
+  bool wants_to_cool;
4486
   cancel_heatup = false;
4477
   cancel_heatup = false;
4487
   millis_t now, next_temp_ms = 0;
4478
   millis_t now, next_temp_ms = 0;
4479
+
4480
+  KEEPALIVE_STATE(NOT_BUSY);
4481
+
4488
   do {
4482
   do {
4483
+
4489
     now = millis();
4484
     now = millis();
4490
     if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
4485
     if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
4491
       next_temp_ms = now + 1000UL;
4486
       next_temp_ms = now + 1000UL;
4506
       #endif
4501
       #endif
4507
     }
4502
     }
4508
 
4503
 
4504
+    // Target temperature might be changed during the loop
4505
+    if (theTarget != degTargetHotend(target_extruder)) {
4506
+      theTarget = degTargetHotend(target_extruder);
4507
+      wants_to_cool = isCoolingHotend(target_extruder);
4508
+
4509
+      // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4510
+      if (no_wait_for_cooling && wants_to_cool) break;
4511
+
4512
+      // Prevent a wait-forever situation if R is misused i.e. M109 R0
4513
+      // Try to calculate a ballpark safe margin by halving EXTRUDE_MINTEMP
4514
+      if (wants_to_cool && theTarget < (EXTRUDE_MINTEMP)/2) break;
4515
+    }
4516
+
4509
     idle();
4517
     idle();
4510
     refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4518
     refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4511
 
4519
 
4512
     #if TEMP_RESIDENCY_TIME > 0
4520
     #if TEMP_RESIDENCY_TIME > 0
4513
 
4521
 
4514
-      float temp_diff = fabs(degTargetHotend(target_extruder) - degHotend(target_extruder));
4522
+      float temp_diff = fabs(theTarget - degHotend(target_extruder));
4515
 
4523
 
4516
       if (!residency_start_ms) {
4524
       if (!residency_start_ms) {
4517
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4525
         // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
4543
     bool no_wait_for_cooling = code_seen('S');
4551
     bool no_wait_for_cooling = code_seen('S');
4544
     if (no_wait_for_cooling || code_seen('R')) setTargetBed(code_value());
4552
     if (no_wait_for_cooling || code_seen('R')) setTargetBed(code_value());
4545
 
4553
 
4546
-    bool wants_to_cool = isCoolingBed();
4547
-
4548
-    // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4549
-    if (no_wait_for_cooling && wants_to_cool) return;
4550
-
4551
     #if TEMP_BED_RESIDENCY_TIME > 0
4554
     #if TEMP_BED_RESIDENCY_TIME > 0
4552
       millis_t residency_start_ms = 0;
4555
       millis_t residency_start_ms = 0;
4553
       // Loop until the temperature has stabilized
4556
       // Loop until the temperature has stabilized
4557
       #define TEMP_BED_CONDITIONS (wants_to_cool ? isCoolingBed() : isHeatingBed())
4560
       #define TEMP_BED_CONDITIONS (wants_to_cool ? isCoolingBed() : isHeatingBed())
4558
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4561
     #endif //TEMP_BED_RESIDENCY_TIME > 0
4559
 
4562
 
4563
+    float theTarget = -1;
4564
+    bool wants_to_cool;
4560
     cancel_heatup = false;
4565
     cancel_heatup = false;
4561
     millis_t now, next_temp_ms = 0;
4566
     millis_t now, next_temp_ms = 0;
4562
 
4567
 
4563
-    // Wait for temperature to come close enough
4564
     KEEPALIVE_STATE(NOT_BUSY);
4568
     KEEPALIVE_STATE(NOT_BUSY);
4569
+
4565
     do {
4570
     do {
4566
       now = millis();
4571
       now = millis();
4567
       if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
4572
       if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
4581
         #endif
4586
         #endif
4582
       }
4587
       }
4583
 
4588
 
4589
+      // Target temperature might be changed during the loop
4590
+      if (theTarget != degTargetBed()) {
4591
+        theTarget = degTargetBed();
4592
+        wants_to_cool = isCoolingBed();
4593
+
4594
+        // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
4595
+        if (no_wait_for_cooling && wants_to_cool) break;
4596
+
4597
+        // Prevent a wait-forever situation if R is misused i.e. M190 R0
4598
+        // Simply don't wait for cooling below 30C
4599
+        if (wants_to_cool && theTarget < (EXTRUDE_MINTEMP)/2) break;
4600
+      }
4601
+
4584
       idle();
4602
       idle();
4585
       refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4603
       refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
4586
 
4604
 

Loading…
Cancel
Save