mirror of https://github.com/Desuuuu/klipper.git
fan: Support setting a max_power attribute for the print cooling fan
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
09140a51d5
commit
5793271308
|
@ -245,6 +245,13 @@ max_temp: 110
|
||||||
pin: ar14
|
pin: ar14
|
||||||
# PWM output pin controlling the fan. This parameter must be
|
# PWM output pin controlling the fan. This parameter must be
|
||||||
# provided.
|
# provided.
|
||||||
|
#max_power: 1.0
|
||||||
|
# The maximum power (expressed as a value from 0.0 to 1.0) that the
|
||||||
|
# pin may be set to. The value 1.0 allows the pin to be set fully
|
||||||
|
# enabled for extended periods, while a value of 0.5 would allow the
|
||||||
|
# pin to be enabled for no more than half the time. This setting may
|
||||||
|
# be used to limit the total power output (over extended periods) to
|
||||||
|
# the fan. The default is 1.0.
|
||||||
#hard_pwm: 0
|
#hard_pwm: 0
|
||||||
# Set this value to force hardware PWM instead of software PWM. Set
|
# Set this value to force hardware PWM instead of software PWM. Set
|
||||||
# to 1 to force a hardware PWM at the fastest rate; set to a higher
|
# to 1 to force a hardware PWM at the fastest rate; set to a higher
|
||||||
|
|
|
@ -11,21 +11,22 @@ class PrinterFan:
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
self.last_fan_value = 0.
|
self.last_fan_value = 0.
|
||||||
self.last_fan_time = 0.
|
self.last_fan_time = 0.
|
||||||
|
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
|
||||||
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
|
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
|
||||||
pin = config.get('pin')
|
pin = config.get('pin')
|
||||||
hard_pwm = config.getint('hard_pwm', 0)
|
hard_pwm = config.getint('hard_pwm', 0)
|
||||||
self.mcu_fan = printer.mcu.create_pwm(pin, PWM_CYCLE_TIME, hard_pwm, 0.)
|
self.mcu_fan = printer.mcu.create_pwm(pin, PWM_CYCLE_TIME, hard_pwm, 0.)
|
||||||
# External commands
|
# External commands
|
||||||
def set_speed(self, print_time, value):
|
def set_speed(self, print_time, value):
|
||||||
value = max(0., min(1., value))
|
value = max(0., min(self.max_power, value))
|
||||||
if value == self.last_fan_value:
|
if value == self.last_fan_value:
|
||||||
return
|
return
|
||||||
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
|
mcu_time = self.mcu_fan.print_to_mcu_time(print_time)
|
||||||
mcu_time = max(self.last_fan_time + FAN_MIN_TIME, mcu_time)
|
mcu_time = max(self.last_fan_time + FAN_MIN_TIME, mcu_time)
|
||||||
if (value and value < 1.
|
if (value and value < self.max_power
|
||||||
and not self.last_fan_value and self.kick_start_time):
|
and not self.last_fan_value and self.kick_start_time):
|
||||||
# Run fan at full speed for specified kick_start_time
|
# Run fan at full speed for specified kick_start_time
|
||||||
self.mcu_fan.set_pwm(mcu_time, 1.)
|
self.mcu_fan.set_pwm(mcu_time, self.max_power)
|
||||||
mcu_time += self.kick_start_time
|
mcu_time += self.kick_start_time
|
||||||
self.mcu_fan.set_pwm(mcu_time, value)
|
self.mcu_fan.set_pwm(mcu_time, value)
|
||||||
self.last_fan_time = mcu_time
|
self.last_fan_time = mcu_time
|
||||||
|
|
Loading…
Reference in New Issue