Skip to content

Commit

Permalink
Extras: unregister overrides on klippy:disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Dec 18, 2024
1 parent ec36942 commit a0b1589
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions configuration/klippy/ratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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 @@ -55,6 +56,10 @@ def _connect(self):

# Register overrides.
self.register_command_overrides()

def _disconnect(self):
self.unregister_command_overrides()

#####
# Settings
#####
Expand Down Expand Up @@ -88,6 +93,10 @@ 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):
prev_cmd = self.gcode.register_command(command, None)
if prev_cmd is None:
Expand All @@ -99,6 +108,12 @@ def register_override(self, command, func, desc):
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 a0b1589

Please sign in to comment.