mcu: Add support for registering callbacks during move queue flush

Support notification callbacks each time the mcu move queue is
flushed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-11-30 11:12:55 -05:00
parent 19862bc3b7
commit 1e5f688b53
1 changed files with 17 additions and 11 deletions

View File

@ -606,6 +606,7 @@ class MCU:
self._reserved_move_slots = 0 self._reserved_move_slots = 0
self._stepqueues = [] self._stepqueues = []
self._steppersync = None self._steppersync = None
self._flush_callbacks = []
# Stats # Stats
self._get_status_info = {} self._get_status_info = {}
self._stats_sumsq_base = 0. self._stats_sumsq_base = 0.
@ -854,10 +855,6 @@ class MCU:
slot = self.seconds_to_clock(oid * .01) slot = self.seconds_to_clock(oid * .01)
t = int(self.estimated_print_time(self._reactor.monotonic()) + 1.5) t = int(self.estimated_print_time(self._reactor.monotonic()) + 1.5)
return self.print_time_to_clock(t) + slot return self.print_time_to_clock(t) + slot
def register_stepqueue(self, stepqueue):
self._stepqueues.append(stepqueue)
def request_move_queue_slot(self):
self._reserved_move_slots += 1
def seconds_to_clock(self, time): def seconds_to_clock(self, time):
return int(time * self._mcu_freq) return int(time * self._mcu_freq)
def get_max_stepper_error(self): def get_max_stepper_error(self):
@ -951,19 +948,21 @@ class MCU:
self._restart_arduino() self._restart_arduino()
def _firmware_restart_bridge(self): def _firmware_restart_bridge(self):
self._firmware_restart(True) self._firmware_restart(True)
# Misc external commands # Move queue tracking
def is_fileoutput(self): def register_stepqueue(self, stepqueue):
return self._printer.get_start_args().get('debugoutput') is not None self._stepqueues.append(stepqueue)
def is_shutdown(self): def request_move_queue_slot(self):
return self._is_shutdown self._reserved_move_slots += 1
def get_shutdown_clock(self): def register_flush_callback(self, callback):
return self._shutdown_clock self._flush_callbacks.append(callback)
def flush_moves(self, print_time): def flush_moves(self, print_time):
if self._steppersync is None: if self._steppersync is None:
return return
clock = self.print_time_to_clock(print_time) clock = self.print_time_to_clock(print_time)
if clock < 0: if clock < 0:
return return
for cb in self._flush_callbacks:
cb(print_time, clock)
ret = self._ffi_lib.steppersync_flush(self._steppersync, clock) ret = self._ffi_lib.steppersync_flush(self._steppersync, clock)
if ret: if ret:
raise error("Internal error in MCU '%s' stepcompress" raise error("Internal error in MCU '%s' stepcompress"
@ -981,6 +980,13 @@ class MCU:
self._name, eventtime) self._name, eventtime)
self._printer.invoke_shutdown("Lost communication with MCU '%s'" % ( self._printer.invoke_shutdown("Lost communication with MCU '%s'" % (
self._name,)) self._name,))
# Misc external commands
def is_fileoutput(self):
return self._printer.get_start_args().get('debugoutput') is not None
def is_shutdown(self):
return self._is_shutdown
def get_shutdown_clock(self):
return self._shutdown_clock
def get_status(self, eventtime=None): def get_status(self, eventtime=None):
return dict(self._get_status_info) return dict(self._get_status_info)
def stats(self, eventtime): def stats(self, eventtime):