controller_fan: Add "stepper" config option (#4447)

Allows contoller_fan sections to monitor only certain steppers instead of
all of them, similar to how heaters are currently handled.

Signed-off-by: Sophie Hirn <sophie.hirn@wyvernscale.com>
This commit is contained in:
Sophie Hirn 2021-07-20 16:19:59 +02:00 committed by GitHub
parent dafb74e3ab
commit de57ce3a99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -2374,7 +2374,7 @@ a shutdown_speed equal to max_power.
Controller cooling fan (one may define any number of sections with a
"controller_fan" prefix). A "controller fan" is a fan that will be
enabled whenever its associated heater or any configured stepper
enabled whenever its associated heater or its associated stepper
driver is active. The fan will stop whenever an idle_timeout is
reached to ensure no overheating will occur after deactivating a
watched component.
@ -2405,10 +2405,12 @@ watched component.
# will be set to when a heater or stepper driver was active and
# before the idle_timeout is reached. The default is fan_speed.
#heater:
# Name of the config section defining the heater that this fan is
# associated with. If a comma separated list of heater names is
# provided here, then the fan will be enabled when any of the given
# heaters are enabled. The default is "extruder".
#stepper:
# Name of the config section defining the heater/stepper that this fan
# is associated with. If a comma separated list of heater/stepper names
# is provided here, then the fan will be enabled when any of the given
# heaters/steppers are enabled. The default heater is "extruder", the
# default stepper is all of them.
```
## [temperature_fan]

View File

@ -11,6 +11,9 @@ class ControllerFan:
def __init__(self, config):
self.printer = config.get_printer()
self.printer.register_event_handler("klippy:ready", self.handle_ready)
self.printer.register_event_handler("klippy:connect",
self.handle_connect)
self.steppers_to_monitor = config.get("stepper", "")
self.stepper_names = []
self.stepper_enable = self.printer.load_object(config, 'stepper_enable')
self.printer.load_object(config, 'heaters')
@ -24,12 +27,23 @@ class ControllerFan:
self.heater_name = config.get("heater", "extruder")
self.last_on = self.idle_timeout
self.last_speed = 0.
def handle_connect(self):
steppers = [n.strip() for n in self.steppers_to_monitor.split(',')]
all_steppers = [s.get_name()
for s in self.stepper_enable.get_steppers()]
if steppers == [""]:
self.stepper_names = all_steppers
return
if not all(x in all_steppers for x in steppers):
raise self.printer.config_error(
("One or more of these steppers are unknown: "
"%s (valid steppers are: %s)")
% (steppers, ", ".join(all_steppers)))
self.stepper_names = steppers
def handle_ready(self):
pheaters = self.printer.lookup_object('heaters')
self.heaters = [pheaters.lookup_heater(n.strip())
for n in self.heater_name.split(',')]
kin = self.printer.lookup_object('toolhead').get_kinematics()
self.stepper_names = [s.get_name() for s in kin.get_steppers()]
reactor = self.printer.get_reactor()
reactor.register_timer(self.callback, reactor.monotonic()+PIN_MIN_TIME)
def get_status(self, eventtime):

View File

@ -126,6 +126,8 @@ class PrinterStepperEnable:
if name not in self.enable_lines:
raise self.printer.config_error("Unknown stepper '%s'" % (name,))
return self.enable_lines[name]
def get_steppers(self):
return [e.stepper for e in self.enable_lines.values()]
def load_config(config):
return PrinterStepperEnable(config)