diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2024-09-21 15:29:47 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2024-09-30 12:23:24 -0400 |
commit | 1c0adb9af88411116a4980636e8070ae1decd457 (patch) | |
tree | 4220acf59bb34fe80ef14dc0b6e029aecebe77c1 /klippy/extras/output_pin.py | |
parent | 8a7a39530ee7bc7acfbe8bb30e5ff5189dac0f3f (diff) | |
download | kutter-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/output_pin.py')
-rw-r--r-- | klippy/extras/output_pin.py | 22 |
1 files changed, 20 insertions, 2 deletions
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") |