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