diff options
Diffstat (limited to 'klippy/extras/verify_heater.py')
-rw-r--r-- | klippy/extras/verify_heater.py | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/klippy/extras/verify_heater.py b/klippy/extras/verify_heater.py index 6726e479..0937b638 100644 --- a/klippy/extras/verify_heater.py +++ b/klippy/extras/verify_heater.py @@ -10,58 +10,61 @@ See the 'verify_heater' section in docs/Config_Reference.md for the parameters that control this check. """ + class HeaterCheck: def __init__(self, config): self.printer = config.get_printer() - self.printer.register_event_handler("klippy:connect", - self.handle_connect) - self.printer.register_event_handler("klippy:shutdown", - self.handle_shutdown) + self.printer.register_event_handler("klippy:connect", self.handle_connect) + self.printer.register_event_handler("klippy:shutdown", self.handle_shutdown) self.heater_name = config.get_name().split()[1] self.heater = None - self.hysteresis = config.getfloat('hysteresis', 5., minval=0.) - self.max_error = config.getfloat('max_error', 120., minval=0.) - self.heating_gain = config.getfloat('heating_gain', 2., above=0.) - default_gain_time = 20. - if self.heater_name == 'heater_bed': - default_gain_time = 60. + self.hysteresis = config.getfloat("hysteresis", 5.0, minval=0.0) + self.max_error = config.getfloat("max_error", 120.0, minval=0.0) + self.heating_gain = config.getfloat("heating_gain", 2.0, above=0.0) + default_gain_time = 20.0 + if self.heater_name == "heater_bed": + default_gain_time = 60.0 self.check_gain_time = config.getfloat( - 'check_gain_time', default_gain_time, minval=1.) + "check_gain_time", default_gain_time, minval=1.0 + ) self.approaching_target = self.starting_approach = False - self.last_target = self.goal_temp = self.error = 0. + self.last_target = self.goal_temp = self.error = 0.0 self.goal_systime = self.printer.get_reactor().NEVER self.check_timer = None + def handle_connect(self): - if self.printer.get_start_args().get('debugoutput') is not None: + if self.printer.get_start_args().get("debugoutput") is not None: # Disable verify_heater if outputting to a debug file return - pheaters = self.printer.lookup_object('heaters') + pheaters = self.printer.lookup_object("heaters") self.heater = pheaters.lookup_heater(self.heater_name) logging.info("Starting heater checks for %s", self.heater_name) reactor = self.printer.get_reactor() self.check_timer = reactor.register_timer(self.check_event, reactor.NOW) + def handle_shutdown(self): if self.check_timer is not None: reactor = self.printer.get_reactor() reactor.update_timer(self.check_timer, reactor.NEVER) + def check_event(self, eventtime): temp, target = self.heater.get_temp(eventtime) - if temp >= target - self.hysteresis or target <= 0.: + if temp >= target - self.hysteresis or target <= 0.0: # Temperature near target - reset checks if self.approaching_target and target: - logging.info("Heater %s within range of %.3f", - self.heater_name, target) + logging.info("Heater %s within range of %.3f", self.heater_name, target) self.approaching_target = self.starting_approach = False if temp <= target + self.hysteresis: - self.error = 0. + self.error = 0.0 self.last_target = target - return eventtime + 1. + return eventtime + 1.0 self.error += (target - self.hysteresis) - temp if not self.approaching_target: if target != self.last_target: # Target changed - reset checks - logging.info("Heater %s approaching new target of %.3f", - self.heater_name, target) + logging.info( + "Heater %s approaching new target of %.3f", self.heater_name, target + ) self.approaching_target = self.starting_approach = True self.goal_temp = temp + self.heating_gain self.goal_systime = eventtime + self.check_gain_time @@ -71,23 +74,26 @@ class HeaterCheck: elif temp >= self.goal_temp: # Temperature approaching target - reset checks self.starting_approach = False - self.error = 0. + self.error = 0.0 self.goal_temp = temp + self.heating_gain self.goal_systime = eventtime + self.check_gain_time elif eventtime >= self.goal_systime: # Temperature is no longer approaching target self.approaching_target = False - logging.info("Heater %s no longer approaching target %.3f", - self.heater_name, target) + logging.info( + "Heater %s no longer approaching target %.3f", self.heater_name, target + ) elif self.starting_approach: self.goal_temp = min(self.goal_temp, temp + self.heating_gain) self.last_target = target - return eventtime + 1. + return eventtime + 1.0 + def heater_fault(self): msg = "Heater %s not heating at expected rate" % (self.heater_name,) logging.error(msg) self.printer.invoke_shutdown(msg + HINT_THERMAL) return self.printer.get_reactor().NEVER + def load_config_prefix(config): return HeaterCheck(config) |