forked from Klipper3d/klipper
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
13 changed files
with
108 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
# Printer cooling fan | ||
# | ||
# Copyright (C) 2016-2020 Kevin O'Connor <[email protected]> | ||
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]> | ||
# | ||
# This file may be distributed under the terms of the GNU GPLv3 license. | ||
from . import pulse_counter | ||
|
||
FAN_MIN_TIME = 0.100 | ||
from . import pulse_counter, output_pin | ||
|
||
class Fan: | ||
def __init__(self, config, default_shutdown_speed=0.): | ||
self.printer = config.get_printer() | ||
self.last_fan_value = 0. | ||
self.last_fan_time = 0. | ||
self.last_fan_value = self.last_req_value = 0. | ||
# Read config | ||
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.) | ||
self.kick_start_time = config.getfloat('kick_start_time', 0.1, | ||
|
@@ -36,6 +33,10 @@ def __init__(self, config, default_shutdown_speed=0.): | |
self.enable_pin = ppins.setup_pin('digital_out', enable_pin) | ||
self.enable_pin.setup_max_duration(0.) | ||
|
||
# Create gcode request queue | ||
self.gcrq = output_pin.GCodeRequestQueue(config, self.mcu_fan.get_mcu(), | ||
self._apply_speed) | ||
|
||
# Setup tachometer | ||
self.tachometer = FanTachometer(config) | ||
|
||
|
@@ -45,37 +46,37 @@ def __init__(self, config, default_shutdown_speed=0.): | |
|
||
def get_mcu(self): | ||
return self.mcu_fan.get_mcu() | ||
def set_speed(self, print_time, value): | ||
def _apply_speed(self, print_time, value): | ||
if value < self.off_below: | ||
value = 0. | ||
value = max(0., min(self.max_power, value * self.max_power)) | ||
if value == self.last_fan_value: | ||
return | ||
print_time = max(self.last_fan_time + FAN_MIN_TIME, print_time) | ||
return "discard", 0. | ||
if self.enable_pin: | ||
if value > 0 and self.last_fan_value == 0: | ||
self.enable_pin.set_digital(print_time, 1) | ||
elif value == 0 and self.last_fan_value > 0: | ||
self.enable_pin.set_digital(print_time, 0) | ||
if (value and value < self.max_power and self.kick_start_time | ||
if (value and self.kick_start_time | ||
and (not self.last_fan_value or value - self.last_fan_value > .5)): | ||
# Run fan at full speed for specified kick_start_time | ||
self.last_req_value = value | ||
self.last_fan_value = self.max_power | ||
self.mcu_fan.set_pwm(print_time, self.max_power) | ||
print_time += self.kick_start_time | ||
return "delay", self.kick_start_time | ||
self.last_fan_value = self.last_req_value = value | ||
self.mcu_fan.set_pwm(print_time, value) | ||
self.last_fan_time = print_time | ||
self.last_fan_value = value | ||
def set_speed(self, print_time, value): | ||
self.gcrq.send_async_request(print_time, value) | ||
def set_speed_from_command(self, value): | ||
toolhead = self.printer.lookup_object('toolhead') | ||
toolhead.register_lookahead_callback((lambda pt: | ||
self.set_speed(pt, value))) | ||
self.gcrq.queue_gcode_request(value) | ||
def _handle_request_restart(self, print_time): | ||
self.set_speed(print_time, 0.) | ||
|
||
def get_status(self, eventtime): | ||
tachometer_status = self.tachometer.get_status(eventtime) | ||
return { | ||
'speed': self.last_fan_value, | ||
'speed': self.last_req_value, | ||
'rpm': tachometer_status['rpm'], | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters