bed_level: hide the panel if bed_screws or screws_tilt_calculate are not defined
there are printers with fixed beds that don't need this panel
This commit is contained in:
1 parent
aa2bfcbaee
commit
c047bed518
5 files changed
+111
-115
No files matched your search
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
Breaking changes will be listed here.
|
Breaking changes will be listed here.
|
||||||
|
|
||||||
|
#### [2022 08](https://github.com/jordanruthe/KlipperScreen/)
|
||||||
|
* The bed level panel will use `[bed_screws]` if defined else`[screws_tilt_calculate]`
|
||||||
|
|
||||||
#### [2022 03 21](https://github.com/jordanruthe/KlipperScreen/commit/bc34b3c8d6761c27a0b0c62fc4dfa11442b417f6)
|
#### [2022 03 21](https://github.com/jordanruthe/KlipperScreen/commit/bc34b3c8d6761c27a0b0c62fc4dfa11442b417f6)
|
||||||
* Default configuration is now merged again.
|
* Default configuration is now merged again.
|
||||||
Fixing [2021 05 20](https://github.com/jordanruthe/KlipperScreen/commit/eb801486928bf02709033dcbc5f0a45ca43b23c1)
|
Fixing [2021 05 20](https://github.com/jordanruthe/KlipperScreen/commit/eb801486928bf02709033dcbc5f0a45ca43b23c1)
|
||||||
|
|||||||
+5
-5
@@ -20,12 +20,12 @@ Klipper Sections:
|
|||||||
* [bed_screws](https://www.klipper3d.org/Config_Reference.html#bed_screws)
|
* [bed_screws](https://www.klipper3d.org/Config_Reference.html#bed_screws)
|
||||||
* [screws_tilt_adjust](https://www.klipper3d.org/Config_Reference.html#screws_tilt_adjust)
|
* [screws_tilt_adjust](https://www.klipper3d.org/Config_Reference.html#screws_tilt_adjust)
|
||||||
|
|
||||||
_Important Note: Due to Klipper using the bltouch/probe offsets in screws_tilt_adjust, if a bltouch/probe is enabled_
|
!!! important:
|
||||||
_KlipperScreen will add the offset to the defined screw values. This will not occur if bed_screws section is used._
|
`[bed_screws]` uses Nozzle positions and `[screws_tilt_adjust]` uses Probe positions
|
||||||
|
|
||||||
This panel will favor screws_tilt_adjust over the bed_screws section. If screws_tilt_adjust is defined, an extra button
|
This panel will favor `[bed_screws]` but if it's not defined,
|
||||||
for _Screws Calibrate_ will appear. This button runs the SCREWS_TILT_CALCULATE command and shows the results on the
|
the probe offset will be applied to the defined screw values in `[screws_tilt_adjust]`,
|
||||||
panel.
|
this way the position buttons behave like if `[bed_screws]` was defined.
|
||||||
|
|
||||||
### Bed Mesh
|
### Bed Mesh
|
||||||
```py
|
```py
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ panel: console
|
|||||||
name: {{ gettext('Bed Level') }}
|
name: {{ gettext('Bed Level') }}
|
||||||
icon: bed-level
|
icon: bed-level
|
||||||
panel: bed_level
|
panel: bed_level
|
||||||
|
enable: {{ printer.bed_screws or printer.screws_tilt_adjust}}
|
||||||
|
|
||||||
[menu __main config bedmesh]
|
[menu __main config bedmesh]
|
||||||
name: {{ gettext('Bed Mesh') }}
|
name: {{ gettext('Bed Mesh') }}
|
||||||
|
|||||||
@@ -244,14 +244,10 @@ class Printer:
|
|||||||
"temperature_devices": {"count": self.tempdevcount},
|
"temperature_devices": {"count": self.tempdevcount},
|
||||||
"fans": {"count": self.fancount},
|
"fans": {"count": self.fancount},
|
||||||
"output_pins": {"count": self.output_pin_count},
|
"output_pins": {"count": self.output_pin_count},
|
||||||
"bltouch": self.config_section_exists("bltouch"),
|
|
||||||
"gcode_macros": {"count": len(self.get_gcode_macros())},
|
"gcode_macros": {"count": len(self.get_gcode_macros())},
|
||||||
"idle_timeout": self.get_stat("idle_timeout").copy(),
|
"idle_timeout": self.get_stat("idle_timeout").copy(),
|
||||||
"pause_resume": {"is_paused": self.state == "paused"},
|
"pause_resume": {"is_paused": self.state == "paused"},
|
||||||
"power_devices": {"count": len(self.get_power_devices())},
|
"power_devices": {"count": len(self.get_power_devices())},
|
||||||
"probe": self.config_section_exists("probe"),
|
|
||||||
"firmware_retraction": self.config_section_exists("firmware_retraction"),
|
|
||||||
"input_shaper": self.config_section_exists("input_shaper")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +256,10 @@ class Printer:
|
|||||||
if self.config_section_exists(section):
|
if self.config_section_exists(section):
|
||||||
data["printer"][section] = self.get_config_section(section).copy()
|
data["printer"][section] = self.get_config_section(section).copy()
|
||||||
|
|
||||||
|
sections = ["firmware_retraction", "input_shaper", "bed_screws", "screws_tilt_adjust"]
|
||||||
|
for section in sections:
|
||||||
|
data["printer"][section] = self.config_section_exists(section)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_klipper_version(self):
|
def get_klipper_version(self):
|
||||||
|
|||||||
+98
-106
@@ -14,84 +14,51 @@ def create_panel(*args):
|
|||||||
|
|
||||||
|
|
||||||
class BedLevelPanel(ScreenPanel):
|
class BedLevelPanel(ScreenPanel):
|
||||||
|
supported = (4, 6, 8)
|
||||||
|
|
||||||
def __init__(self, screen, title, back=True, action_bar=True, printer_name=True):
|
def __init__(self, screen, title, back=True, action_bar=True, printer_name=True):
|
||||||
super().__init__(screen, title, back, action_bar, printer_name)
|
super().__init__(screen, title, back, action_bar, printer_name)
|
||||||
self.response_count = None
|
self.response_count = 0
|
||||||
self.panel_name = None
|
self.panel_name = ""
|
||||||
self.screw_dict = None
|
self.screw_dict = {}
|
||||||
self.screws = None
|
self.screws = []
|
||||||
self.y_cnt = None
|
self.y_cnt = 0
|
||||||
self.x_cnt = None
|
self.x_cnt = 0
|
||||||
self.x_offset = 0
|
self.x_offset = 0
|
||||||
self.y_offset = 0
|
self.y_offset = 0
|
||||||
|
|
||||||
def initialize(self, panel_name):
|
def initialize(self, panel_name):
|
||||||
self.panel_name = panel_name
|
self.panel_name = panel_name
|
||||||
|
self.labels['dm'] = self._gtk.ButtonImage("motor-off", _("Disable XY"), "color3")
|
||||||
|
self.labels['dm'].connect("clicked", self.disable_motors)
|
||||||
|
|
||||||
grid = self._gtk.HomogeneousGrid()
|
grid = self._gtk.HomogeneousGrid()
|
||||||
|
grid.attach(self.labels['dm'], 0, 0, 1, 1)
|
||||||
|
|
||||||
screws = []
|
if "bed_screws" in self._screen.printer.get_config_section_list():
|
||||||
config_section_name = None
|
self.screws = self._get_screws("bed_screws")
|
||||||
if "screws_tilt_adjust" in self._screen.printer.get_config_section_list():
|
elif "screws_tilt_adjust" in self._screen.printer.get_config_section_list():
|
||||||
config_section_name = "screws_tilt_adjust"
|
self.screws = self._get_screws("screws_tilt_adjust")
|
||||||
elif "bed_screws" in self._screen.printer.get_config_section_list():
|
self.labels['screws'] = self._gtk.ButtonImage("refresh", _("Screws Adjust"), "color4")
|
||||||
config_section_name = "bed_screws"
|
self.labels['screws'].connect("clicked", self.screws_tilt_calculate)
|
||||||
|
grid.attach(self.labels['screws'], 0, 1, 1, 1)
|
||||||
|
|
||||||
if config_section_name is not None:
|
nscrews = len(self.screws)
|
||||||
config_section = self._screen.printer.get_config_section(config_section_name)
|
if nscrews not in self.supported:
|
||||||
for item in config_section:
|
logging.debug(f"{nscrews} bed_screws not supported.")
|
||||||
logging.debug(f"Screws section: {config_section[item]}")
|
label = Gtk.Label(
|
||||||
result = re.match(r"([\-0-9\.]+)\s*,\s*([\-0-9\.]+)", config_section[item])
|
_("Bed screw configuration not supported:") + f" {nscrews}\n\n"
|
||||||
if result:
|
+ _("Supported number of screws:") + f" {self.supported}"
|
||||||
screws.append([
|
)
|
||||||
round(float(result.group(1)), 2),
|
grid.attach(label, 1, 0, 3, 2)
|
||||||
round(float(result.group(2)), 2)
|
# Take the user to the console to see results
|
||||||
])
|
if 'screws' in self.labels:
|
||||||
|
self.labels['screws'].connect("clicked", self.menu_item_clicked, "console", {
|
||||||
screws = sorted(screws, key=lambda s: (float(s[1]), float(s[0])))
|
"name": "Console",
|
||||||
|
"panel": "console"
|
||||||
supported = [4, 6, 8]
|
})
|
||||||
nscrews = len(screws)
|
self.content.add(grid)
|
||||||
if nscrews not in supported:
|
return
|
||||||
logging.debug(f"{nscrews} bed_screws not supported: calculating 4 locations")
|
|
||||||
xconf = self._screen.printer.get_config_section("stepper_x")
|
|
||||||
yconf = self._screen.printer.get_config_section("stepper_y")
|
|
||||||
x = int(int(xconf['position_max']) / 4)
|
|
||||||
y = int(int(yconf['position_max']) / 4)
|
|
||||||
self.screws = [
|
|
||||||
[x, y],
|
|
||||||
[x * 3, y],
|
|
||||||
[x, y * 3],
|
|
||||||
[x * 3, y * 3],
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
self.screws = screws
|
|
||||||
|
|
||||||
if (("bltouch" in self._screen.printer.get_config_section_list() or
|
|
||||||
"probe" in self._screen.printer.get_config_section_list()) and
|
|
||||||
config_section_name == "screws_tilt_adjust"):
|
|
||||||
if "bltouch" in self._screen.printer.get_config_section_list():
|
|
||||||
bltouch = self._screen.printer.get_config_section("bltouch")
|
|
||||||
if "x_offset" in bltouch:
|
|
||||||
self.x_offset = float(bltouch['x_offset'])
|
|
||||||
if "y_offset" in bltouch:
|
|
||||||
self.y_offset = float(bltouch['y_offset'])
|
|
||||||
logging.debug(f"Bltouch found substracted offset X: {self.x_offset} Y: {self.y_offset}")
|
|
||||||
self._screen.show_popup_message(_("Bltouch found applied offset"), level=1)
|
|
||||||
elif "probe" in self._screen.printer.get_config_section_list():
|
|
||||||
probe = self._screen.printer.get_config_section("probe")
|
|
||||||
if "x_offset" in probe:
|
|
||||||
self.x_offset = float(probe['x_offset'])
|
|
||||||
if "y_offset" in probe:
|
|
||||||
self.y_offset = float(probe['y_offset'])
|
|
||||||
logging.debug(f"Probe found substracting offset X: {self.x_offset} Y: {self.y_offset}")
|
|
||||||
self._screen.show_popup_message(_("Probe found applied offset"), level=1)
|
|
||||||
new_screws = []
|
|
||||||
for screw in self.screws:
|
|
||||||
new_screws.append([
|
|
||||||
self.apply_offset(screw[0], self.x_offset),
|
|
||||||
self.apply_offset(screw[1], self.y_offset)
|
|
||||||
])
|
|
||||||
self.screws = new_screws
|
|
||||||
|
|
||||||
# get dimensions
|
# get dimensions
|
||||||
self.x_cnt = len(list(dict.fromkeys([int(x[0]) for x in self.screws])))
|
self.x_cnt = len(list(dict.fromkeys([int(x[0]) for x in self.screws])))
|
||||||
@@ -256,16 +223,6 @@ class BedLevelPanel(ScreenPanel):
|
|||||||
|
|
||||||
grid.attach(bedgrid, 1, 0, 3, 2)
|
grid.attach(bedgrid, 1, 0, 3, 2)
|
||||||
|
|
||||||
self.labels['dm'] = self._gtk.ButtonImage("motor-off", _("Disable XY"), "color3")
|
|
||||||
self.labels['dm'].connect("clicked", self.disable_motors)
|
|
||||||
|
|
||||||
grid.attach(self.labels['dm'], 0, 0, 1, 1)
|
|
||||||
|
|
||||||
if self._printer.config_section_exists("screws_tilt_adjust"):
|
|
||||||
self.labels['screws'] = self._gtk.ButtonImage("refresh", _("Screws Adjust"), "color4")
|
|
||||||
self.labels['screws'].connect("clicked", self.screws_tilt_calculate)
|
|
||||||
grid.attach(self.labels['screws'], 0, 1, 1, 1)
|
|
||||||
|
|
||||||
self.content.add(grid)
|
self.content.add(grid)
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
@@ -296,40 +253,75 @@ class BedLevelPanel(ScreenPanel):
|
|||||||
|
|
||||||
def process_update(self, action, data):
|
def process_update(self, action, data):
|
||||||
|
|
||||||
if action == "notify_gcode_response":
|
if action != "notify_gcode_response":
|
||||||
if data.startswith('!!'):
|
return
|
||||||
self.response_count = 0
|
if data.startswith('!!'):
|
||||||
|
self.response_count = 0
|
||||||
|
self.labels['screws'].set_sensitive(True)
|
||||||
|
return
|
||||||
|
result = re.match(
|
||||||
|
"^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]+ :" +
|
||||||
|
" (Adjust ->|adjust) ([CW]+ [0-9:]+)",
|
||||||
|
data
|
||||||
|
)
|
||||||
|
if result:
|
||||||
|
x = self.apply_offset(result[2], self.x_offset)
|
||||||
|
y = self.apply_offset(result[3], self.y_offset)
|
||||||
|
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.labels[key].set_label(result[5])
|
||||||
|
break
|
||||||
|
self.response_count += 1
|
||||||
|
if self.response_count >= len(self.screws) - 1:
|
||||||
self.labels['screws'].set_sensitive(True)
|
self.labels['screws'].set_sensitive(True)
|
||||||
return
|
else:
|
||||||
result = re.match(
|
result = re.match(
|
||||||
"^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]+ :" +
|
"^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]",
|
||||||
" (Adjust ->|adjust) ([CW]+ [0-9:]+)",
|
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
if result:
|
if result and re.search('base', result[1]):
|
||||||
x = self.apply_offset(result.group(2), self.x_offset)
|
x = self.apply_offset(result[2], self.x_offset)
|
||||||
y = self.apply_offset(result.group(3), self.y_offset)
|
y = self.apply_offset(result[3], self.y_offset)
|
||||||
|
logging.debug(f"X: {x} Y: {y} is the reference")
|
||||||
for key, value in self.screw_dict.items():
|
for key, value in self.screw_dict.items():
|
||||||
if value and x == value[0] and y == value[1]:
|
if value and x == value[0] and y == value[1]:
|
||||||
logging.debug(f"X: {x} Y: {y} Adjust: {result.group(5)} Pos: {key}")
|
logging.debug(f"X: {x} Y: {y} Pos: {key}")
|
||||||
self.labels[key].set_label(result.group(5))
|
self.labels[key].set_label(_("Reference"))
|
||||||
break
|
|
||||||
self.response_count += 1
|
def _get_screws(self, config_section_name):
|
||||||
if self.response_count >= len(self.screws) - 1:
|
screws = []
|
||||||
self.labels['screws'].set_sensitive(True)
|
config_section = self._screen.printer.get_config_section(config_section_name)
|
||||||
else:
|
for item in config_section:
|
||||||
result = re.match(
|
logging.debug(f"Screws section: {config_section[item]}")
|
||||||
"^// (.*) : [xX= ]+([\\-0-9\\.]+), [yY= ]+([\\-0-9\\.]+), [zZ= ]+[\\-0-9\\.]",
|
result = re.match(r"([\-0-9\.]+)\s*,\s*([\-0-9\.]+)", config_section[item])
|
||||||
data
|
if result:
|
||||||
)
|
screws.append([
|
||||||
if result and re.search('base', result.group(1)):
|
round(float(result[1]), 2),
|
||||||
x = self.apply_offset(result.group(2), self.x_offset)
|
round(float(result[2]), 2)
|
||||||
y = self.apply_offset(result.group(3), self.y_offset)
|
])
|
||||||
logging.debug(f"X: {x} Y: {y} is the reference")
|
screws = sorted(screws, key=lambda s: (float(s[1]), float(s[0])))
|
||||||
for key, value in self.screw_dict.items():
|
logging.info(f"Defined Screws: {config_section_name} {screws}")
|
||||||
if value and x == value[0] and y == value[1]:
|
# bed_screws uses NOZZLE positions
|
||||||
logging.debug(f"X: {x} Y: {y} Pos: {key}")
|
# screws_tilt_adjust uses PROBE positions and to be offseted for the buttons to work equal to bed_screws
|
||||||
self.labels[key].set_label(_("Reference"))
|
if config_section_name == "screws_tilt_adjust":
|
||||||
|
if "bltouch" in self._screen.printer.get_config_section_list():
|
||||||
|
self._get_offsets("bltouch")
|
||||||
|
elif "probe" in self._screen.printer.get_config_section_list():
|
||||||
|
self._get_offsets("probe")
|
||||||
|
for screw in screws:
|
||||||
|
screw[0] = self.apply_offset(screw[0], self.x_offset)
|
||||||
|
screw[1] = self.apply_offset(screw[1], self.y_offset)
|
||||||
|
logging.info(f"Screws with probe offsets: {screws}")
|
||||||
|
return screws
|
||||||
|
|
||||||
|
def _get_offsets(self, section):
|
||||||
|
probe = self._screen.printer.get_config_section(section)
|
||||||
|
if "x_offset" in probe:
|
||||||
|
self.x_offset = float(probe['x_offset'])
|
||||||
|
if "y_offset" in probe:
|
||||||
|
self.y_offset = float(probe['y_offset'])
|
||||||
|
logging.debug(f"{section} offset X: {self.x_offset} Y: {self.y_offset}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def apply_offset(pos, offset):
|
def apply_offset(pos, offset):
|
||||||
|
|||||||
Reference in new issue
Block a user