From af075cdf65debb352f82bcd6e8fea35f07a30fc1 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Wed, 29 May 2024 13:59:24 -0300 Subject: [PATCH] bed_mesh: change how profiles with points instead of matrix are handled --- ks_includes/printer.py | 17 ----------------- ks_includes/widgets/bedmap.py | 15 ++++++++++++--- panels/zcalibrate.py | 5 ++++- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/ks_includes/printer.py b/ks_includes/printer.py index 6a1ff6dd..932e3c33 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -78,8 +78,6 @@ class Printer: self.output_pin_count += 1 elif section == "pwm_tool": self.pwm_tools_count += 1 - elif section == "bed_mesh": - self.process_bed_mesh(x) elif section in ( "led", "neopixel", @@ -90,9 +88,7 @@ class Printer: self.ledcount += 1 self.tools = sorted(self.tools) - self.log_counts(printer_info) - self.process_update(data) def log_counts(self, printer_info): @@ -104,19 +100,6 @@ class Printer: logging.info(f"# PWM tools: {self.pwm_tools_count}") logging.info(f"# Leds: {self.ledcount}") - def process_bed_mesh(self, x): - try: - r = self.config[x] - r['x_count'] = int(r['x_count']) - r['y_count'] = int(r['y_count']) - r['max_x'] = float(r['max_x']) - r['min_x'] = float(r['min_x']) - r['max_y'] = float(r['max_y']) - r['min_y'] = float(r['min_y']) - r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")] - except KeyError: - logging.debug(f"Couldn't load mesh {x}: {self.config[x]}") - def stop_tempstore_updates(self): if self.store_timeout is not None: GLib.source_remove(self.store_timeout) diff --git a/ks_includes/widgets/bedmap.py b/ks_includes/widgets/bedmap.py index 91e2ba43..e910d9c0 100644 --- a/ks_includes/widgets/bedmap.py +++ b/ks_includes/widgets/bedmap.py @@ -29,17 +29,20 @@ class BedMap(Gtk.DrawingArea): for key, value in bm.items(): if key == 'profiles': continue - logging.info(f"{key}: {value}") if radius: self.mesh_radius = float(radius) if 'mesh_min' in bm: self.mesh_min = bm['mesh_min'] + elif 'min_x' in bm and 'min_y' in bm: + self.mesh_min = (float(bm['min_x']), float(bm['min_y'])) if 'mesh_max' in bm: self.mesh_max = bm['mesh_max'] + elif 'max_x' in bm and 'max_y' in bm: + self.mesh_max = (float(bm['max_x']), float(bm['max_y'])) if 'probed_matrix' in bm: bm = bm['probed_matrix'] elif 'points' in bm: - bm = bm['points'] + bm = self.transform_points_to_matrix(bm['points']) else: self.bm = None return @@ -65,6 +68,11 @@ class BedMap(Gtk.DrawingArea): if self.rotation in (90, 180, 270): self.bm = self.rotate_matrix(self.bm) + @staticmethod + def transform_points_to_matrix(points): + rows = points.strip().split('\n') + return [list(map(float, row.split(','))) for row in rows] + def rotate_matrix(self, matrix): if self.rotation == 90: new_max = [self.mesh_max[1], self.mesh_min[0]] @@ -132,6 +140,7 @@ class BedMap(Gtk.DrawingArea): for i, row in enumerate(self.bm): ty = (gheight / rows * i) by = ty + gheight / rows + column: float for j, column in enumerate(row): if self.mesh_radius > 0 and self.round_bed_skip(i, j, row, rows, columns): continue @@ -170,7 +179,7 @@ class BedMap(Gtk.DrawingArea): return False @staticmethod - def colorbar(value): + def colorbar(value: float): rmax = 0.25 color = min(1, max(0, 1 - 1 / rmax * abs(value))) if value > 0: diff --git a/panels/zcalibrate.py b/panels/zcalibrate.py index 2f92ffdc..8ad1ea12 100644 --- a/panels/zcalibrate.py +++ b/panels/zcalibrate.py @@ -128,9 +128,12 @@ class Panel(ScreenPanel): if 'mesh_origin' in mesh: self.mesh_origin = self._csv_to_array(mesh['mesh_origin']) logging.info(f"Mesh Radius: {self.mesh_radius} Origin: {self.mesh_origin}") - else: + elif 'mesh_min' in mesh and 'mesh_max' in mesh: self.mesh_min = self._csv_to_array(mesh['mesh_min']) self.mesh_max = self._csv_to_array(mesh['mesh_max']) + elif 'min_x' in mesh and 'min_y' in mesh and 'max_x' in mesh and 'max_y' in mesh: + self.mesh_min = [float(mesh['min_x']), float(mesh['min_y'])] + self.mesh_max = [float(mesh['max_x']), float(mesh['max_y'])] if 'zero_reference_position' in self._printer.get_config_section("bed_mesh"): self.zero_ref = self._csv_to_array(mesh['zero_reference_position']) if "probe" not in functions: