diff --git a/configuration/klippy/ratos.py b/configuration/klippy/ratos.py index f7f6e1db0..1f7b89055 100644 --- a/configuration/klippy/ratos.py +++ b/configuration/klippy/ratos.py @@ -40,7 +40,6 @@ def __init__(self, config): ##### def register_handler(self): self.printer.register_event_handler("klippy:connect", self._connect) - self.printer.register_event_handler("klippy:disconnect", self._disconnect) def _connect(self): self.v_sd = self.printer.lookup_object('virtual_sdcard', None) @@ -57,9 +56,6 @@ def _connect(self): # Register overrides. self.register_command_overrides() - def _disconnect(self): - self.unregister_command_overrides() - ##### # Settings ##### @@ -93,27 +89,21 @@ def register_command_overrides(self): self.register_override('TEST_RESONANCES', self.override_TEST_RESONANCES, desc=(self.desc_TEST_RESONANCES)) self.register_override('SHAPER_CALIBRATE', self.override_SHAPER_CALIBRATE, desc=(self.desc_SHAPER_CALIBRATE)) - def unregister_command_overrides(self): - for command in self.OverriddenCommands: - self.gcode.unregister_command(command) - def register_override(self, command, func, desc): + if self.overriddenCommands[command] is not None: + if self.overriddenCommands[command] != command: + raise self.printer.config_error("Command '%s' is already overridden with a different function" % (command,)) + return + prev_cmd = self.gcode.register_command(command, None) if prev_cmd is None: raise self.printer.config_error("Existing command '%s' not found in RatOS override" % (command,)) if command not in self.OverriddenCommands: raise self.printer.config_error("Command '%s' not found in RatOS override list" % (command,)) - if self.OverriddenCommands[command] is not None: - raise self.printer.config_error("Command '%s' already overridden in RatOS" % (command,)) + self.OverriddenCommands[command] = prev_cmd; self.gcode.register_command(command, func, desc=(desc)) - def unregister_override(self, command): - if command not in self.OverriddenCommands or self.OverriddenCommands[command] is None: - raise self.printer.config_error("Previous function for command '%s' not found in RatOS override list" % (command,)) - self.gcode.register_command(command, self.OverriddenCommands[command], desc=desc) - self.OverriddenCommands[command] = None - def get_prev_cmd(self, command): if command not in self.OverriddenCommands or self.OverriddenCommands[command] is None: raise self.printer.config_error("Previous function for command '%s' not found in RatOS override list" % (command,))