Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest Klipper3d/klipper (9f41f53c) #138

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions klippy/extras/bed_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -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):
Expand Down
Loading