2018-01-20 07:46:01 +03:00
|
|
|
# Support fans that are enabled when a heater is on
|
|
|
|
#
|
2020-07-04 06:23:24 +03:00
|
|
|
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
|
2018-01-20 07:46:01 +03:00
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
2020-06-12 16:55:57 +03:00
|
|
|
from . import fan
|
2018-01-20 07:46:01 +03:00
|
|
|
|
|
|
|
PIN_MIN_TIME = 0.100
|
|
|
|
|
|
|
|
class PrinterHeaterFan:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.printer = config.get_printer()
|
2020-05-05 21:10:30 +03:00
|
|
|
self.printer.load_object(config, 'heaters')
|
2019-01-08 18:55:18 +03:00
|
|
|
self.printer.register_event_handler("klippy:ready", self.handle_ready)
|
2019-11-08 00:24:52 +03:00
|
|
|
self.heater_name = config.get("heater", "extruder")
|
2018-01-20 07:46:01 +03:00
|
|
|
self.heater_temp = config.getfloat("heater_temp", 50.0)
|
2018-08-17 17:20:12 +03:00
|
|
|
self.heaters = []
|
2020-07-04 06:23:24 +03:00
|
|
|
self.fan = fan.Fan(config, default_shutdown_speed=1.)
|
2018-04-20 20:15:03 +03:00
|
|
|
self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.)
|
2019-01-08 18:55:18 +03:00
|
|
|
def handle_ready(self):
|
2020-04-25 20:27:41 +03:00
|
|
|
pheaters = self.printer.lookup_object('heaters')
|
|
|
|
self.heaters = [pheaters.lookup_heater(n.strip())
|
2019-01-08 18:55:18 +03:00
|
|
|
for n in self.heater_name.split(',')]
|
|
|
|
reactor = self.printer.get_reactor()
|
|
|
|
reactor.register_timer(self.callback, reactor.NOW)
|
2019-06-02 16:32:41 +03:00
|
|
|
def get_status(self, eventtime):
|
|
|
|
return self.fan.get_status(eventtime)
|
2018-01-20 07:46:01 +03:00
|
|
|
def callback(self, eventtime):
|
|
|
|
power = 0.
|
2018-08-17 17:20:12 +03:00
|
|
|
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
|
2020-07-04 06:23:24 +03:00
|
|
|
print_time = self.fan.get_mcu().estimated_print_time(eventtime)
|
|
|
|
self.fan.set_speed(print_time + PIN_MIN_TIME, power)
|
2018-01-20 07:46:01 +03:00
|
|
|
return eventtime + 1.
|
|
|
|
|
2018-02-03 20:53:11 +03:00
|
|
|
def load_config_prefix(config):
|
2018-01-20 07:46:01 +03:00
|
|
|
return PrinterHeaterFan(config)
|