diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py index 1c29aae81a16..614db3b8a301 100644 --- a/klippy/extras/heaters.py +++ b/klippy/extras/heaters.py @@ -36,6 +36,7 @@ def __init__(self, config, sensor): self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.) self.smooth_time = config.getfloat('smooth_time', 1., above=0.) self.inv_smooth_time = 1. / self.smooth_time + self.is_shutdown = False self.lock = threading.Lock() self.last_temp = self.smoothed_temp = self.target_temp = 0. self.last_temp_time = 0. @@ -61,8 +62,10 @@ def __init__(self, config, sensor): gcode.register_mux_command("SET_HEATER_TEMPERATURE", "HEATER", self.name, self.cmd_SET_HEATER_TEMPERATURE, desc=self.cmd_SET_HEATER_TEMPERATURE_help) + self.printer.register_event_handler("klippy:shutdown", + self._handle_shutdown) def set_pwm(self, read_time, value): - if self.target_temp <= 0.: + if self.target_temp <= 0. or self.is_shutdown: value = 0. if ((read_time < self.next_pwm_time or not self.last_pwm_value) and abs(value - self.last_pwm_value) < 0.05): @@ -86,6 +89,8 @@ def temperature_callback(self, read_time, temp): self.smoothed_temp += temp_diff * adj_time self.can_extrude = (self.smoothed_temp >= self.min_extrude_temp) #logging.debug("temp: %.3f %f = %f", read_time, temp) + def _handle_shutdown(self): + self.is_shutdown = True # External commands def get_pwm_delay(self): return self.pwm_delay