From adf6040e9eeb09299379ad980f8382538c163750 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 25 Feb 2019 21:26:27 -0500 Subject: gcode: Use an event to handle restart request actions Instead of directly turning off motors, heaters, and fans from gcode.py, raise a new event and allow the heater, fan, and toolhead to handle the event as needed. Signed-off-by: Kevin O'Connor --- klippy/extras/fan.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'klippy/extras/fan.py') diff --git a/klippy/extras/fan.py b/klippy/extras/fan.py index d69c1127..1796f636 100644 --- a/klippy/extras/fan.py +++ b/klippy/extras/fan.py @@ -10,9 +10,12 @@ class PrinterFan: def __init__(self, config, default_shutdown_speed=0.): self.last_fan_value = 0. self.last_fan_time = 0. + printer = config.get_printer() + printer.register_event_handler("gcode:request_restart", + self.handle_request_restart) self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.) self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.) - ppins = config.get_printer().lookup_object('pins') + ppins = printer.lookup_object('pins') self.mcu_fan = ppins.setup_pin('pwm', config.get('pin')) self.mcu_fan.setup_max_duration(0.) cycle_time = config.getfloat('cycle_time', 0.010, above=0.) @@ -22,6 +25,8 @@ class PrinterFan: 'shutdown_speed', default_shutdown_speed, minval=0., maxval=1.) self.mcu_fan.setup_start_value( 0., max(0., min(self.max_power, shutdown_speed))) + def handle_request_restart(self, print_time): + self.set_speed(print_time, 0.) def set_speed(self, print_time, value): value = max(0., min(self.max_power, value * self.max_power)) if value == self.last_fan_value: -- cgit v1.2.3-70-g09d2