-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Klippy-Tools-Bot
committed
Oct 11, 2024
1 parent
ccdf59c
commit 67fa383
Showing
24 changed files
with
411 additions
and
277 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Support for "dotstar" leds | ||
# | ||
# Copyright (C) 2019-2022 Kevin O'Connor <[email protected]> | ||
# Copyright (C) 2019-2024 Kevin O'Connor <[email protected]> | ||
# | ||
# This file may be distributed under the terms of the GNU GPLv3 license. | ||
from . import bus | ||
from . import bus, led | ||
|
||
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000 | ||
|
||
|
@@ -22,9 +22,8 @@ def __init__(self, config): | |
self.spi = bus.MCU_SPI(mcu, None, None, 0, 500000, sw_spi_pins) | ||
# Initialize color data | ||
self.chain_count = config.getint('chain_count', 1, minval=1) | ||
pled = printer.load_object(config, "led") | ||
self.led_helper = pled.setup_helper(config, self.update_leds, | ||
self.chain_count) | ||
self.led_helper = led.LEDHelper(config, self.update_leds, | ||
self.chain_count) | ||
self.prev_data = None | ||
# Register commands | ||
printer.register_event_handler("klippy:connect", self.handle_connect) | ||
|
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, value, print_time=None): | ||
self.gcrq.send_async_request(value, print_time) | ||
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.) | ||
self.set_speed(0., print_time) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Support fans that are controlled by gcode | ||
# | ||
# 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 fan | ||
from . import fan, output_pin | ||
|
||
class PrinterFanGeneric: | ||
cmd_SET_FAN_SPEED_help = "Sets the speed of a fan" | ||
|
@@ -12,6 +12,9 @@ def __init__(self, config): | |
self.fan = fan.Fan(config, default_shutdown_speed=0.) | ||
self.fan_name = config.get_name().split()[-1] | ||
|
||
# Template handling | ||
self.template_eval = output_pin.lookup_template_eval(config) | ||
|
||
gcode = self.printer.lookup_object("gcode") | ||
gcode.register_mux_command("SET_FAN_SPEED", "FAN", | ||
self.fan_name, | ||
|
@@ -20,8 +23,21 @@ def __init__(self, config): | |
|
||
def get_status(self, eventtime): | ||
return self.fan.get_status(eventtime) | ||
def _template_update(self, text): | ||
try: | ||
value = float(text) | ||
except ValueError as e: | ||
logging.exception("fan_generic template render error") | ||
self.fan.set_speed(value) | ||
def cmd_SET_FAN_SPEED(self, gcmd): | ||
speed = gcmd.get_float('SPEED', 0.) | ||
speed = gcmd.get_float('SPEED', None, 0.) | ||
template = gcmd.get('TEMPLATE', None) | ||
if (speed is None) == (template is None): | ||
raise gcmd.error("SET_FAN_SPEED must specify SPEED or TEMPLATE") | ||
# Check for template setting | ||
if template is not None: | ||
self.template_eval.set_template(gcmd, self._template_update) | ||
return | ||
self.fan.set_speed_from_command(speed) | ||
|
||
def load_config_prefix(config): | ||
|
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
Oops, something went wrong.