printer: create get_probe to support other probe types
This commit is contained in:
parent
e29b41e5c3
commit
c4c7e50314
@ -187,6 +187,14 @@ class Printer:
|
|||||||
sensors.extend(iter(self.get_config_section_list("filament_motion_sensor ")))
|
sensors.extend(iter(self.get_config_section_list("filament_motion_sensor ")))
|
||||||
return sensors
|
return sensors
|
||||||
|
|
||||||
|
def get_probe(self):
|
||||||
|
probe_types = ["probe", "bltouch", "smart_effector", "dockable_probe"]
|
||||||
|
for probe_type in probe_types:
|
||||||
|
if self.config_section_exists(probe_type):
|
||||||
|
logging.info(f"Probe type: {probe_type}")
|
||||||
|
return self.get_config_section(probe_type)
|
||||||
|
return None
|
||||||
|
|
||||||
def get_printer_status_data(self):
|
def get_printer_status_data(self):
|
||||||
data = {
|
data = {
|
||||||
"printer": {
|
"printer": {
|
||||||
|
@ -41,10 +41,13 @@ class BedLevelPanel(ScreenPanel):
|
|||||||
self.screws = self._get_screws("screws_tilt_adjust")
|
self.screws = self._get_screws("screws_tilt_adjust")
|
||||||
logging.info(f"screws_tilt_adjust: {self.screws}")
|
logging.info(f"screws_tilt_adjust: {self.screws}")
|
||||||
|
|
||||||
if "bltouch" in self._screen.printer.get_config_section_list():
|
probe = self._screen.printer.get_probe()
|
||||||
self._get_offsets("bltouch")
|
if probe:
|
||||||
elif "probe" in self._screen.printer.get_config_section_list():
|
if "x_offset" in probe:
|
||||||
self._get_offsets("probe")
|
self.x_offset = round(float(probe['x_offset']), 1)
|
||||||
|
if "y_offset" in probe:
|
||||||
|
self.y_offset = round(float(probe['y_offset']), 1)
|
||||||
|
logging.debug(f"offset X: {self.x_offset} Y: {self.y_offset}")
|
||||||
# bed_screws uses NOZZLE positions
|
# bed_screws uses NOZZLE positions
|
||||||
# screws_tilt_adjust uses PROBE positions and to be offseted for the buttons to work equal to bed_screws
|
# screws_tilt_adjust uses PROBE positions and to be offseted for the buttons to work equal to bed_screws
|
||||||
new_screws = [
|
new_screws = [
|
||||||
@ -337,14 +340,6 @@ class BedLevelPanel(ScreenPanel):
|
|||||||
])
|
])
|
||||||
return sorted(screws, key=lambda s: (float(s[1]), float(s[0])))
|
return sorted(screws, key=lambda s: (float(s[1]), float(s[0])))
|
||||||
|
|
||||||
def _get_offsets(self, section):
|
|
||||||
probe = self._screen.printer.get_config_section(section)
|
|
||||||
if "x_offset" in probe:
|
|
||||||
self.x_offset = round(float(probe['x_offset']), 1)
|
|
||||||
if "y_offset" in probe:
|
|
||||||
self.y_offset = round(float(probe['y_offset']), 1)
|
|
||||||
logging.debug(f"{section} offset X: {self.x_offset} Y: {self.y_offset}")
|
|
||||||
|
|
||||||
def screws_tilt_calculate(self, widget):
|
def screws_tilt_calculate(self, widget):
|
||||||
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
|
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
|
||||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
|
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
|
||||||
|
@ -268,7 +268,7 @@ class BedMeshPanel(ScreenPanel):
|
|||||||
self._screen._ws.klippy.gcode_script("BED_MESH_CALIBRATE")
|
self._screen._ws.klippy.gcode_script("BED_MESH_CALIBRATE")
|
||||||
|
|
||||||
# Load zcalibrate to do a manual mesh
|
# Load zcalibrate to do a manual mesh
|
||||||
if not (self._printer.config_section_exists("probe") or self._printer.config_section_exists("bltouch")):
|
if not self._screen.printer.get_probe():
|
||||||
self.menu_item_clicked(widget, "refresh", {"name": _("Mesh calibrate"), "panel": "zcalibrate"})
|
self.menu_item_clicked(widget, "refresh", {"name": _("Mesh calibrate"), "panel": "zcalibrate"})
|
||||||
|
|
||||||
def send_clear_mesh(self, widget):
|
def send_clear_mesh(self, widget):
|
||||||
|
@ -401,20 +401,16 @@ class JobStatusPanel(ScreenPanel):
|
|||||||
self.buttons['save_offset_endstop'].connect("clicked", self.save_offset, "endstop")
|
self.buttons['save_offset_endstop'].connect("clicked", self.save_offset, "endstop")
|
||||||
|
|
||||||
def save_offset(self, widget, device):
|
def save_offset(self, widget, device):
|
||||||
saved_z_offset = 0
|
|
||||||
if self._printer.config_section_exists("probe"):
|
|
||||||
saved_z_offset = float(self._screen.printer.get_config_section("probe")['z_offset'])
|
|
||||||
elif self._printer.config_section_exists("bltouch"):
|
|
||||||
saved_z_offset = float(self._screen.printer.get_config_section("bltouch")['z_offset'])
|
|
||||||
|
|
||||||
sign = "+" if self.zoffset > 0 else "-"
|
sign = "+" if self.zoffset > 0 else "-"
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
if device == "probe":
|
if device == "probe":
|
||||||
|
probe = self._printer.get_probe()
|
||||||
|
saved_z_offset = probe['z_offset'] if probe else "?"
|
||||||
label.set_text(_("Apply %s%.2f offset to Probe?") % (sign, abs(self.zoffset))
|
label.set_text(_("Apply %s%.2f offset to Probe?") % (sign, abs(self.zoffset))
|
||||||
+ "\n\n"
|
+ "\n\n"
|
||||||
+ _("Saved offset: %s") % saved_z_offset)
|
+ _("Saved offset: %s") % saved_z_offset)
|
||||||
elif device == "endstop":
|
elif device == "endstop":
|
||||||
label.set_text(_("Apply %.2f offset to Endstop?") % self.zoffset)
|
label.set_text(_("Apply %.2f offset to Endstop?") % (sign, abs(self.zoffset)))
|
||||||
label.set_hexpand(True)
|
label.set_hexpand(True)
|
||||||
label.set_halign(Gtk.Align.CENTER)
|
label.set_halign(Gtk.Align.CENTER)
|
||||||
label.set_vexpand(True)
|
label.set_vexpand(True)
|
||||||
@ -808,7 +804,7 @@ class JobStatusPanel(ScreenPanel):
|
|||||||
self.buttons['button_grid'].attach(self.buttons["save_offset_endstop"], 0, 0, 1, 1)
|
self.buttons['button_grid'].attach(self.buttons["save_offset_endstop"], 0, 0, 1, 1)
|
||||||
else:
|
else:
|
||||||
self.buttons['button_grid'].attach(Gtk.Label(""), 0, 0, 1, 1)
|
self.buttons['button_grid'].attach(Gtk.Label(""), 0, 0, 1, 1)
|
||||||
if self._printer.config_section_exists("probe") or self._printer.config_section_exists("bltouch"):
|
if self._screen.printer.get_probe():
|
||||||
self.buttons['button_grid'].attach(self.buttons["save_offset_probe"], 1, 0, 1, 1)
|
self.buttons['button_grid'].attach(self.buttons["save_offset_probe"], 1, 0, 1, 1)
|
||||||
else:
|
else:
|
||||||
self.buttons['button_grid'].attach(Gtk.Label(""), 1, 0, 1, 1)
|
self.buttons['button_grid'].attach(Gtk.Label(""), 1, 0, 1, 1)
|
||||||
|
@ -18,16 +18,14 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
widgets = {}
|
widgets = {}
|
||||||
distances = ['.01', '.05', '.1', '.5', '1', '5']
|
distances = ['.01', '.05', '.1', '.5', '1', '5']
|
||||||
distance = distances[-2]
|
distance = distances[-2]
|
||||||
probe_types = ["probe", "bltouch", "smart_effector", "dockable_probe"]
|
|
||||||
|
|
||||||
def __init__(self, screen, title, back=True):
|
def __init__(self, screen, title, back=True):
|
||||||
super().__init__(screen, title, False)
|
super().__init__(screen, title, False)
|
||||||
self.z_offset = None
|
self.z_offset = None
|
||||||
for probe_type in self.probe_types:
|
self.probe = self._screen.printer.get_probe()
|
||||||
if self._printer.config_section_exists(probe_type):
|
if self.probe:
|
||||||
self.z_offset = float(self._screen.printer.get_config_section(probe_type)['z_offset'])
|
self.z_offset = float(self.probe['z_offset'])
|
||||||
logging.info(f"Using: {probe_type} Z offset: {self.z_offset}")
|
logging.info(f"Z offset: {self.z_offset}")
|
||||||
break
|
|
||||||
self.widgets['zposition'] = Gtk.Label("Z: ?")
|
self.widgets['zposition'] = Gtk.Label("Z: ?")
|
||||||
|
|
||||||
pos = self._gtk.HomogeneousGrid()
|
pos = self._gtk.HomogeneousGrid()
|
||||||
@ -56,11 +54,9 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
and not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"):
|
and not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"):
|
||||||
self._add_button("Endstop", "endstop", pobox)
|
self._add_button("Endstop", "endstop", pobox)
|
||||||
functions.append("endstop")
|
functions.append("endstop")
|
||||||
for probe_type in self.probe_types:
|
if self.probe:
|
||||||
if self._printer.config_section_exists(probe_type):
|
|
||||||
self._add_button("Probe", "probe", pobox)
|
self._add_button("Probe", "probe", pobox)
|
||||||
functions.append("probe")
|
functions.append("probe")
|
||||||
break
|
|
||||||
if self._printer.config_section_exists("bed_mesh") and "probe" not in functions:
|
if self._printer.config_section_exists("bed_mesh") and "probe" not in functions:
|
||||||
# This is used to do a manual bed mesh if there is no probe
|
# This is used to do a manual bed mesh if there is no probe
|
||||||
self._add_button("Bed mesh", "mesh", pobox)
|
self._add_button("Bed mesh", "mesh", pobox)
|
||||||
@ -165,14 +161,11 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
x_position = self._config.get_config()['z_calibrate_position'].getfloat("calibrate_x_position", None)
|
x_position = self._config.get_config()['z_calibrate_position'].getfloat("calibrate_x_position", None)
|
||||||
y_position = self._config.get_config()['z_calibrate_position'].getfloat("calibrate_y_position", None)
|
y_position = self._config.get_config()['z_calibrate_position'].getfloat("calibrate_y_position", None)
|
||||||
|
|
||||||
klipper_cfg = self._screen.printer.get_config_section_list()
|
if self.probe:
|
||||||
for probe_type in self.probe_types:
|
if "sample_retract_dist" in self.probe:
|
||||||
if probe_type in klipper_cfg:
|
z_hop = self.probe['sample_retract_dist']
|
||||||
probe = self._screen.printer.get_config_section(probe_type)
|
if "speed" in self.probe:
|
||||||
if "sample_retract_dist" in probe:
|
speed = self.probe['speed']
|
||||||
z_hop = probe['sample_retract_dist']
|
|
||||||
if "speed" in probe:
|
|
||||||
speed = probe['speed']
|
|
||||||
|
|
||||||
# Use safe_z_home position
|
# Use safe_z_home position
|
||||||
if "safe_z_home" in self._screen.printer.get_config_section_list():
|
if "safe_z_home" in self._screen.printer.get_config_section_list():
|
||||||
@ -201,9 +194,9 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
logging.info("Detected delta kinematics calibrating at 0,0")
|
logging.info("Detected delta kinematics calibrating at 0,0")
|
||||||
self._screen._ws.klippy.gcode_script('G0 X0 Y0 F3000')
|
self._screen._ws.klippy.gcode_script('G0 X0 Y0 F3000')
|
||||||
else:
|
else:
|
||||||
self._calculate_position(klipper_cfg)
|
self._calculate_position()
|
||||||
|
|
||||||
def _calculate_position(self, klipper_cfg):
|
def _calculate_position(self):
|
||||||
logging.debug("Position not configured, probing the middle of the bed")
|
logging.debug("Position not configured, probing the middle of the bed")
|
||||||
try:
|
try:
|
||||||
xmax = float(self._screen.printer.get_config_section("stepper_x")['position_max'])
|
xmax = float(self._screen.printer.get_config_section("stepper_x")['position_max'])
|
||||||
@ -217,14 +210,11 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
|
|
||||||
# Find probe offset
|
# Find probe offset
|
||||||
x_offset = y_offset = None
|
x_offset = y_offset = None
|
||||||
for probe_type in self.probe_types:
|
if self.probe:
|
||||||
if probe_type in klipper_cfg:
|
if "x_offset" in self.probe:
|
||||||
probe = self._screen.printer.get_config_section(probe_type)
|
x_offset = float(self.probe['x_offset'])
|
||||||
if "x_offset" in probe:
|
if "y_offset" in self.probe:
|
||||||
x_offset = float(probe['x_offset'])
|
y_offset = float(self.probe['y_offset'])
|
||||||
if "y_offset" in probe:
|
|
||||||
y_offset = float(probe['y_offset'])
|
|
||||||
break
|
|
||||||
logging.info(f"Offset X:{x_offset} Y:{y_offset}")
|
logging.info(f"Offset X:{x_offset} Y:{y_offset}")
|
||||||
if x_offset is not None:
|
if x_offset is not None:
|
||||||
x_position = x_position - x_offset
|
x_position = x_position - x_offset
|
||||||
@ -264,7 +254,7 @@ class ZCalibratePanel(ScreenPanel):
|
|||||||
def update_position(self, position):
|
def update_position(self, position):
|
||||||
self.widgets['zposition'].set_text(f"Z: {position[2]:.2f}")
|
self.widgets['zposition'].set_text(f"Z: {position[2]:.2f}")
|
||||||
if self.z_offset is not None:
|
if self.z_offset is not None:
|
||||||
self.widgets['zoffset'].set_text(f"{-position[2] + self.z_offset:.2f}")
|
self.widgets['zoffset'].set_text(f"{position[2] - self.z_offset:.2f}")
|
||||||
|
|
||||||
def change_distance(self, widget, distance):
|
def change_distance(self, widget, distance):
|
||||||
logging.info(f"### Distance {distance}")
|
logging.info(f"### Distance {distance}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user