diff --git a/klippy/extras/motion_queuing.py b/klippy/extras/motion_queuing.py index 91060019..55a7b929 100644 --- a/klippy/extras/motion_queuing.py +++ b/klippy/extras/motion_queuing.py @@ -13,6 +13,7 @@ class PrinterMotionQueuing: self.trapqs = [] self.stepcompress = [] self.steppersyncs = [] + self.flush_callbacks = [] ffi_main, ffi_lib = chelper.get_ffi() self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves def allocate_trapq(self): @@ -40,7 +41,11 @@ class PrinterMotionQueuing: return ss def register_stepper(self, config, 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): + for cb in self.flush_callbacks: + cb(must_flush_time) for stepper in self.steppers: stepper.generate_steps(max_step_gen_time) def clean_motion_queues(self, trapq_free_time, clear_history_time): diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py index 05266382..9eb8ea8b 100644 --- a/klippy/extras/output_pin.py +++ b/klippy/extras/output_pin.py @@ -20,11 +20,12 @@ class GCodeRequestQueue: self.rqueue = [] self.next_min_flush_time = 0. 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) def _handle_connect(self): 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() rqueue = self.rqueue while rqueue: diff --git a/klippy/extras/pwm_tool.py b/klippy/extras/pwm_tool.py index a0739b5b..69fc1a46 100644 --- a/klippy/extras/pwm_tool.py +++ b/klippy/extras/pwm_tool.py @@ -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, diff --git a/klippy/mcu.py b/klippy/mcu.py index d7665036..c8bc9c9b 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -606,7 +606,6 @@ class MCU: minval=0.) self._reserved_move_slots = 0 self._steppersync = None - self._flush_callbacks = [] # Stats self._get_status_info = {} self._stats_sumsq_base = 0. @@ -971,16 +970,12 @@ class MCU: # Move queue tracking 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, clear_history_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) clear_history_clock = \ max(0, self.print_time_to_clock(clear_history_time)) ret = self._ffi_lib.steppersync_flush(self._steppersync, clock,