bed_mesh: add support for rotation and inversion to the meshMap
This commit is contained in:
parent
6908d5832c
commit
b091eeff37
@ -92,6 +92,7 @@ moonraker_port: 7125
|
||||
# screw_positions: bl, br, fm
|
||||
|
||||
# Rotation is useful if the screen is not directly in front of the machine.
|
||||
# It will affect the bed mesh visualization.
|
||||
# Valid values are 0 90 180 270
|
||||
# screw_rotation: 0
|
||||
|
||||
|
@ -13,9 +13,33 @@ class BedMap(Gtk.DrawingArea):
|
||||
self.font_size = font_size
|
||||
self.font_spacing = round(self.font_size * 1.5)
|
||||
self.bm = list(reversed(bm)) if bm is not None else None
|
||||
self.invert_x = False
|
||||
self.invert_y = False
|
||||
self.rotation = 0
|
||||
|
||||
def update_bm(self, bm):
|
||||
self.bm = list(reversed(bm)) if bm is not None else None
|
||||
if bm is None:
|
||||
self.bm = None
|
||||
return
|
||||
print(bm)
|
||||
if self.invert_x and self.invert_y:
|
||||
self.bm = [list(reversed(b)) for b in bm]
|
||||
elif self.invert_x:
|
||||
self.bm = [list(reversed(b)) for b in list(reversed(bm))]
|
||||
elif self.invert_y:
|
||||
self.bm = list(bm)
|
||||
else:
|
||||
self.bm = list(reversed(bm))
|
||||
if self.rotation in (90, 180, 270):
|
||||
self.bm = self.rotate_matrix(self.bm)
|
||||
|
||||
def rotate_matrix(self, matrix):
|
||||
if self.rotation == 90:
|
||||
return [list(row) for row in zip(*matrix[::-1])]
|
||||
elif self.rotation == 180:
|
||||
return [list(row)[::-1] for row in matrix[::-1]]
|
||||
elif self.rotation == 270:
|
||||
return [list(row) for row in zip(*matrix)][::-1]
|
||||
|
||||
def draw_graph(self, da, ctx):
|
||||
width = da.get_allocated_width()
|
||||
@ -68,3 +92,10 @@ class BedMap(Gtk.DrawingArea):
|
||||
if value < 0:
|
||||
return [color, color, 1]
|
||||
return [1, 1, 1]
|
||||
|
||||
def set_inversion(self, x=False, y=False):
|
||||
self.invert_x = x
|
||||
self.invert_y = y
|
||||
|
||||
def set_rotation(self, rotation=0):
|
||||
self.rotation = rotation
|
||||
|
@ -96,6 +96,15 @@ class Panel(ScreenPanel):
|
||||
return bm[matrix]
|
||||
|
||||
def update_graph(self, widget=None, profile=None):
|
||||
if self.ks_printer_cfg is not None:
|
||||
invert_x = self._config.get_config()['main'].getboolean("invert_x", False)
|
||||
invert_y = self._config.get_config()['main'].getboolean("invert_y", False)
|
||||
self.labels['map'].set_inversion(x=invert_x, y=invert_y)
|
||||
rotation = self.ks_printer_cfg.getint("screw_rotation", 0)
|
||||
if rotation not in (0, 90, 180, 270):
|
||||
rotation = 0
|
||||
self.labels['map'].set_rotation(rotation)
|
||||
logging.info(f"Inversion X: {invert_x} Y: {invert_y} Rotation: {rotation}")
|
||||
self.labels['map'].update_bm(self.retrieve_bm(profile))
|
||||
self.labels['map'].queue_draw()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user