2016-05-25 17:37:40 +02:00
|
|
|
# Printer fan support
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
FAN_MIN_TIME = 0.1
|
2017-03-09 02:00:27 +01:00
|
|
|
PWM_CYCLE_TIME = 0.010
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
class PrinterFan:
|
|
|
|
def __init__(self, printer, config):
|
2016-08-25 17:24:18 +02:00
|
|
|
self.last_fan_value = 0.
|
2016-08-24 21:16:02 +02:00
|
|
|
self.last_fan_time = 0.
|
2017-04-11 17:37:09 +02:00
|
|
|
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
|
2017-03-13 03:43:05 +01:00
|
|
|
pin = config.get('pin')
|
|
|
|
hard_pwm = config.getint('hard_pwm', 0)
|
|
|
|
self.mcu_fan = printer.mcu.create_pwm(pin, PWM_CYCLE_TIME, hard_pwm, 0.)
|
2016-05-25 17:37:40 +02:00
|
|
|
# External commands
|
|
|
|
def set_speed(self, print_time, value):
|
2016-08-25 17:24:18 +02:00
|
|
|
value = max(0., min(1., value))
|
2016-05-25 17:37:40 +02:00
|
|
|
if value == self.last_fan_value:
|
|
|
|
return
|
2016-08-24 21:16:02 +02:00
|
|
|
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
|
|
|
|
mcu_time = max(self.last_fan_time + FAN_MIN_TIME, mcu_time)
|
2016-08-25 17:24:18 +02:00
|
|
|
if (value and value < 1.
|
2016-08-24 21:16:02 +02:00
|
|
|
and not self.last_fan_value and self.kick_start_time):
|
2016-05-25 17:37:40 +02:00
|
|
|
# Run fan at full speed for specified kick_start_time
|
2016-08-25 17:24:18 +02:00
|
|
|
self.mcu_fan.set_pwm(mcu_time, 1.)
|
2016-08-24 21:16:02 +02:00
|
|
|
mcu_time += self.kick_start_time
|
|
|
|
self.mcu_fan.set_pwm(mcu_time, value)
|
|
|
|
self.last_fan_time = mcu_time
|
2016-05-25 17:37:40 +02:00
|
|
|
self.last_fan_value = value
|
2017-04-29 19:57:02 +02:00
|
|
|
|
|
|
|
def add_printer_objects(printer, config):
|
|
|
|
if config.has_section('fan'):
|
|
|
|
printer.add_object('fan', PrinterFan(printer, config.getsection('fan')))
|