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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-02-25 21:26:27 -05:00
parent ff9605c082
commit adf6040e9e
4 changed files with 17 additions and 11 deletions

View file

@ -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: