From 33c2c8f1bdca48eda4d00b8c5a98a3ba9f9e6644 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 20 May 2018 13:04:52 -0400 Subject: [PATCH] gcode: Raise an error if a duplicate command is registered Signed-off-by: Kevin O'Connor --- klippy/extras/homing_override.py | 1 + klippy/extras/virtual_sdcard.py | 1 + klippy/gcode.py | 2 ++ 3 files changed, 4 insertions(+) diff --git a/klippy/extras/homing_override.py b/klippy/extras/homing_override.py index 62a97aa4..f69298aa 100644 --- a/klippy/extras/homing_override.py +++ b/klippy/extras/homing_override.py @@ -12,6 +12,7 @@ class HomingOverride: self.script = config.get('gcode') self.in_script = False self.gcode = self.printer.lookup_object('gcode') + self.gcode.register_command("G28", None) self.gcode.register_command("G28", self.cmd_G28) def cmd_G28(self, params): if self.in_script: diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index 5a3a09a2..5d2780d7 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -19,6 +19,7 @@ class VirtualSD: self.work_timer = None # Register commands self.gcode = printer.lookup_object('gcode') + self.gcode.register_command('M21', None) for cmd in ['M20', 'M21', 'M23', 'M24', 'M25', 'M26', 'M27']: self.gcode.register_command(cmd, getattr(self, 'cmd_' + cmd)) for cmd in ['M28', 'M29', 'M30']: diff --git a/klippy/gcode.py b/klippy/gcode.py index d381620d..6cee4570 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -62,6 +62,8 @@ class GCodeParser: if cmd in self.base_gcode_handlers: del self.base_gcode_handlers[cmd] return + if cmd in self.ready_gcode_handlers: + raise error("gcode command %s already registered" % (cmd,)) if not (len(cmd) >= 2 and not cmd[0].isupper() and cmd[1].isdigit()): origfunc = func func = lambda params: origfunc(self.get_extended_params(params))