Skip to content

Commit

Permalink
Extras: return if function already correctly overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Dec 18, 2024
1 parent a0b1589 commit 24356cc
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions configuration/klippy/ratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -57,9 +56,6 @@ def _connect(self):
# Register overrides.
self.register_command_overrides()

def _disconnect(self):
self.unregister_command_overrides()

#####
# Settings
#####
Expand Down Expand Up @@ -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,))
Expand Down

0 comments on commit 24356cc

Please sign in to comment.