From b17ec3d2e9d0afb96351a6ed26fba958584899ac Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 6 Aug 2021 09:56:06 -0400 Subject: [PATCH] stepcompress: Pass clock to stepcompress_set_last_position() Using sc->last_step_clock for the last position marker does not work properly, because the stepper.py code calls stepcompress_reset() prior to calling stepcompress_set_last_position(). Fix by passing an explicit clock to stepcompress_set_last_position(). Signed-off-by: Kevin O'Connor --- klippy/chelper/__init__.py | 2 +- klippy/chelper/stepcompress.c | 5 +++-- klippy/chelper/stepcompress.h | 2 +- klippy/stepper.py | 5 ++++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index 6c579ab7..86560939 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -43,7 +43,7 @@ defs_stepcompress = """ void stepcompress_free(struct stepcompress *sc); int stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock); int stepcompress_set_last_position(struct stepcompress *sc - , int64_t last_position); + , uint64_t clock, int64_t last_position); int64_t stepcompress_find_past_position(struct stepcompress *sc , uint64_t clock); int stepcompress_queue_msg(struct stepcompress *sc diff --git a/klippy/chelper/stepcompress.c b/klippy/chelper/stepcompress.c index fab15a2c..b38b72ad 100644 --- a/klippy/chelper/stepcompress.c +++ b/klippy/chelper/stepcompress.c @@ -553,7 +553,8 @@ stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock) // Set last_position in the stepcompress object int __visible -stepcompress_set_last_position(struct stepcompress *sc, int64_t last_position) +stepcompress_set_last_position(struct stepcompress *sc, uint64_t clock + , int64_t last_position) { int ret = stepcompress_flush(sc, UINT64_MAX); if (ret) @@ -563,7 +564,7 @@ stepcompress_set_last_position(struct stepcompress *sc, int64_t last_position) // Add a marker to the history list struct history_steps *hs = malloc(sizeof(*hs)); memset(hs, 0, sizeof(*hs)); - hs->first_clock = hs->last_clock = sc->last_step_clock; + hs->first_clock = hs->last_clock = clock; hs->start_position = last_position; list_add_head(&hs->node, &sc->history_list); return 0; diff --git a/klippy/chelper/stepcompress.h b/klippy/chelper/stepcompress.h index d10cccf9..5bca39a5 100644 --- a/klippy/chelper/stepcompress.h +++ b/klippy/chelper/stepcompress.h @@ -22,7 +22,7 @@ int stepcompress_append(struct stepcompress *sc, int sdir , double print_time, double step_time); int stepcompress_commit(struct stepcompress *sc); int stepcompress_reset(struct stepcompress *sc, uint64_t last_step_clock); -int stepcompress_set_last_position(struct stepcompress *sc +int stepcompress_set_last_position(struct stepcompress *sc, uint64_t clock , int64_t last_position); int64_t stepcompress_find_past_position(struct stepcompress *sc , uint64_t clock); diff --git a/klippy/stepper.py b/klippy/stepper.py index b92c78ce..ca7df28f 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -151,7 +151,10 @@ class MCU_stepper: last_pos = params['pos'] if self._invert_dir: last_pos = -last_pos - ret = ffi_lib.stepcompress_set_last_position(self._stepqueue, last_pos) + print_time = self._mcu.estimated_print_time(params['#receive_time']) + clock = self._mcu.print_time_to_clock(print_time) + ret = ffi_lib.stepcompress_set_last_position(self._stepqueue, clock, + last_pos) if ret: raise error("Internal error in stepcompress") self._set_mcu_position(last_pos)