Skip to content

Commit

Permalink
fan: Support calling set_speed() without a print_time
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Sep 30, 2024
1 parent 1c0adb9 commit f4143af
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 1 addition & 3 deletions klippy/extras/controller_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def callback(self, eventtime):
self.last_on += 1
if speed != self.last_speed:
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)
self.fan.set_speed(speed)
return eventtime + 1.

def load_config_prefix(config):
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _apply_speed(self, print_time, value):
return "delay", self.kick_start_time
self.last_fan_value = self.last_req_value = value
self.mcu_fan.set_pwm(print_time, value)
def set_speed(self, print_time, value):
def set_speed(self, value, print_time=None):
self.gcrq.send_async_request(value, print_time)
def set_speed_from_command(self, value):
self.gcrq.queue_gcode_request(value)
Expand Down
4 changes: 1 addition & 3 deletions klippy/extras/heater_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def callback(self, eventtime):
speed = self.fan_speed
if speed != self.last_speed:
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)
self.fan.set_speed(speed)
return eventtime + 1.

def load_config_prefix(config):
Expand Down
12 changes: 6 additions & 6 deletions klippy/extras/temperature_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, config):
self.cmd_SET_TEMPERATURE_FAN_TARGET,
desc=self.cmd_SET_TEMPERATURE_FAN_TARGET_help)

def set_speed(self, read_time, value):
def set_tf_speed(self, read_time, value):
if value <= 0.:
value = 0.
elif value < self.min_speed:
Expand All @@ -60,7 +60,7 @@ def set_speed(self, read_time, value):
speed_time = read_time + self.speed_delay
self.next_speed_time = speed_time + 0.75 * MAX_FAN_TIME
self.last_speed_value = value
self.fan.set_speed(speed_time, value)
self.fan.set_speed(value, speed_time)
def temperature_callback(self, read_time, temp):
self.last_temp = temp
self.control.temperature_callback(read_time, temp)
Expand Down Expand Up @@ -128,10 +128,10 @@ def temperature_callback(self, read_time, temp):
and temp <= target_temp-self.max_delta):
self.heating = True
if self.heating:
self.temperature_fan.set_speed(read_time, 0.)
self.temperature_fan.set_tf_speed(read_time, 0.)
else:
self.temperature_fan.set_speed(read_time,
self.temperature_fan.get_max_speed())
self.temperature_fan.set_tf_speed(
read_time, self.temperature_fan.get_max_speed())

######################################################################
# Proportional Integral Derivative (PID) control algo
Expand Down Expand Up @@ -171,7 +171,7 @@ def temperature_callback(self, read_time, temp):
# Calculate output
co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv
bounded_co = max(0., min(self.temperature_fan.get_max_speed(), co))
self.temperature_fan.set_speed(
self.temperature_fan.set_tf_speed(
read_time, max(self.temperature_fan.get_min_speed(),
self.temperature_fan.get_max_speed() - bounded_co))
# Store state for next measurement
Expand Down

0 comments on commit f4143af

Please sign in to comment.