Skip to content

Commit

Permalink
mcu: Add support for registering callbacks during move queue flush
Browse files Browse the repository at this point in the history
Support notification callbacks each time the mcu move queue is
flushed.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Dec 16, 2023
1 parent 19862bc commit 1e5f688
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ def __init__(self, config, clocksync):
self._reserved_move_slots = 0
self._stepqueues = []
self._steppersync = None
self._flush_callbacks = []
# Stats
self._get_status_info = {}
self._stats_sumsq_base = 0.
Expand Down Expand Up @@ -854,10 +855,6 @@ def get_query_slot(self, oid):
slot = self.seconds_to_clock(oid * .01)
t = int(self.estimated_print_time(self._reactor.monotonic()) + 1.5)
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):
return int(time * self._mcu_freq)
def get_max_stepper_error(self):
Expand Down Expand Up @@ -951,19 +948,21 @@ def _firmware_restart(self, force=False):
self._restart_arduino()
def _firmware_restart_bridge(self):
self._firmware_restart(True)
# 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
# Move queue tracking
def register_stepqueue(self, stepqueue):
self._stepqueues.append(stepqueue)
def request_move_queue_slot(self):
self._reserved_move_slots += 1
def register_flush_callback(self, callback):
self._flush_callbacks.append(callback)
def flush_moves(self, print_time):
if self._steppersync is None:
return
clock = self.print_time_to_clock(print_time)
if clock < 0:
return
for cb in self._flush_callbacks:
cb(print_time, clock)
ret = self._ffi_lib.steppersync_flush(self._steppersync, clock)
if ret:
raise error("Internal error in MCU '%s' stepcompress"
Expand All @@ -981,6 +980,13 @@ def check_active(self, print_time, eventtime):
self._name, eventtime)
self._printer.invoke_shutdown("Lost communication with MCU '%s'" % (
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):
return dict(self._get_status_info)
def stats(self, eventtime):
Expand Down

0 comments on commit 1e5f688

Please sign in to comment.