From ba940da9b508b859b41d12cf7119c21694d85296 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 18 Feb 2021 15:39:55 -0500 Subject: [PATCH] stepper: Don't cache ffi_lib object in the stepper It's easier to just call chelper.get_ffi() if the ffi_lib object is needed. Signed-off-by: Kevin O'Connor --- klippy/stepper.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/klippy/stepper.py b/klippy/stepper.py index 8ba0b5f1..b3da9237 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -35,13 +35,13 @@ class MCU_stepper: self._min_stop_interval = 0. self._reset_cmd_tag = self._get_position_cmd = None self._active_callbacks = [] - ffi_main, self._ffi_lib = chelper.get_ffi() - self._stepqueue = ffi_main.gc(self._ffi_lib.stepcompress_alloc(oid), - self._ffi_lib.stepcompress_free) + ffi_main, ffi_lib = chelper.get_ffi() + self._stepqueue = ffi_main.gc(ffi_lib.stepcompress_alloc(oid), + ffi_lib.stepcompress_free) self._mcu.register_stepqueue(self._stepqueue) self._stepper_kinematics = None - self._itersolve_generate_steps = self._ffi_lib.itersolve_generate_steps - self._itersolve_check_active = self._ffi_lib.itersolve_check_active + self._itersolve_generate_steps = ffi_lib.itersolve_generate_steps + self._itersolve_check_active = ffi_lib.itersolve_check_active self._trapq = ffi_main.NULL def get_mcu(self): return self._mcu @@ -87,9 +87,10 @@ class MCU_stepper: self._get_position_cmd = self._mcu.lookup_query_command( "stepper_get_position oid=%c", "stepper_position oid=%c pos=%i", oid=self._oid) - self._ffi_lib.stepcompress_fill( - self._stepqueue, self._mcu.seconds_to_clock(max_error), - self._invert_dir, step_cmd_tag, dir_cmd_tag) + ffi_main, ffi_lib = chelper.get_ffi() + ffi_lib.stepcompress_fill(self._stepqueue, + self._mcu.seconds_to_clock(max_error), + self._invert_dir, step_cmd_tag, dir_cmd_tag) def get_oid(self): return self._oid def get_step_dist(self): @@ -100,16 +101,19 @@ class MCU_stepper: def is_dir_inverted(self): return self._invert_dir def calc_position_from_coord(self, coord): - return self._ffi_lib.itersolve_calc_position_from_coord( + ffi_main, ffi_lib = chelper.get_ffi() + return ffi_lib.itersolve_calc_position_from_coord( self._stepper_kinematics, coord[0], coord[1], coord[2]) def set_position(self, coord): opos = self.get_commanded_position() sk = self._stepper_kinematics - self._ffi_lib.itersolve_set_position(sk, coord[0], coord[1], coord[2]) + ffi_main, ffi_lib = chelper.get_ffi() + ffi_lib.itersolve_set_position(sk, coord[0], coord[1], coord[2]) self._mcu_position_offset += opos - self.get_commanded_position() def get_commanded_position(self): sk = self._stepper_kinematics - return self._ffi_lib.itersolve_get_commanded_pos(sk) + ffi_main, ffi_lib = chelper.get_ffi() + return ffi_lib.itersolve_get_commanded_pos(sk) def get_mcu_position(self): mcu_pos_dist = self.get_commanded_position() + self._mcu_position_offset mcu_pos = mcu_pos_dist / self._step_dist @@ -124,17 +128,18 @@ class MCU_stepper: old_sk = self._stepper_kinematics self._stepper_kinematics = sk if sk is not None: - self._ffi_lib.itersolve_set_stepcompress(sk, self._stepqueue, - self._step_dist) + ffi_main, ffi_lib = chelper.get_ffi() + ffi_lib.itersolve_set_stepcompress(sk, self._stepqueue, + self._step_dist) self.set_trapq(self._trapq) return old_sk def note_homing_end(self, did_trigger=False): - ret = self._ffi_lib.stepcompress_reset(self._stepqueue, 0) + ffi_main, ffi_lib = chelper.get_ffi() + ret = ffi_lib.stepcompress_reset(self._stepqueue, 0) if ret: raise error("Internal error in stepcompress") data = (self._reset_cmd_tag, self._oid, 0) - ret = self._ffi_lib.stepcompress_queue_msg(self._stepqueue, data, - len(data)) + ret = ffi_lib.stepcompress_queue_msg(self._stepqueue, data, len(data)) if ret: raise error("Internal error in stepcompress") if not did_trigger or self._mcu.is_fileoutput(): @@ -145,10 +150,10 @@ class MCU_stepper: mcu_pos_dist = -mcu_pos_dist self._mcu_position_offset = mcu_pos_dist - self.get_commanded_position() def set_trapq(self, tq): + ffi_main, ffi_lib = chelper.get_ffi() if tq is None: - ffi_main, self._ffi_lib = chelper.get_ffi() tq = ffi_main.NULL - self._ffi_lib.itersolve_set_trapq(self._stepper_kinematics, tq) + ffi_lib.itersolve_set_trapq(self._stepper_kinematics, tq) old_tq = self._trapq self._trapq = tq return old_tq @@ -170,8 +175,8 @@ class MCU_stepper: if ret: raise error("Internal error in stepcompress") def is_active_axis(self, axis): - return self._ffi_lib.itersolve_is_active_axis( - self._stepper_kinematics, axis) + ffi_main, ffi_lib = chelper.get_ffi() + return ffi_lib.itersolve_is_active_axis(self._stepper_kinematics, axis) # Helper code to build a stepper object from a config section def PrinterStepper(config, units_in_radians=False):