diff --git a/README.md b/README.md index 32f9703..1890d05 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ cd AFC-Klipper-Add-On To update the AFC plugin software, you can simply run the following command: ```bash +cd AFC-Klipper-Add-On ./install-afc.sh ``` The update process should be non-destructive and will not overwrite any existing configuration files without your permission. diff --git a/extras/AFC_BoxTurtle.py b/extras/AFC_BoxTurtle.py index 78174ee..14a8564 100644 --- a/extras/AFC_BoxTurtle.py +++ b/extras/AFC_BoxTurtle.py @@ -133,6 +133,22 @@ def cmd_CALIBRATE_AFC(self, gcmd): cal_msg = '' + def find_lane_to_calibrate(lane_name): + """ + Search for the given lane across all units in the AFC system. + + Args: lane_name: The name of the lane to search for + + Returns: The lane name if found, otherwise None + """ + for UNIT in self.AFC.lanes.keys(): + if lane_name in self.AFC.lanes[UNIT]: + return lane_name + + # If the lane was not found + self.AFC.gcode.respond_info('{} not found in any unit.'.format(lane_name)) + return None + # Helper functions for movement and calibration def calibrate_hub(CUR_LANE, CUR_HUB): hub_pos = 0 @@ -192,18 +208,13 @@ def calibrate_lane(LANE): cal_msg += 'AFC Calibration distances +/-{}mm'.format(tol) cal_msg += '\nUpdate values in AFC_Hardware.cfg' if lanes != 'all': - lane_to_calibrate = None - # Search for the lane within the units - for UNIT in self.AFC.lanes.keys(): - if lanes in self.AFC.lanes[UNIT]: - lane_to_calibrate = lanes - break + lane_to_calibrate = find_lane_to_calibrate(lanes) + if lane_to_calibrate is None: - self.AFC.gcode.respond_info('{} not found in any unit.'.format(lanes)) return # Calibrate the specific lane - checked, msg = calibrate_lane(lanes) + checked, msg = calibrate_lane(lane_to_calibrate) if(not checked): return cal_msg += msg else: @@ -223,7 +234,13 @@ def calibrate_lane(LANE): self.AFC.gcode.respond_info('Starting AFC distance Calibrations') cal_msg += 'AFC Calibration distances +/-{}mm'.format(tol) cal_msg += '\nUpdate values in AFC_Hardware.cfg' - lane = afc_bl + + lane_to_calibrate = find_lane_to_calibrate(afc_bl) + + if lane_to_calibrate is None: + return + + lane = lane_to_calibrate CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane) CUR_EXTRUDER = self.printer.lookup_object('AFC_extruder ' + CUR_LANE.extruder_name) CUR_HUB = self.printer.lookup_object('AFC_hub ' + CUR_LANE.unit) diff --git a/extras/AFC_spool.py b/extras/AFC_spool.py index 86ccbf6..8f3f3dd 100644 --- a/extras/AFC_spool.py +++ b/extras/AFC_spool.py @@ -112,7 +112,7 @@ def cmd_SET_WEIGHT(self, gcmd): Args: gcmd: The G-code command object containing the parameters for the command. Expected parameters: - + LANE: The name of the lane whose weight is to be changed. WEIGHT: The new weight (optional, defaults to ''). @@ -141,7 +141,7 @@ def cmd_SET_MATERIAL(self, gcmd): Args: gcmd: The G-code command object containing the parameters for the command. Expected parameters: - + LANE: The name of the lane whose material is to be changed. MATERIAL: The new material (optional, defaults to ''). @@ -157,7 +157,6 @@ def cmd_SET_MATERIAL(self, gcmd): CUR_LANE.material = material self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = material self.AFC.save_vars() - def set_active_spool(self, ID): webhooks = self.printer.lookup_object('webhooks') if self.AFC.spoolman_ip != None: