aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-09-15 00:03:58 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-09-16 13:31:14 -0400
commit69e0d866c02a93072ea6aeaaec230b6939ba7604 (patch)
tree8b34790d7e06f2649d462bcc0d52d703aeba1ec7 /klippy
parent0532a41c752df66f149cf55d779072f420ee1b6a (diff)
downloadkutter-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')
-rw-r--r--klippy/extras/output_pin.py32
-rw-r--r--klippy/extras/servo.py8
2 files changed, 23 insertions, 17 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
diff --git a/klippy/extras/servo.py b/klippy/extras/servo.py
index 10537e67..f1ce9976 100644
--- a/klippy/extras/servo.py
+++ b/klippy/extras/servo.py
@@ -45,10 +45,10 @@ class PrinterServo:
def get_status(self, eventtime):
return {'value': self.last_value}
def _set_pwm(self, print_time, value):
- if value != self.last_value:
- self.last_value = value
- self.mcu_servo.set_pwm(print_time, value)
- return (True, 0.)
+ if value == self.last_value:
+ return "discard", 0.
+ self.last_value = value
+ self.mcu_servo.set_pwm(print_time, value)
def _get_pwm_from_angle(self, angle):
angle = max(0., min(self.max_angle, angle))
width = self.min_width + angle * self.angle_to_width