diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py index 7cb663a4a279..1454354272d2 100644 --- a/klippy/extras/heaters.py +++ b/klippy/extras/heaters.py @@ -14,6 +14,7 @@ MAX_HEAT_TIME = 5.0 AMBIENT_TEMP = 25. PID_PARAM_BASE = 255. +MAX_MAINTHREAD_TIME = 5.0 class Heater: def __init__(self, config, sensor): @@ -37,7 +38,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.verify_mainthread_time = -999. self.lock = threading.Lock() self.last_temp = self.smoothed_temp = self.target_temp = 0. self.last_temp_time = 0. @@ -66,7 +67,7 @@ def __init__(self, config, sensor): self.printer.register_event_handler("klippy:shutdown", self._handle_shutdown) def set_pwm(self, read_time, value): - if self.target_temp <= 0. or self.is_shutdown: + if self.target_temp <= 0. or read_time > self.verify_mainthread_time: value = 0. if ((read_time < self.next_pwm_time or not self.last_pwm_value) and abs(value - self.last_pwm_value) < 0.05): @@ -91,7 +92,7 @@ def temperature_callback(self, read_time, temp): 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 + self.verify_mainthread_time = -999. # External commands def get_name(self): return self.name @@ -129,6 +130,9 @@ def alter_target(self, target_temp): target_temp = max(self.min_temp, min(self.max_temp, target_temp)) self.target_temp = target_temp def stats(self, eventtime): + est_print_time = self.mcu_pwm.get_mcu().estimated_print_time(eventtime) + if not self.printer.is_shutdown(): + self.verify_mainthread_time = est_print_time + MAX_MAINTHREAD_TIME with self.lock: target_temp = self.target_temp last_temp = self.last_temp