aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-01-19 23:46:01 -0500
committerKevin O'Connor <kevin@koconnor.net>2018-01-28 12:19:26 -0500
commitd166d1f69208b0b5a5eb32d6795c2b7a9485ad63 (patch)
tree1823ea67e777bafeb7a212ec4f313cc1330a9681 /klippy
parent9399911490a8163ea40b14eac1431ff469eeaf3e (diff)
downloadkutter-d166d1f69208b0b5a5eb32d6795c2b7a9485ad63.tar.gz
kutter-d166d1f69208b0b5a5eb32d6795c2b7a9485ad63.tar.xz
kutter-d166d1f69208b0b5a5eb32d6795c2b7a9485ad63.zip
fan: Move fan code to extras directory
The print cooling fan and printer heater_fan are independent modules that can reside in the extras directory. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/fan.py39
-rw-r--r--klippy/extras/heater_fan.py37
-rw-r--r--klippy/fan.py64
-rw-r--r--klippy/klippy.py4
4 files changed, 78 insertions, 66 deletions
diff --git a/klippy/extras/fan.py b/klippy/extras/fan.py
new file mode 100644
index 00000000..c7434ca5
--- /dev/null
+++ b/klippy/extras/fan.py
@@ -0,0 +1,39 @@
+# Printer cooling fan
+#
+# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import pins
+
+FAN_MIN_TIME = 0.1
+PWM_CYCLE_TIME = 0.010
+
+class PrinterFan:
+ def __init__(self, config):
+ self.last_fan_value = 0.
+ self.last_fan_time = 0.
+ 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.)
+ printer = config.get_printer()
+ self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
+ self.mcu_fan.setup_max_duration(0.)
+ self.mcu_fan.setup_cycle_time(PWM_CYCLE_TIME)
+ self.mcu_fan.setup_hard_pwm(config.getint('hard_pwm', 0))
+ def set_speed(self, print_time, value):
+ value = max(0., min(self.max_power, value))
+ if value == self.last_fan_value:
+ return
+ print_time = max(self.last_fan_time + FAN_MIN_TIME, print_time)
+ if (value and value < self.max_power
+ and not self.last_fan_value and self.kick_start_time):
+ # Run fan at full speed for specified kick_start_time
+ self.mcu_fan.set_pwm(print_time, self.max_power)
+ print_time += self.kick_start_time
+ self.mcu_fan.set_pwm(print_time, value)
+ self.last_fan_time = print_time
+ self.last_fan_value = value
+
+def load_config(config):
+ if config.get_name() != 'fan':
+ raise config.error("Invalid print cooling fan config name")
+ return PrinterFan(config)
diff --git a/klippy/extras/heater_fan.py b/klippy/extras/heater_fan.py
new file mode 100644
index 00000000..2b5ff904
--- /dev/null
+++ b/klippy/extras/heater_fan.py
@@ -0,0 +1,37 @@
+# Support fans that are enabled when a heater is on
+#
+# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import fan, extruder
+
+PIN_MIN_TIME = 0.100
+
+class PrinterHeaterFan:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ self.heater_name = config.get("heater", "extruder0")
+ self.heater_temp = config.getfloat("heater_temp", 50.0)
+ self.fan = fan.PrinterFan(config)
+ self.mcu = self.fan.mcu_fan.get_mcu()
+ max_power = self.fan.max_power
+ self.fan_speed = config.getfloat(
+ "fan_speed", max_power, minval=0., maxval=max_power)
+ self.fan.mcu_fan.setup_start_value(0., max_power)
+ def printer_state(self, state):
+ if state == 'ready':
+ self.heater = extruder.get_printer_heater(
+ self.printer, self.heater_name)
+ reactor = self.printer.get_reactor()
+ reactor.register_timer(self.callback, reactor.NOW)
+ def callback(self, eventtime):
+ current_temp, target_temp = self.heater.get_temp(eventtime)
+ power = 0.
+ if target_temp or current_temp > self.heater_temp:
+ power = self.fan_speed
+ 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 PrinterHeaterFan(config)
diff --git a/klippy/fan.py b/klippy/fan.py
deleted file mode 100644
index 50dc2500..00000000
--- a/klippy/fan.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# Printer fan support
-#
-# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
-#
-# This file may be distributed under the terms of the GNU GPLv3 license.
-import extruder, pins
-
-FAN_MIN_TIME = 0.1
-PWM_CYCLE_TIME = 0.010
-
-class PrinterFan:
- def __init__(self, printer, config):
- self.last_fan_value = 0.
- self.last_fan_time = 0.
- 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.)
- self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
- self.mcu_fan.setup_max_duration(0.)
- self.mcu_fan.setup_cycle_time(PWM_CYCLE_TIME)
- self.mcu_fan.setup_hard_pwm(config.getint('hard_pwm', 0))
- def set_speed(self, print_time, value):
- value = max(0., min(self.max_power, value))
- if value == self.last_fan_value:
- return
- print_time = max(self.last_fan_time + FAN_MIN_TIME, print_time)
- if (value and value < self.max_power
- and not self.last_fan_value and self.kick_start_time):
- # Run fan at full speed for specified kick_start_time
- self.mcu_fan.set_pwm(print_time, self.max_power)
- print_time += self.kick_start_time
- self.mcu_fan.set_pwm(print_time, value)
- self.last_fan_time = print_time
- self.last_fan_value = value
-
-class PrinterHeaterFan:
- def __init__(self, printer, config):
- self.fan = PrinterFan(printer, config)
- self.mcu = printer.lookup_object('mcu')
- heater = config.get("heater", "extruder0")
- self.heater = extruder.get_printer_heater(printer, heater)
- self.heater_temp = config.getfloat("heater_temp", 50.0)
- max_power = self.fan.max_power
- self.fan_speed = config.getfloat(
- "fan_speed", max_power, minval=0., maxval=max_power)
- self.fan.mcu_fan.setup_start_value(0., max_power)
- reactor = printer.get_reactor()
- reactor.register_timer(self.callback, reactor.NOW)
- def callback(self, eventtime):
- current_temp, target_temp = self.heater.get_temp(eventtime)
- if not current_temp and not target_temp and not self.fan.last_fan_time:
- # Printer still starting
- return eventtime + 1.
- power = 0.
- if target_temp or current_temp > self.heater_temp:
- power = self.fan_speed
- print_time = self.mcu.estimated_print_time(eventtime) + FAN_MIN_TIME
- self.fan.set_speed(print_time, power)
- return eventtime + 1.
-
-def add_printer_objects(printer, config):
- if config.has_section('fan'):
- printer.add_object('fan', PrinterFan(printer, config.getsection('fan')))
- for s in config.get_prefix_sections('heater_fan '):
- printer.add_object(s.section, PrinterHeaterFan(printer, s))
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 2bc5269d..0c28ba2d 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -7,7 +7,7 @@
import sys, os, optparse, logging, time, threading
import collections, ConfigParser, importlib
import util, reactor, queuelogger, msgproto
-import gcode, pins, mcu, chipmisc, toolhead, extruder, heater, fan
+import gcode, pins, mcu, chipmisc, toolhead, extruder, heater
message_ready = "Printer is ready"
@@ -209,7 +209,7 @@ class Printer:
m.add_printer_objects(self, config)
for section in self.fileconfig.sections():
self._try_load_module(config, section)
- for m in [chipmisc, toolhead, extruder, heater, fan]:
+ for m in [chipmisc, toolhead, extruder, heater]:
m.add_printer_objects(self, config)
# Validate that there are no undefined parameters in the config file
valid_sections = { s: 1 for s, o in self.all_config_options }