bed_mesh: change how profiles with points instead of matrix are handled

This commit is contained in:
Alfredo Monclus
2024-05-29 13:59:24 -03:00
parent b91566c718
commit af075cdf65
3 changed files with 16 additions and 21 deletions

View File

@@ -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: