Standard methods to wait for heating (#11949)
This commit is contained in:
		@@ -80,14 +80,6 @@ void GcodeSuite::M104() {
 | 
			
		||||
 * M109: Sxxx Wait for extruder(s) to reach temperature. Waits only when heating.
 | 
			
		||||
 *       Rxxx Wait for extruder(s) to reach temperature. Waits when heating and cooling.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef MIN_COOLING_SLOPE_DEG
 | 
			
		||||
  #define MIN_COOLING_SLOPE_DEG 1.50
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef MIN_COOLING_SLOPE_TIME
 | 
			
		||||
  #define MIN_COOLING_SLOPE_TIME 60
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void GcodeSuite::M109() {
 | 
			
		||||
 | 
			
		||||
  if (get_target_extruder_from_command()) return;
 | 
			
		||||
@@ -137,110 +129,5 @@ void GcodeSuite::M109() {
 | 
			
		||||
    planner.autotemp_M104_M109();
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if TEMP_RESIDENCY_TIME > 0
 | 
			
		||||
    millis_t residency_start_ms = 0;
 | 
			
		||||
    // Loop until the temperature has stabilized
 | 
			
		||||
    #define TEMP_CONDITIONS (!residency_start_ms || PENDING(now, residency_start_ms + (TEMP_RESIDENCY_TIME) * 1000UL))
 | 
			
		||||
  #else
 | 
			
		||||
    // Loop until the temperature is very close target
 | 
			
		||||
    #define TEMP_CONDITIONS (wants_to_cool ? thermalManager.isCoolingHotend(target_extruder) : thermalManager.isHeatingHotend(target_extruder))
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  float target_temp = -1.0, old_temp = 9999.0;
 | 
			
		||||
  bool wants_to_cool = false;
 | 
			
		||||
  wait_for_heatup = true;
 | 
			
		||||
  millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
 | 
			
		||||
 | 
			
		||||
  #if DISABLED(BUSY_WHILE_HEATING)
 | 
			
		||||
    KEEPALIVE_STATE(NOT_BUSY);
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if ENABLED(PRINTER_EVENT_LEDS)
 | 
			
		||||
    const float start_temp = thermalManager.degHotend(target_extruder);
 | 
			
		||||
    uint8_t old_blue = 0;
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  do {
 | 
			
		||||
    // Target temperature might be changed during the loop
 | 
			
		||||
    if (target_temp != thermalManager.degTargetHotend(target_extruder)) {
 | 
			
		||||
      wants_to_cool = thermalManager.isCoolingHotend(target_extruder);
 | 
			
		||||
      target_temp = thermalManager.degTargetHotend(target_extruder);
 | 
			
		||||
 | 
			
		||||
      // Exit if S<lower>, continue if S<higher>, R<lower>, or R<higher>
 | 
			
		||||
      if (no_wait_for_cooling && wants_to_cool) break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    now = millis();
 | 
			
		||||
    if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
 | 
			
		||||
      next_temp_ms = now + 1000UL;
 | 
			
		||||
      thermalManager.print_heaterstates();
 | 
			
		||||
      #if TEMP_RESIDENCY_TIME > 0
 | 
			
		||||
        SERIAL_PROTOCOLPGM(" W:");
 | 
			
		||||
        if (residency_start_ms)
 | 
			
		||||
          SERIAL_PROTOCOL(long((((TEMP_RESIDENCY_TIME) * 1000UL) - (now - residency_start_ms)) / 1000UL));
 | 
			
		||||
        else
 | 
			
		||||
          SERIAL_PROTOCOLCHAR('?');
 | 
			
		||||
      #endif
 | 
			
		||||
      SERIAL_EOL();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    idle();
 | 
			
		||||
    reset_stepper_timeout(); // Keep steppers powered
 | 
			
		||||
 | 
			
		||||
    const float temp = thermalManager.degHotend(target_extruder);
 | 
			
		||||
 | 
			
		||||
    #if ENABLED(PRINTER_EVENT_LEDS)
 | 
			
		||||
      // Gradually change LED strip from violet to red as nozzle heats up
 | 
			
		||||
      if (!wants_to_cool) {
 | 
			
		||||
        const uint8_t blue = map(constrain(temp, start_temp, target_temp), start_temp, target_temp, 255, 0);
 | 
			
		||||
        if (blue != old_blue) {
 | 
			
		||||
          old_blue = blue;
 | 
			
		||||
          leds.set_color(
 | 
			
		||||
            MakeLEDColor(255, 0, blue, 0, pixels.getBrightness())
 | 
			
		||||
            #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
 | 
			
		||||
              , true
 | 
			
		||||
            #endif
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if TEMP_RESIDENCY_TIME > 0
 | 
			
		||||
 | 
			
		||||
      const float temp_diff = ABS(target_temp - temp);
 | 
			
		||||
 | 
			
		||||
      if (!residency_start_ms) {
 | 
			
		||||
        // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
 | 
			
		||||
        if (temp_diff < TEMP_WINDOW) residency_start_ms = now;
 | 
			
		||||
      }
 | 
			
		||||
      else if (temp_diff > TEMP_HYSTERESIS) {
 | 
			
		||||
        // Restart the timer whenever the temperature falls outside the hysteresis.
 | 
			
		||||
        residency_start_ms = now;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    // Prevent a wait-forever situation if R is misused i.e. M109 R0
 | 
			
		||||
    if (wants_to_cool) {
 | 
			
		||||
      // break after MIN_COOLING_SLOPE_TIME seconds
 | 
			
		||||
      // if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
 | 
			
		||||
      if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
 | 
			
		||||
        if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG)) break;
 | 
			
		||||
        next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME;
 | 
			
		||||
        old_temp = temp;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  } while (wait_for_heatup && TEMP_CONDITIONS);
 | 
			
		||||
 | 
			
		||||
  if (wait_for_heatup) {
 | 
			
		||||
    lcd_reset_status();
 | 
			
		||||
    #if ENABLED(PRINTER_EVENT_LEDS)
 | 
			
		||||
      leds.set_white();
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  #if DISABLED(BUSY_WHILE_HEATING)
 | 
			
		||||
    KEEPALIVE_STATE(IN_HANDLER);
 | 
			
		||||
  #endif
 | 
			
		||||
  (void)thermalManager.wait_for_hotend(target_extruder, no_wait_for_cooling);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user