mirror of
https://github.com/andreili/klipper.git
synced 2025-08-23 19:34:06 +02:00
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:
parent
6f685e9e01
commit
c09ca4cf5a
@ -13,6 +13,7 @@ class PrinterMotionQueuing:
|
|||||||
self.trapqs = []
|
self.trapqs = []
|
||||||
self.stepcompress = []
|
self.stepcompress = []
|
||||||
self.steppersyncs = []
|
self.steppersyncs = []
|
||||||
|
self.flush_callbacks = []
|
||||||
ffi_main, ffi_lib = chelper.get_ffi()
|
ffi_main, ffi_lib = chelper.get_ffi()
|
||||||
self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves
|
self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves
|
||||||
def allocate_trapq(self):
|
def allocate_trapq(self):
|
||||||
@ -40,7 +41,11 @@ class PrinterMotionQueuing:
|
|||||||
return ss
|
return ss
|
||||||
def register_stepper(self, config, stepper):
|
def register_stepper(self, config, stepper):
|
||||||
self.steppers.append(stepper)
|
self.steppers.append(stepper)
|
||||||
|
def register_flush_callback(self, callback):
|
||||||
|
self.flush_callbacks.append(callback)
|
||||||
def flush_motion_queues(self, must_flush_time, max_step_gen_time):
|
def flush_motion_queues(self, must_flush_time, max_step_gen_time):
|
||||||
|
for cb in self.flush_callbacks:
|
||||||
|
cb(must_flush_time)
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
stepper.generate_steps(max_step_gen_time)
|
stepper.generate_steps(max_step_gen_time)
|
||||||
def clean_motion_queues(self, trapq_free_time, clear_history_time):
|
def clean_motion_queues(self, trapq_free_time, clear_history_time):
|
||||||
|
@ -20,11 +20,12 @@ class GCodeRequestQueue:
|
|||||||
self.rqueue = []
|
self.rqueue = []
|
||||||
self.next_min_flush_time = 0.
|
self.next_min_flush_time = 0.
|
||||||
self.toolhead = None
|
self.toolhead = None
|
||||||
mcu.register_flush_callback(self._flush_notification)
|
motion_queuing = printer.load_object(config, 'motion_queuing')
|
||||||
|
motion_queuing.register_flush_callback(self._flush_notification)
|
||||||
printer.register_event_handler("klippy:connect", self._handle_connect)
|
printer.register_event_handler("klippy:connect", self._handle_connect)
|
||||||
def _handle_connect(self):
|
def _handle_connect(self):
|
||||||
self.toolhead = self.printer.lookup_object('toolhead')
|
self.toolhead = self.printer.lookup_object('toolhead')
|
||||||
def _flush_notification(self, print_time, clock):
|
def _flush_notification(self, print_time):
|
||||||
min_sched_time = self.mcu.min_schedule_time()
|
min_sched_time = self.mcu.min_schedule_time()
|
||||||
rqueue = self.rqueue
|
rqueue = self.rqueue
|
||||||
while rqueue:
|
while rqueue:
|
||||||
|
@ -46,12 +46,13 @@ class MCU_queued_pwm:
|
|||||||
self._start_value = max(0., min(1., start_value))
|
self._start_value = max(0., min(1., start_value))
|
||||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||||
def _build_config(self):
|
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:
|
if self._max_duration and self._start_value != self._shutdown_value:
|
||||||
raise config_error("Pin with max duration must have start"
|
raise config_error("Pin with max duration must have start"
|
||||||
" value equal to shutdown value")
|
" value equal to shutdown value")
|
||||||
cmd_queue = self._mcu.alloc_command_queue()
|
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)
|
printtime = self._mcu.estimated_print_time(curtime)
|
||||||
self._last_clock = self._mcu.print_time_to_clock(printtime + 0.200)
|
self._last_clock = self._mcu.print_time_to_clock(printtime + 0.200)
|
||||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||||
@ -61,7 +62,8 @@ class MCU_queued_pwm:
|
|||||||
if self._duration_ticks >= 1<<31:
|
if self._duration_ticks >= 1<<31:
|
||||||
raise config_error("PWM pin max duration too large")
|
raise config_error("PWM pin max duration too large")
|
||||||
if self._duration_ticks:
|
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:
|
if self._hardware_pwm:
|
||||||
self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
|
self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
|
||||||
self._default_value = self._shutdown_value * self._pwm_max
|
self._default_value = self._shutdown_value * self._pwm_max
|
||||||
@ -122,7 +124,8 @@ class MCU_queued_pwm:
|
|||||||
value = 1. - value
|
value = 1. - value
|
||||||
v = int(max(0., min(1., value)) * self._pwm_max + 0.5)
|
v = int(max(0., min(1., value)) * self._pwm_max + 0.5)
|
||||||
self._send_update(clock, v)
|
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:
|
if self._last_value != self._default_value:
|
||||||
while clock >= self._last_clock + self._duration_ticks:
|
while clock >= self._last_clock + self._duration_ticks:
|
||||||
self._send_update(self._last_clock + self._duration_ticks,
|
self._send_update(self._last_clock + self._duration_ticks,
|
||||||
|
@ -606,7 +606,6 @@ class MCU:
|
|||||||
minval=0.)
|
minval=0.)
|
||||||
self._reserved_move_slots = 0
|
self._reserved_move_slots = 0
|
||||||
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.
|
||||||
@ -971,16 +970,12 @@ class MCU:
|
|||||||
# Move queue tracking
|
# Move queue tracking
|
||||||
def request_move_queue_slot(self):
|
def request_move_queue_slot(self):
|
||||||
self._reserved_move_slots += 1
|
self._reserved_move_slots += 1
|
||||||
def register_flush_callback(self, callback):
|
|
||||||
self._flush_callbacks.append(callback)
|
|
||||||
def flush_moves(self, print_time, clear_history_time):
|
def flush_moves(self, print_time, clear_history_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)
|
|
||||||
clear_history_clock = \
|
clear_history_clock = \
|
||||||
max(0, self.print_time_to_clock(clear_history_time))
|
max(0, self.print_time_to_clock(clear_history_time))
|
||||||
ret = self._ffi_lib.steppersync_flush(self._steppersync, clock,
|
ret = self._ffi_lib.steppersync_flush(self._steppersync, clock,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user