aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-12-01 11:46:43 -0500
committerKevin O'Connor <kevin@koconnor.net>2020-12-01 11:51:24 -0500
commita7e9050439f539a85d8fc9a4a78e794d6f3620ca (patch)
tree4feb4d9f4593106a0ec85883ca9a7e854d09be65
parentf90fbb56d2f94f330ab558c54ada41b0914849e4 (diff)
downloadkutter-a7e9050439f539a85d8fc9a4a78e794d6f3620ca.tar.gz
kutter-a7e9050439f539a85d8fc9a4a78e794d6f3620ca.tar.xz
kutter-a7e9050439f539a85d8fc9a4a78e794d6f3620ca.zip
heater_fan: Improve timing of fan commands
Don't use the reactor eventtime to schedule micro-controller commands as that time may have low accuracy. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/heater_fan.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/klippy/extras/heater_fan.py b/klippy/extras/heater_fan.py
index d69a7cf4..1294b4d2 100644
--- a/klippy/extras/heater_fan.py
+++ b/klippy/extras/heater_fan.py
@@ -17,22 +17,27 @@ class PrinterHeaterFan:
self.heaters = []
self.fan = fan.Fan(config, default_shutdown_speed=1.)
self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.)
+ self.last_speed = 0.
def handle_ready(self):
pheaters = self.printer.lookup_object('heaters')
self.heaters = [pheaters.lookup_heater(n.strip())
for n in self.heater_name.split(',')]
reactor = self.printer.get_reactor()
- reactor.register_timer(self.callback, reactor.NOW)
+ reactor.register_timer(self.callback, reactor.monotonic()+PIN_MIN_TIME)
def get_status(self, eventtime):
return self.fan.get_status(eventtime)
def callback(self, eventtime):
- power = 0.
+ speed = 0.
for heater in self.heaters:
current_temp, target_temp = heater.get_temp(eventtime)
if target_temp or current_temp > self.heater_temp:
- power = self.fan_speed
- print_time = self.fan.get_mcu().estimated_print_time(eventtime)
- self.fan.set_speed(print_time + PIN_MIN_TIME, power)
+ speed = self.fan_speed
+ if speed == self.last_speed:
+ return
+ self.last_speed = speed
+ curtime = self.printer.get_reactor().monotonic()
+ print_time = self.fan.get_mcu().estimated_print_time(curtime)
+ self.fan.set_speed(print_time + PIN_MIN_TIME, speed)
return eventtime + 1.
def load_config_prefix(config):