Skip to content

Commit

Permalink
dockable_probe: pre|post_attach|detach hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Dec 11, 2024
1 parent aa13acd commit d8fa86f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,11 @@ detach_position: 0,0,0
#dock_sense_pin:
# This supplemental pin can be defined to determine a docked state in
# addition to probe_sense_pin or check_open_attach.
#pre_attach_gcode:
#post_attach_gcode:
#pre_detach_gcode:
#post_detach_gcode:
#
#x_offset:
#y_offset:
#z_offset:
Expand Down
20 changes: 20 additions & 0 deletions klippy/extras/dockable_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ def __init__(self, config):
config, "deactivate_gcode", ""
)

self.pre_attach_gcode = gcode_macro.load_template(
config, "pre_attach_gcode", ""
)
self.post_attach_gcode = gcode_macro.load_template(
config, "post_attach_gcode", ""
)

self.pre_detach_gcode = gcode_macro.load_template(
config, "pre_detach_gcode", ""
)
self.post_detach_gcode = gcode_macro.load_template(
config, "post_detach_gcode", ""
)

# Pins
ppins = self.printer.lookup_object("pins")
pin = config.get("pin")
Expand Down Expand Up @@ -493,6 +507,7 @@ def cmd_MOVE_AVOIDING_DOCK(self, gcmd):

def attach_probe(self, return_pos=None, always_restore_toolhead=False):
self._lower_probe()
self.pre_attach_gcode.run_gcode_from_command()

retry = 0
while (
Expand Down Expand Up @@ -527,7 +542,10 @@ def attach_probe(self, return_pos=None, always_restore_toolhead=False):
# Do NOT return to the original Z position after attach
# as the probe might crash into the bed.

self.post_attach_gcode.run_gcode_from_command()

def detach_probe(self, return_pos=None):
self.pre_detach_gcode.run_gcode_from_command()
retry = 0
while (
self.get_probe_state() != PROBE_DOCKED
Expand All @@ -550,6 +568,8 @@ def detach_probe(self, return_pos=None):
if self.get_probe_state() != PROBE_DOCKED:
raise self.printer.command_error("Probe detach failed!")

self.post_detach_gcode.run_gcode_from_command()

if return_pos and self.restore_toolhead:
# return to the original XY position, if inside safe_dock area
# move to the closest point
Expand Down

0 comments on commit d8fa86f

Please sign in to comment.