Fix for M109 and M190 cooldown

Also removes the re-definition of now inside M190's while loop
This commit is contained in:
gralco 2016-04-11 14:33:35 -06:00 committed by Scott Lahteine
parent 47e3564bbd
commit c218db136a

View file

@ -4242,12 +4242,11 @@ inline void gcode_M105() {
* Rxxx Wait for extruder(s) to reach temperature. Waits when heating and cooling. * Rxxx Wait for extruder(s) to reach temperature. Waits when heating and cooling.
*/ */
inline void gcode_M109() { inline void gcode_M109() {
bool no_wait_for_cooling = true;
if (setTargetedHotend(109)) return; if (setTargetedHotend(109)) return;
if (DEBUGGING(DRYRUN)) return; if (DEBUGGING(DRYRUN)) return;
no_wait_for_cooling = code_seen('S'); bool no_wait_for_cooling = code_seen('S');
if (no_wait_for_cooling || code_seen('R')) { if (no_wait_for_cooling || code_seen('R')) {
float temp = code_value(); float temp = code_value();
setTargetHotend(temp, target_extruder); setTargetHotend(temp, target_extruder);
@ -4282,12 +4281,14 @@ inline void gcode_M109() {
if (code_seen('B')) autotemp_max = code_value(); if (code_seen('B')) autotemp_max = code_value();
#endif #endif
// Exit if the temperature is above target and not waiting for cooling bool wants_to_cool = isCoolingHotend(target_extruder);
if (no_wait_for_cooling && !isHeatingHotend(target_extruder)) return;
// Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
if (no_wait_for_cooling && wants_to_cool) return;
// Prevents a wait-forever situation if R is misused i.e. M109 R0 // Prevents a wait-forever situation if R is misused i.e. M109 R0
// Try to calculate a ballpark safe margin by halving EXTRUDE_MINTEMP // Try to calculate a ballpark safe margin by halving EXTRUDE_MINTEMP
if (degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return; if (wants_to_cool && degTargetHotend(target_extruder) < (EXTRUDE_MINTEMP)/2) return;
#ifdef TEMP_RESIDENCY_TIME #ifdef TEMP_RESIDENCY_TIME
millis_t residency_start_ms = 0; millis_t residency_start_ms = 0;
@ -4295,12 +4296,12 @@ inline void gcode_M109() {
#define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL)) #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
#else #else
// Loop until the temperature is very close target // Loop until the temperature is very close target
#define TEMP_CONDITIONS (isHeatingHotend(target_extruder)) #define TEMP_CONDITIONS (wants_to_cool ? isCoolingHotend(target_extruder) : isHeatingHotend(target_extruder))
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
cancel_heatup = false; cancel_heatup = false;
millis_t now = millis(), next_temp_ms = now + 1000UL; millis_t now, next_temp_ms = 0;
while (!cancel_heatup && TEMP_CONDITIONS) { do {
now = millis(); now = millis();
if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
next_temp_ms = now + 1000UL; next_temp_ms = now + 1000UL;
@ -4326,7 +4327,7 @@ inline void gcode_M109() {
#ifdef TEMP_RESIDENCY_TIME #ifdef TEMP_RESIDENCY_TIME
float temp_diff = labs(degHotend(target_extruder) - degTargetHotend(target_extruder)); float temp_diff = fabs(degTargetHotend(target_extruder) - degHotend(target_extruder));
if (!residency_start_ms) { if (!residency_start_ms) {
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@ -4339,7 +4340,7 @@ inline void gcode_M109() {
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
} // while(!cancel_heatup && TEMP_CONDITIONS) } while (!cancel_heatup && TEMP_CONDITIONS);
LCD_MESSAGEPGM(MSG_HEATING_COMPLETE); LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
} }
@ -4355,15 +4356,18 @@ inline void gcode_M109() {
LCD_MESSAGEPGM(MSG_BED_HEATING); LCD_MESSAGEPGM(MSG_BED_HEATING);
bool no_wait_for_cooling = code_seen('S'); bool no_wait_for_cooling = code_seen('S');
if (no_wait_for_cooling || code_seen('R')) if (no_wait_for_cooling || code_seen('R')) setTargetBed(code_value());
setTargetBed(code_value());
// Exit if the temperature is above target and not waiting for cooling bool wants_to_cool = isCoolingBed();
if (no_wait_for_cooling && !isHeatingBed()) return;
// Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
if (no_wait_for_cooling && wants_to_cool) return;
cancel_heatup = false; cancel_heatup = false;
millis_t now = millis(), next_temp_ms = now + 1000UL; millis_t next_temp_ms = 0;
while (!cancel_heatup && isHeatingBed()) {
// Wait for temperature to come close enough
do {
millis_t now = millis(); millis_t now = millis();
if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up. if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
next_temp_ms = now + 1000UL; next_temp_ms = now + 1000UL;
@ -4372,7 +4376,7 @@ inline void gcode_M109() {
} }
idle(); idle();
refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
} } while (!cancel_heatup && (wants_to_cool ? isCoolingBed() : isHeatingBed()));
LCD_MESSAGEPGM(MSG_BED_DONE); LCD_MESSAGEPGM(MSG_BED_DONE);
} }