motion_queuing: Add register_flush_callback()

Move register_flush_callback() from mcu.py code to motion_queuing
module.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2025-08-05 00:06:32 -04:00
parent 6f685e9e01
commit c09ca4cf5a
4 changed files with 15 additions and 11 deletions

View File

@@ -46,12 +46,13 @@ class MCU_queued_pwm:
self._start_value = max(0., min(1., start_value))
self._shutdown_value = max(0., min(1., shutdown_value))
def _build_config(self):
config_error = self._mcu.get_printer().config_error
printer = self._mcu.get_printer()
config_error = printer.config_error
if self._max_duration and self._start_value != self._shutdown_value:
raise config_error("Pin with max duration must have start"
" value equal to shutdown value")
cmd_queue = self._mcu.alloc_command_queue()
curtime = self._mcu.get_printer().get_reactor().monotonic()
curtime = printer.get_reactor().monotonic()
printtime = self._mcu.estimated_print_time(curtime)
self._last_clock = self._mcu.print_time_to_clock(printtime + 0.200)
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
@@ -61,7 +62,8 @@ class MCU_queued_pwm:
if self._duration_ticks >= 1<<31:
raise config_error("PWM pin max duration too large")
if self._duration_ticks:
self._mcu.register_flush_callback(self._flush_notification)
motion_queuing = printer.lookup_object('motion_queuing')
motion_queuing.register_flush_callback(self._flush_notification)
if self._hardware_pwm:
self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
self._default_value = self._shutdown_value * self._pwm_max
@@ -122,7 +124,8 @@ class MCU_queued_pwm:
value = 1. - value
v = int(max(0., min(1., value)) * self._pwm_max + 0.5)
self._send_update(clock, v)
def _flush_notification(self, print_time, clock):
def _flush_notification(self, print_time):
clock = self._mcu.print_time_to_clock(print_time)
if self._last_value != self._default_value:
while clock >= self._last_clock + self._duration_ticks:
self._send_update(self._last_clock + self._duration_ticks,