diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 30250f8e5..5edfd8f10 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -281,7 +281,7 @@ def update_status(self): mesh_max = (params["max_x"], params["max_y"]) probed_matrix = self.z_mesh.get_probed_matrix() mesh_matrix = self.z_mesh.get_mesh_matrix() - self.status["profile_name"] = self.pmgr.get_current_profile() + self.status["profile_name"] = self.z_mesh.get_profile_name() self.status["mesh_min"] = mesh_min self.status["mesh_max"] = mesh_max self.status["probed_matrix"] = probed_matrix @@ -374,7 +374,7 @@ def __init__(self, config, bedmesh): self.mesh_config = collections.OrderedDict() self._init_mesh_config(config) self._generate_points(config.error) - self._profile_name = None + self._profile_name = "default" self.probe_helper = probe.ProbePointsHelper( config, self.probe_finalize, self._get_adjusted_points() ) @@ -387,7 +387,7 @@ def __init__(self, config, bedmesh): desc=self.cmd_BED_MESH_CALIBRATE_help, ) - def _generate_points(self, error): + def _generate_points(self, error, probe_method="automatic"): x_cnt = self.mesh_config["x_count"] y_cnt = self.mesh_config["y_count"] min_x, min_y = self.mesh_min @@ -437,7 +437,7 @@ def _generate_points(self, error): if rri >= len(self.points): raise error("bed_mesh: relative reference index out of range") self.zero_ref_pos = points[rri] - if self.zero_ref_pos is None: + if self.zero_ref_pos is None or probe_method == "manual": # Zero Reference Disabled self.zero_reference_mode = ZrefMode.DISABLED elif within(self.zero_ref_pos, self.mesh_min, self.mesh_max): @@ -467,6 +467,8 @@ def _generate_points(self, error): ) ) # Check to see if any points fall within faulty regions + if probe_method == "manual": + return last_y = self.points[0][1] is_reversed = False for i, coord in enumerate(self.points): @@ -854,10 +856,11 @@ def update_config(self, gcmd): need_cfg_update = True need_cfg_update |= self.set_adaptive_mesh(gcmd) + probe_method = gcmd.get("METHOD", "automatic") if need_cfg_update: self._verify_algorithm(gcmd.error) - self._generate_points(gcmd.error) + self._generate_points(gcmd.error, probe_method) gcmd.respond_info("Generating new points...") self.print_generated_points(gcmd.respond_info) pts = self._get_adjusted_points() @@ -870,7 +873,7 @@ def update_config(self, gcmd): ) logging.info("Updated Mesh Configuration:\n" + msg) else: - self._generate_points(gcmd.error) + self._generate_points(gcmd.error, probe_method) pts = self._get_adjusted_points() self.probe_helper.update_probe_points(pts, 3) @@ -1024,7 +1027,7 @@ def probe_finalize(self, offsets, positions): % (len(probed_matrix), str(probed_matrix)) ) - z_mesh = ZMesh(params) + z_mesh = ZMesh(params, self._profile_name) try: z_mesh.build_mesh(probed_matrix) except BedMeshError as e: @@ -1140,7 +1143,8 @@ def split(self): class ZMesh: - def __init__(self, params): + def __init__(self, params, name): + self.profile_name = name or "adaptive-%X" % (id(self),) self.probed_matrix = self.mesh_matrix = None self.mesh_params = params self.mesh_offsets = [0.0, 0.0] @@ -1200,6 +1204,9 @@ def get_probed_matrix(self): def get_mesh_params(self): return self.mesh_params + def get_profile_name(self): + return self.profile_name + def print_probed_matrix(self, print_func): if self.probed_matrix is not None: msg = "Mesh Leveling Probed Z positions:\n" @@ -1486,7 +1493,6 @@ def __init__(self, config, bedmesh): self.gcode = self.printer.lookup_object("gcode") self.bedmesh = bedmesh self.profiles = {} - self.current_profile = "" self.incompatible_profiles = [] # Fetch stored profiles from Config stored_profs = config.get_prefix_sections(self.name) @@ -1525,9 +1531,6 @@ def __init__(self, config, bedmesh): def get_profiles(self): return self.profiles - def get_current_profile(self): - return self.current_profile - def _check_incompatible_profiles(self): if self.incompatible_profiles: configfile = self.printer.lookup_object("configfile") @@ -1571,7 +1574,6 @@ def save_profile(self, prof_name): profile["points"] = probed_matrix profile["mesh_params"] = collections.OrderedDict(mesh_params) self.profiles = profiles - self.current_profile = prof_name self.bedmesh.update_status() self.gcode.respond_info( "Bed Mesh state has been saved to profile [%s]\n" @@ -1586,12 +1588,11 @@ def load_profile(self, prof_name): raise self.gcode.error("bed_mesh: Unknown profile [%s]" % prof_name) probed_matrix = profile["points"] mesh_params = profile["mesh_params"] - z_mesh = ZMesh(mesh_params) + z_mesh = ZMesh(mesh_params, prof_name) try: z_mesh.build_mesh(probed_matrix) except BedMeshError as e: raise self.gcode.error(str(e)) - self.current_profile = prof_name self.bedmesh.set_mesh(z_mesh) def remove_profile(self, prof_name):