mirror of https://github.com/Desuuuu/klipper.git
controller_fan: Improve timing of fan commands
Don't use the reactor eventtime to schedule micro-controller commands as that time may have low accuracy. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a7e9050439
commit
f261a4688b
|
@ -23,6 +23,7 @@ class ControllerFan:
|
|||
self.idle_timeout = config.getint("idle_timeout", default=30, minval=0)
|
||||
self.heater_name = config.get("heater", "extruder")
|
||||
self.last_on = self.idle_timeout
|
||||
self.last_speed = 0.
|
||||
def handle_ready(self):
|
||||
pheaters = self.printer.lookup_object('heaters')
|
||||
self.heaters = [pheaters.lookup_heater(n.strip())
|
||||
|
@ -30,11 +31,11 @@ class ControllerFan:
|
|||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
self.stepper_names = [s.get_name() for s in kin.get_steppers()]
|
||||
reactor = self.printer.get_reactor()
|
||||
reactor.register_timer(self.callback, reactor.NOW)
|
||||
reactor.register_timer(self.callback, reactor.monotonic()+PIN_MIN_TIME)
|
||||
def get_status(self, eventtime):
|
||||
return self.fan.get_status(eventtime)
|
||||
def callback(self, eventtime):
|
||||
power = 0.
|
||||
speed = 0.
|
||||
active = False
|
||||
for name in self.stepper_names:
|
||||
active |= self.stepper_enable.lookup_enable(name).is_motor_enabled()
|
||||
|
@ -44,12 +45,16 @@ class ControllerFan:
|
|||
active = True
|
||||
if active:
|
||||
self.last_on = 0
|
||||
power = self.fan_speed
|
||||
speed = self.fan_speed
|
||||
elif self.last_on < self.idle_timeout:
|
||||
power = self.idle_speed
|
||||
speed = self.idle_speed
|
||||
self.last_on += 1
|
||||
print_time = self.fan.get_mcu().estimated_print_time(eventtime)
|
||||
self.fan.set_speed(print_time + PIN_MIN_TIME, power)
|
||||
if speed == self.last_speed:
|
||||
return
|
||||
self.last_speed = speed
|
||||
curtime = self.printer.get_reactor().monotonic()
|
||||
print_time = self.fan.get_mcu().estimated_print_time(curtime)
|
||||
self.fan.set_speed(print_time + PIN_MIN_TIME, speed)
|
||||
return eventtime + 1.
|
||||
|
||||
def load_config_prefix(config):
|
||||
|
|
Loading…
Reference in New Issue