Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable heater if it appears main thread has stopped updating #6777

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down