gcode: Return previous handler from register_command(cmd, None)
When overriding a g-code command, allow the caller to obtain the previous command handler. Use this feature in homing_override and safe_z_home. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
512ad4b3a4
commit
0cfab84e1a
|
@ -14,12 +14,12 @@ class HomingOverride:
|
|||
self.template = gcode_macro.load_template(config, 'gcode')
|
||||
self.in_script = False
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command("G28", None)
|
||||
self.prev_G28 = self.gcode.register_command("G28", None)
|
||||
self.gcode.register_command("G28", self.cmd_G28)
|
||||
def cmd_G28(self, params):
|
||||
if self.in_script:
|
||||
# Was called recursively - invoke the real G28 command
|
||||
self.gcode.cmd_G28(params)
|
||||
self.prev_G28(params)
|
||||
return
|
||||
|
||||
# if no axis is given as parameter we assume the override
|
||||
|
|
|
@ -21,7 +21,7 @@ class SafeZHoming:
|
|||
self.speed = config.getfloat('speed', 50.0, above=0.)
|
||||
self.move_to_previous = config.getboolean('move_to_previous', False)
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command("G28", None)
|
||||
self.prev_G28 = self.gcode.register_command("G28", None)
|
||||
self.gcode.register_command("G28", self.cmd_G28)
|
||||
|
||||
if config.has_section("homing_override"):
|
||||
|
@ -63,7 +63,7 @@ class SafeZHoming:
|
|||
if need_y:
|
||||
new_params['Y'] = '0'
|
||||
if new_params:
|
||||
self.gcode.cmd_G28(new_params)
|
||||
self.prev_G28(new_params)
|
||||
# Home Z axis if necessary
|
||||
if need_z:
|
||||
# Move to safe XY homing position
|
||||
|
@ -75,7 +75,7 @@ class SafeZHoming:
|
|||
toolhead.move(pos, self.speed)
|
||||
self.gcode.reset_last_position()
|
||||
# Home Z
|
||||
self.gcode.cmd_G28({'Z': '0'})
|
||||
self.prev_G28({'Z': '0'})
|
||||
# Perform Z Hop again for pressure-based probes
|
||||
pos = toolhead.get_position()
|
||||
if self.z_hop:
|
||||
|
|
|
@ -71,11 +71,12 @@ class GCodeParser:
|
|||
return False
|
||||
def register_command(self, cmd, func, when_not_ready=False, desc=None):
|
||||
if func is None:
|
||||
old_cmd = self.ready_gcode_handlers.get(cmd)
|
||||
if cmd in self.ready_gcode_handlers:
|
||||
del self.ready_gcode_handlers[cmd]
|
||||
if cmd in self.base_gcode_handlers:
|
||||
del self.base_gcode_handlers[cmd]
|
||||
return
|
||||
return old_cmd
|
||||
if cmd in self.ready_gcode_handlers:
|
||||
raise self.printer.config_error(
|
||||
"gcode command %s already registered" % (cmd,))
|
||||
|
|
Loading…
Reference in New Issue