From 37f09ef57381227064698f0f908b0f70840b4f5b Mon Sep 17 00:00:00 2001 From: Lexi <156489988+lexidevs@users.noreply.github.com> Date: Sat, 2 Aug 2025 14:38:40 -0600 Subject: [PATCH] homing_override: Add rename_existing option Add the ability to rename the existing G28 command to something else (say, G90028), so that the original homing sequence can be used elsewhere. Signed-off-by: Lexi Roth --- docs/Config_Reference.md | 4 ++++ klippy/extras/homing_override.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index a9b6db6ce..8c62ad4ef 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1502,6 +1502,10 @@ gcode: # disables homing checks for that axis. This may be useful if the # head must move prior to invoking the normal G28 mechanism for an # axis. The default is to not force a position for an axis. +#rename_existing: +# If specified, this option will rename the original G28 command to +# the value specified here, allowing the unmodified homing sequence +# to be used outside of this block. ``` ### [endstop_phase] diff --git a/klippy/extras/homing_override.py b/klippy/extras/homing_override.py index 0a987d59c..ef9c662aa 100644 --- a/klippy/extras/homing_override.py +++ b/klippy/extras/homing_override.py @@ -15,8 +15,27 @@ class HomingOverride: self.in_script = False self.printer.load_object(config, 'homing') self.gcode = self.printer.lookup_object('gcode') + self.rename_existing = config.get('rename_existing', None) self.prev_G28 = self.gcode.register_command("G28", None) + if self.rename_existing is not None: + # Verify that the alias is also a traditional G-Code command + if not self.gcode.is_traditional_gcode(self.rename_existing): + raise config.error("Homing override: rename command '%s' is" + "not a traditional G-Code command" + % self.rename_existing) + # Register connect handler to rename the existing command + self.printer.register_event_handler("klippy:connect", + self.handle_connect) + + else: + self.gcode.register_command("G28", self.cmd_G28) + + def handle_connect(self): + pdesc = "Renamed builtin of 'G28'" + self.gcode.register_command(self.rename_existing, + self.prev_G28, desc=pdesc) self.gcode.register_command("G28", self.cmd_G28) + def cmd_G28(self, gcmd): if self.in_script: # Was called recursively - invoke the real G28 command