diff --git a/docs/Configuration.md b/docs/Configuration.md index 420fd539..044e3fc6 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -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 diff --git a/ks_includes/widgets/bedmap.py b/ks_includes/widgets/bedmap.py index b1dffac7..334a5e69 100644 --- a/ks_includes/widgets/bedmap.py +++ b/ks_includes/widgets/bedmap.py @@ -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 diff --git a/panels/bed_mesh.py b/panels/bed_mesh.py index c9047846..013040af 100644 --- a/panels/bed_mesh.py +++ b/panels/bed_mesh.py @@ -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()