diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2024-09-15 00:03:58 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2024-09-16 13:31:14 -0400 |
commit | 69e0d866c02a93072ea6aeaaec230b6939ba7604 (patch) | |
tree | 8b34790d7e06f2649d462bcc0d52d703aeba1ec7 /klippy/extras/output_pin.py | |
parent | 0532a41c752df66f149cf55d779072f420ee1b6a (diff) | |
download | kutter-69e0d866c02a93072ea6aeaaec230b6939ba7604.tar.gz kutter-69e0d866c02a93072ea6aeaaec230b6939ba7604.tar.xz kutter-69e0d866c02a93072ea6aeaaec230b6939ba7604.zip |
output_pin: Improve GCodeRequestQueue timing on duplicate requests
If there is a duplicate request it is not necessary to add a 100ms
delay to the next update. Rework the callback signaling to better
report these duplicate updates.
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 | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py index 3d7a952c..2c5cae9c 100644 --- a/klippy/extras/output_pin.py +++ b/klippy/extras/output_pin.py @@ -32,12 +32,18 @@ class GCodeRequestQueue: pos += 1 req_pt, req_val = rqueue[pos] # Invoke callback for the request - want_dequeue, min_wait_time = self.callback(next_time, req_val) - self.next_min_flush_time = next_time + max(min_wait_time, - PIN_MIN_TIME) - if want_dequeue: - pos += 1 - del rqueue[:pos] + min_wait = 0. + ret = self.callback(next_time, req_val) + if ret is not None: + # Handle special cases + action, min_wait = ret + if action == "discard": + del rqueue[:pos+1] + continue + if action == "delay": + pos -= 1 + del rqueue[:pos+1] + self.next_min_flush_time = next_time + max(min_wait, PIN_MIN_TIME) # Ensure following queue items are flushed self.toolhead.note_mcu_movequeue_activity(self.next_min_flush_time) def queue_request(self, print_time, value): @@ -82,13 +88,13 @@ class PrinterOutputPin: def get_status(self, eventtime): return {'value': self.last_value} def _set_pin(self, print_time, value): - if value != self.last_value: - self.last_value = value - if self.is_pwm: - self.mcu_pin.set_pwm(print_time, value) - else: - self.mcu_pin.set_digital(print_time, value) - return (True, 0.) + if value == self.last_value: + return "discard", 0. + self.last_value = value + if self.is_pwm: + self.mcu_pin.set_pwm(print_time, value) + else: + self.mcu_pin.set_digital(print_time, value) cmd_SET_PIN_help = "Set the value of an output pin" def cmd_SET_PIN(self, gcmd): # Read requested value |