-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fan_generic: Support setting a TEMPLATE on SET_FAN_SPEED commands
Signed-off-by: Kevin O'Connor <[email protected]>
- Loading branch information
1 parent
f4143af
commit 8f361a1
Showing
2 changed files
with
33 additions
and
3 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,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): | ||
|