aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-09-21 15:29:47 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-09-30 12:23:24 -0400
commit1c0adb9af88411116a4980636e8070ae1decd457 (patch)
tree4220acf59bb34fe80ef14dc0b6e029aecebe77c1 /klippy/extras
parent8a7a39530ee7bc7acfbe8bb30e5ff5189dac0f3f (diff)
downloadkutter-1c0adb9af88411116a4980636e8070ae1decd457.tar.gz
kutter-1c0adb9af88411116a4980636e8070ae1decd457.tar.xz
kutter-1c0adb9af88411116a4980636e8070ae1decd457.zip
output_pin: Support setting a TEMPLATE on SET_PIN commands
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r--klippy/extras/fan.py2
-rw-r--r--klippy/extras/output_pin.py22
2 files changed, 21 insertions, 3 deletions
diff --git a/klippy/extras/fan.py b/klippy/extras/fan.py
index 14769473..0fc88a37 100644
--- a/klippy/extras/fan.py
+++ b/klippy/extras/fan.py
@@ -67,7 +67,7 @@ class Fan:
self.last_fan_value = self.last_req_value = value
self.mcu_fan.set_pwm(print_time, value)
def set_speed(self, print_time, value):
- self.gcrq.send_async_request(print_time, value)
+ self.gcrq.send_async_request(value, print_time)
def set_speed_from_command(self, value):
self.gcrq.queue_gcode_request(value)
def _handle_request_restart(self, print_time):
diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py
index 524b1844..24d27a62 100644
--- a/klippy/extras/output_pin.py
+++ b/klippy/extras/output_pin.py
@@ -58,7 +58,10 @@ class GCodeRequestQueue:
def queue_gcode_request(self, value):
self.toolhead.register_lookahead_callback(
(lambda pt: self._queue_request(pt, value)))
- def send_async_request(self, print_time, value):
+ def send_async_request(self, value, print_time=None):
+ if print_time is None:
+ systime = self.printer.get_reactor().monotonic()
+ print_time = self.mcu.estimated_print_time(systime + PIN_MIN_TIME)
while 1:
next_time = max(print_time, self.next_min_flush_time)
# Invoke callback for the request
@@ -202,6 +205,8 @@ class PrinterOutputPin:
# Create gcode request queue
self.gcrq = GCodeRequestQueue(config, self.mcu_pin.get_mcu(),
self._set_pin)
+ # Template handling
+ self.template_eval = lookup_template_eval(config)
# Register commands
pin_name = config.get_name().split()[1]
gcode = self.printer.lookup_object('gcode')
@@ -218,10 +223,23 @@ class PrinterOutputPin:
self.mcu_pin.set_pwm(print_time, value)
else:
self.mcu_pin.set_digital(print_time, value)
+ def _template_update(self, text):
+ try:
+ value = float(text)
+ except ValueError as e:
+ logging.exception("output_pin template render error")
+ self.gcrq.send_async_request(value)
cmd_SET_PIN_help = "Set the value of an output pin"
def cmd_SET_PIN(self, gcmd):
+ value = gcmd.get_float('VALUE', None, minval=0., maxval=self.scale)
+ template = gcmd.get('TEMPLATE', None)
+ if (value is None) == (template is None):
+ raise gcmd.error("SET_PIN command must specify VALUE or TEMPLATE")
+ # Check for template setting
+ if template is not None:
+ self.template_eval.set_template(gcmd, self._template_update)
+ return
# Read requested value
- value = gcmd.get_float('VALUE', minval=0., maxval=self.scale)
value /= self.scale
if not self.is_pwm and value not in [0., 1.]:
raise gcmd.error("Invalid pin value")