From b5e87152f11bf7609080ba3a4a80486ede7e4cc0 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Thu, 25 Jan 2024 22:46:51 -0300 Subject: [PATCH] bed_level: improvements (#1248) 1. use the status reference instead of regex matching (this was coded before the status existed) 2. change icons to reflect the rotation direction 3. change icon to reflect that the adjustment is good enough (according to klipper docs below 6 minutes) 4. auto open the panel when screws_tilt_calculate finished close #1231 --- ks_includes/printer.py | 13 +--- panels/bed_level.py | 76 ++++++++-------------- screen.py | 10 ++- styles/colorized/images/ccw.svg | 82 +++++++++++++++++++++++ styles/colorized/images/cw.svg | 76 ++++++++++++++++++++++ styles/material-dark/images/ccw.svg | 40 ++++++++++++ styles/material-dark/images/cw.svg | 38 +++++++++++ styles/material-darker/images/ccw.svg | 40 ++++++++++++ styles/material-darker/images/cw.svg | 38 +++++++++++ styles/material-light/images/ccw.svg | 40 ++++++++++++ styles/material-light/images/cw.svg | 40 ++++++++++++ styles/z-bolt/images/ccw.svg | 93 +++++++++++++++++++++++++++ styles/z-bolt/images/cw.svg | 93 +++++++++++++++++++++++++++ 13 files changed, 613 insertions(+), 66 deletions(-) create mode 100644 styles/colorized/images/ccw.svg create mode 100644 styles/colorized/images/cw.svg create mode 100644 styles/material-dark/images/ccw.svg create mode 100644 styles/material-dark/images/cw.svg create mode 100644 styles/material-darker/images/ccw.svg create mode 100644 styles/material-darker/images/cw.svg create mode 100644 styles/material-light/images/ccw.svg create mode 100644 styles/material-light/images/cw.svg create mode 100644 styles/z-bolt/images/ccw.svg create mode 100644 styles/z-bolt/images/cw.svg diff --git a/ks_includes/printer.py b/ks_includes/printer.py index 0af3f463..7695fd47 100644 --- a/ks_includes/printer.py +++ b/ks_includes/printer.py @@ -6,7 +6,7 @@ from gi.repository import GLib class Printer: - def __init__(self, state_cb, state_callbacks, busy_cb): + def __init__(self, state_cb, state_callbacks): self.config = {} self.data = {} self.state = "disconnected" @@ -22,8 +22,6 @@ class Printer: self.output_pin_count = 0 self.store_timeout = None self.tempstore = {} - self.busy_cb = busy_cb - self.busy = False self.tempstore_size = 1200 self.cameras = [] self.available_commands = {} @@ -41,7 +39,6 @@ class Printer: self.ledcount = 0 self.output_pin_count = 0 self.tempstore = {} - self.busy = False if not self.store_timeout: self.store_timeout = GLib.timeout_add_seconds(1, self._update_temp_store) self.tempstore_size = 1200 @@ -137,18 +134,10 @@ class Printer: return "paused" if self.data['print_stats']['state'] == 'printing': return "printing" - if self.data['idle_timeout']['state'].lower() == "printing": - return "busy" return self.data['webhooks']['state'] def process_status_update(self): state = self.evaluate_state() - if state == "busy": - self.busy = True - return GLib.idle_add(self.busy_cb, True) - if self.busy: - self.busy = False - GLib.idle_add(self.busy_cb, False) if state != self.state: self.change_state(state) return False diff --git a/panels/bed_level.py b/panels/bed_level.py index ae98cd40..ff9444ac 100644 --- a/panels/bed_level.py +++ b/panels/bed_level.py @@ -36,7 +36,6 @@ class Panel(ScreenPanel): def __init__(self, screen, title): super().__init__(screen, title) - self.response_count = 0 self.screw_dict = {} self.screws = [] self.y_cnt = 0 @@ -306,7 +305,6 @@ class Panel(ScreenPanel): self._screen._ws.klippy.gcode_script("Z_TILT_ADJUST") def go_to_position(self, widget, position): - widget.set_sensitive(False) self.home() logging.debug(f"Going to position: {position}") script = [ @@ -323,55 +321,40 @@ class Panel(ScreenPanel): def process_busy(self, busy): for button in self.buttons: if button == "screws": - self.buttons[button].set_sensitive( - self._printer.config_section_exists("screws_tilt_adjust") - and (not busy)) continue self.buttons[button].set_sensitive((not busy)) def process_update(self, action, data): - if action == "notify_busy": - self.process_busy(data) + if 'idle_timeout' in data: + self.process_busy(data['idle_timeout']['state'].lower() == "printing") + if action != "notify_status_update": return - if action != "notify_gcode_response": - return - if data.startswith('!!'): - self.response_count = 0 - self.buttons['screws'].set_sensitive(True) - return - result = re.match( - "^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]+ :" + - " (Adjust ->|adjust) ([CW]+ [0-9:]+)", - data - ) - # screws_tilt_adjust uses PROBE positions and was offseted for the buttons to work equal to bed_screws - # for the result we need to undo the offset - if result: - x = round(float(result[2]) + self.x_offset, 1) - y = round(float(result[3]) + self.y_offset, 1) - for key, value in self.screw_dict.items(): - if value and x == value[0] and y == value[1]: - logging.debug(f"X: {x} Y: {y} Adjust: {result[5]} Pos: {key}") - self.buttons[key].set_label(result[5]) - break - self.response_count += 1 - if self.response_count >= len(self.screws) - 1: + if "screws_tilt_adjust" in data: + if "error" in data["screws_tilt_adjust"]: self.buttons['screws'].set_sensitive(True) - else: - result = re.match( - "^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]", - data - ) - # screws_tilt_adjust uses PROBE positions and was offseted for the buttons to work equal to bed_screws - # for the result we need to undo the offset - if result and re.search('base', result[1]): - x = round(float(result[2]) + self.x_offset, 1) - y = round(float(result[3]) + self.y_offset, 1) - logging.debug(f"X: {x} Y: {y} is the reference") - for key, value in self.screw_dict.items(): - if value and x == value[0] and y == value[1]: - logging.debug(f"X: {x} Y: {y} Pos: {key}") - self.buttons[key].set_label(_("Reference")) + logging.info("Error reported by screws_tilt_adjust") + if "results" in data["screws_tilt_adjust"]: + section = self._printer.get_config_section('screws_tilt_adjust') + for screw, result in data["screws_tilt_adjust"]["results"].items(): + logging.info(f"{screw} {result['sign']} {result['adjust']}") + if screw not in section: + logging.error(f"{screw} not found in {section}") + continue + x, y = section[screw].split(',') + x = round(float(x) + self.x_offset, 1) + y = round(float(y) + self.y_offset, 1) + for key, value in self.screw_dict.items(): + if value and x == value[0] and y == value[1]: + logging.debug(f"X: {x} Y: {y} Adjust: {result['adjust']} Pos: {key}") + if result['is_base']: + logging.info(f"{screw} is the Reference") + self.buttons[key].set_label(_("Reference")) + else: + self.buttons[key].set_label(f"{result['sign']} {result['adjust']}") + if int(result['adjust'].split(':')[1]) < 6: + self.buttons[key].set_image(self._gtk.Image('complete')) + else: + self.buttons[key].set_image(self._gtk.Image(result['sign'].lower())) def _get_screws(self, config_section_name): screws = [] @@ -397,8 +380,5 @@ class Panel(ScreenPanel): return sorted(screws, key=lambda s: (float(s[1]), float(s[0]))) def screws_tilt_calculate(self, widget): - widget.set_sensitive(False) self.home() - self.response_count = 0 - self.buttons['screws'].set_sensitive(False) self._screen._send_action(widget, "printer.gcode.script", {"script": "SCREWS_TILT_CALCULATE"}) diff --git a/screen.py b/screen.py index 061900ec..c02712f9 100755 --- a/screen.py +++ b/screen.py @@ -191,7 +191,7 @@ class KlipperScreen(Gtk.Window): "shutdown": self.state_shutdown } for printer in self.printers: - printer["data"] = Printer(state_execute, state_callbacks, self.process_busy_state) + printer["data"] = Printer(state_execute, state_callbacks) default_printer = self._config.get_main_config().get('default_printer') logging.debug(f"Default printer: {default_printer}") if [True for p in self.printers if default_printer in p]: @@ -266,6 +266,7 @@ class KlipperScreen(Gtk.Window): "motion_report": ["live_position", "live_velocity", "live_extruder_velocity"], "exclude_object": ["current_object", "objects", "excluded_objects"], "manual_probe": ['is_active'], + "screws_tilt_adjust": ['results', 'error'], } } for extruder in self.printer.get_tools(): @@ -326,7 +327,6 @@ class KlipperScreen(Gtk.Window): logging.debug(f"Current panel hierarchy: {' > '.join(self._cur_panels)}") if hasattr(self.panels[panel], "process_update"): self.process_update("notify_status_update", self.printer.data) - self.process_update("notify_busy", self.printer.busy) if hasattr(self.panels[panel], "activate"): self.panels[panel].activate() self.show_all() @@ -652,10 +652,6 @@ class KlipperScreen(Gtk.Window): self.base_panel.show_heaters(False) self.show_panel("printer_select", _("Printer Select"), remove_all=True) - def process_busy_state(self, busy): - self.process_update("notify_busy", busy) - return False - def websocket_disconnected(self, msg): self.printer_initializing(msg, remove=True) self.printer.state = "disconnected" @@ -758,6 +754,8 @@ class KlipperScreen(Gtk.Window): self.printer.process_update(data) if 'manual_probe' in data and data['manual_probe']['is_active'] and 'zcalibrate' not in self._cur_panels: self.show_panel("zcalibrate", _('Z Calibrate')) + if "screws_tilt_adjust" in data and 'bed_level' not in self._cur_panels: + self.show_panel("bed_level", _('Bed Level')) elif action == "notify_filelist_changed": if self.files is not None: self.files.process_update(data) diff --git a/styles/colorized/images/ccw.svg b/styles/colorized/images/ccw.svg new file mode 100644 index 00000000..5ec61f2b --- /dev/null +++ b/styles/colorized/images/ccw.svg @@ -0,0 +1,82 @@ + + + + + + + image/svg+xml + + reboot + + + + + + reboot + Created with Sketch. + + + + + diff --git a/styles/colorized/images/cw.svg b/styles/colorized/images/cw.svg new file mode 100644 index 00000000..7026e695 --- /dev/null +++ b/styles/colorized/images/cw.svg @@ -0,0 +1,76 @@ + + + + + + + image/svg+xml + + reboot + + + + + + reboot + Created with Sketch. + + + diff --git a/styles/material-dark/images/ccw.svg b/styles/material-dark/images/ccw.svg new file mode 100644 index 00000000..db061810 --- /dev/null +++ b/styles/material-dark/images/ccw.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/styles/material-dark/images/cw.svg b/styles/material-dark/images/cw.svg new file mode 100644 index 00000000..03411b0d --- /dev/null +++ b/styles/material-dark/images/cw.svg @@ -0,0 +1,38 @@ + + + + + + diff --git a/styles/material-darker/images/ccw.svg b/styles/material-darker/images/ccw.svg new file mode 100644 index 00000000..db061810 --- /dev/null +++ b/styles/material-darker/images/ccw.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/styles/material-darker/images/cw.svg b/styles/material-darker/images/cw.svg new file mode 100644 index 00000000..03411b0d --- /dev/null +++ b/styles/material-darker/images/cw.svg @@ -0,0 +1,38 @@ + + + + + + diff --git a/styles/material-light/images/ccw.svg b/styles/material-light/images/ccw.svg new file mode 100644 index 00000000..53f72152 --- /dev/null +++ b/styles/material-light/images/ccw.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/styles/material-light/images/cw.svg b/styles/material-light/images/cw.svg new file mode 100644 index 00000000..ba13833a --- /dev/null +++ b/styles/material-light/images/cw.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/styles/z-bolt/images/ccw.svg b/styles/z-bolt/images/ccw.svg new file mode 100644 index 00000000..29a1e8b4 --- /dev/null +++ b/styles/z-bolt/images/ccw.svg @@ -0,0 +1,93 @@ + + + + + + image/svg+xml + + folder + + + + + + + folder + Created with Sketch. + + + + + diff --git a/styles/z-bolt/images/cw.svg b/styles/z-bolt/images/cw.svg new file mode 100644 index 00000000..23206c1f --- /dev/null +++ b/styles/z-bolt/images/cw.svg @@ -0,0 +1,93 @@ + + + + + + image/svg+xml + + folder + + + + + + + folder + Created with Sketch. + + + + +