aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/example-extras.cfg30
-rw-r--r--klippy/extras/controller_fan.py53
2 files changed, 83 insertions, 0 deletions
diff --git a/config/example-extras.cfg b/config/example-extras.cfg
index dd8db7a7..5ef8e404 100644
--- a/config/example-extras.cfg
+++ b/config/example-extras.cfg
@@ -414,6 +414,36 @@
# is 1.0
+# Controller cooling fan. A "controller fan" is a fan that will be
+# enabled whenever its associated heater or any configured 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.
+#[controller_fan]
+#pin:
+#max_power:
+#shutdown_speed:
+#cycle_time:
+#hardware_pwm:
+#kick_start_time:
+# See the "fan" section in example.cfg for a description of the
+# above parameters.
+#idle_timeout:
+# The ammount of time (in seconds) after a stepper driver or heater
+# was active and the fan should be kept running. The default
+# is 30 seconds.
+#idle_speed:
+# The fan speed (expressed as a value from 0.0 to 1.0) that the fan
+# will be set to when a heater or stepper driver was active and before
+# the idle_timeout is reached. This must be greater or equal
+# max_power. The default is max_power
+#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".
+
+
# Temperature-triggered cooling fans (one may define any number of
# sections with a "temperature_fan" prefix). A "temperature fan" is a
# fan that will be enabled whenever its associated sensor is above a
diff --git a/klippy/extras/controller_fan.py b/klippy/extras/controller_fan.py
new file mode 100644
index 00000000..05897e3b
--- /dev/null
+++ b/klippy/extras/controller_fan.py
@@ -0,0 +1,53 @@
+# Support a fan for cooling the MCU whenever a stepper or heater is on
+#
+# Copyright (C) 2019 Nils Friedchen <nils.friedchen@googlemail.com>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import fan
+
+PIN_MIN_TIME = 0.100
+
+class ControllerFan:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ self.printer.register_event_handler("klippy:ready", self.handle_ready)
+ self.steppers = []
+ self.fan = fan.PrinterFan(config)
+ self.mcu = self.fan.mcu_fan.get_mcu()
+ self.max_power = config.getfloat(
+ 'max_power', 1., minval=0., maxval=1.)
+ self.idle_speed = config.getfloat(
+ 'idle_speed', self.max_power, minval=0., maxval=self.max_power)
+ self.idle_timeout = config.getint("idle_timeout", 30, minval=0)
+ self.heater_name = config.get("heater", "extruder")
+ self.last_on = self.idle_timeout
+ def handle_ready(self):
+ pheater = self.printer.lookup_object('heater')
+ self.heaters = [pheater.lookup_heater(n.strip())
+ for n in self.heater_name.split(',')]
+ kin = self.printer.lookup_object('toolhead').get_kinematics()
+ self.steppers = kin.get_steppers()
+ reactor = self.printer.get_reactor()
+ reactor.register_timer(self.callback, reactor.NOW)
+ def callback(self, eventtime):
+ power = 0.
+ active = False
+ for stepper in self.steppers:
+ active |= stepper.is_motor_enabled()
+ for heater in self.heaters:
+ currentTemp, targetTemp = heater.get_temp(eventtime)
+ if targetTemp:
+ active = True
+ if active:
+ self.last_on = 0
+ power = self.max_power
+ else:
+ if self.last_on < self.idle_timeout:
+ power = self.idle_speed
+ self.last_on += 1
+ print_time = self.mcu.estimated_print_time(eventtime) + PIN_MIN_TIME
+ self.fan.set_speed(print_time, power)
+ return eventtime + 1.
+
+def load_config(config):
+ return ControllerFan(config)