aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-01-02 19:32:10 -0500
committerKevin O'Connor <kevin@koconnor.net>2020-01-03 18:13:57 -0500
commit8158dbcc21fed0a7b703d904c9f34692d8ab5ef7 (patch)
tree1884413651f3301d2d5afa11c2a12938a32e2eb7
parent4b6a65c1e03a889e6004c00f301164495965e49c (diff)
downloadkutter-8158dbcc21fed0a7b703d904c9f34692d8ab5ef7.tar.gz
kutter-8158dbcc21fed0a7b703d904c9f34692d8ab5ef7.tar.xz
kutter-8158dbcc21fed0a7b703d904c9f34692d8ab5ef7.zip
toolhead: Add register_lookahead_callback() method
Add a mechanism for obtaining the print_time via a callback instead of by flushing the look-ahead queue. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/toolhead.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 51d39148..85e4be53 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -17,6 +17,7 @@ class Move:
self.start_pos = tuple(start_pos)
self.end_pos = tuple(end_pos)
self.accel = toolhead.max_accel
+ self.timing_callbacks = []
velocity = min(speed, toolhead.max_velocity)
self.is_kinematic_move = True
self.axes_d = axes_d = [end_pos[i] - start_pos[i] for i in (0, 1, 2, 3)]
@@ -112,6 +113,10 @@ class MoveQueue:
self.junction_flush = LOOKAHEAD_FLUSH_TIME
def set_flush_time(self, flush_time):
self.junction_flush = flush_time
+ def get_last(self):
+ if self.queue:
+ return self.queue[-1]
+ return None
def flush(self, lazy=False):
self.junction_flush = LOOKAHEAD_FLUSH_TIME
update_flush_count = lazy
@@ -314,6 +319,8 @@ class ToolHead:
self.extruder.move(next_move_time, move)
next_move_time = (next_move_time + move.accel_t
+ move.cruise_t + move.decel_t)
+ for cb in move.timing_callbacks:
+ cb(next_move_time)
# Generate steps for moves
if self.special_queuing_state:
self._update_drip_move_time(next_move_time)
@@ -507,6 +514,12 @@ class ToolHead:
self.kin_flush_times.append(delay)
new_delay = max(self.kin_flush_times + [0.])
self.kin_flush_delay = new_delay
+ def register_lookahead_callback(self, callback):
+ last_move = self.move_queue.get_last()
+ if last_move is None:
+ callback(self.get_last_move_time())
+ return
+ last_move.timing_callbacks.append(callback)
def note_kinematic_activity(self, kin_time):
self.last_kin_move_time = max(self.last_kin_move_time, kin_time)
def get_max_velocity(self):