2018-01-20 07:46:01 +03:00
|
|
|
# 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.
|
2018-04-04 00:01:10 +03:00
|
|
|
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()
|
|
|
|
self.heater_name = config.get("heater", "extruder0")
|
|
|
|
self.heater_temp = config.getfloat("heater_temp", 50.0)
|
2018-05-19 02:12:03 +03:00
|
|
|
self.fan = fan.PrinterFan(config, default_shutdown_speed=1.)
|
2018-01-20 07:46:01 +03:00
|
|
|
self.mcu = self.fan.mcu_fan.get_mcu()
|
2018-04-20 20:15:03 +03:00
|
|
|
self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.)
|
2018-01-20 07:46:01 +03:00
|
|
|
def printer_state(self, state):
|
|
|
|
if state == 'ready':
|
2018-04-04 00:01:10 +03:00
|
|
|
pheater = self.printer.lookup_object('heater')
|
|
|
|
self.heater = pheater.lookup_heater(self.heater_name)
|
2018-01-20 07:46:01 +03:00
|
|
|
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.
|
|
|
|
|
2018-02-03 20:53:11 +03:00
|
|
|
def load_config_prefix(config):
|
2018-01-20 07:46:01 +03:00
|
|
|
return PrinterHeaterFan(config)
|