From 739e6e73963effdd64677872af87a303cd68c3de Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 6 Jun 2020 14:41:15 -0400 Subject: [PATCH] extruder_stepper: Don't directly access extruder member variables Rework extruder.get_trapq() into extruder.sync_stepper() so that extruder_stepper.py does not need to directly access the extruder internals. Signed-off-by: Kevin O'Connor --- klippy/extras/extruder_stepper.py | 21 ++++++++------------- klippy/kinematics/extruder.py | 6 ++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/klippy/extras/extruder_stepper.py b/klippy/extras/extruder_stepper.py index 58f16375..9678472a 100644 --- a/klippy/extras/extruder_stepper.py +++ b/klippy/extras/extruder_stepper.py @@ -23,23 +23,18 @@ class ExtruderStepper: desc=self.cmd_SYNC_STEPPER_TO_EXTRUDER_help) def handle_connect(self): extruder = self.printer.lookup_object(self.extruder_name) - self.stepper.set_trapq(extruder.get_trapq()) + extruder.sync_stepper(self.stepper) toolhead = self.printer.lookup_object('toolhead') toolhead.register_step_generator(self.stepper.generate_steps) cmd_SYNC_STEPPER_TO_EXTRUDER_help = "Set extruder stepper" def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd): - gcode = self.printer.lookup_object('gcode') - self.extruder_name = gcmd.get('EXTRUDER', None) - extruder = self.printer.lookup_object(self.extruder_name, None) - if extruder is not None: - epos = extruder.stepper.get_commanded_position() - self.stepper.set_position([epos, 0., 0.]) - self.stepper.set_trapq(extruder.get_trapq()) - gcode.respond_info("Extruder stepper now syncing with '%s'" - % (self.extruder_name)) - else: - raise gcmd.error("'%s' is not a valid extruder." - % (self.extruder_name)) + ename = gcmd.get('EXTRUDER') + extruder = self.printer.lookup_object(ename, None) + if extruder is None: + raise gcmd.error("'%s' is not a valid extruder." % (ename,)) + extruder.sync_stepper(self.stepper) + self.extruder_name = ename + gcmd.respond_info("Extruder stepper now syncing with '%s'" % (ename,)) def load_config_prefix(config): return ExtruderStepper(config) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index c0ba299c..3a03b606 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -98,8 +98,10 @@ class PrinterExtruder: return self.name def get_heater(self): return self.heater - def get_trapq(self): - return self.trapq + def sync_stepper(self, stepper): + epos = self.stepper.get_commanded_position() + stepper.set_position([epos, 0., 0.]) + stepper.set_trapq(self.trapq) def stats(self, eventtime): return self.heater.stats(eventtime) def check_move(self, move):