aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-05-25 12:33:01 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-05-25 12:40:06 -0400
commitc38a63d4db592177c86046e76d512c9e2a55955b (patch)
treeca1958ee1fb7a72d4f3276a24e8fff1b1c8eb0ab /klippy
parent29946383809bf79e521c3e33b276499842092915 (diff)
downloadkutter-c38a63d4db592177c86046e76d512c9e2a55955b.tar.gz
kutter-c38a63d4db592177c86046e76d512c9e2a55955b.tar.xz
kutter-c38a63d4db592177c86046e76d512c9e2a55955b.zip
gcode_macro: Add the ability to define custom g-code macros
Add the ability to add a custom g-code command that in turn executes one or more configured g-code commands. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/gcode_macro.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py
new file mode 100644
index 00000000..08ad3b74
--- /dev/null
+++ b/klippy/extras/gcode_macro.py
@@ -0,0 +1,29 @@
+# Add ability to define custom g-code macros
+#
+# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+
+class GCodeMacro:
+ def __init__(self, config):
+ self.alias = config.get_name().split()[1].upper()
+ self.script = config.get('gcode')
+ printer = config.get_printer()
+ self.gcode = printer.lookup_object('gcode')
+ try:
+ self.gcode.register_command(self.alias, self.cmd, desc=self.cmd_desc)
+ except self.gcode.error as e:
+ raise config.error(str(e))
+ self.in_script = False
+ cmd_desc = "G-Code macro"
+ def cmd(self, params):
+ if self.in_script:
+ raise self.gcode.error("Macro %s called recursively" % (self.alias,))
+ self.in_script = True
+ try:
+ self.gcode.run_script(self.script)
+ finally:
+ self.in_script = False
+
+def load_config_prefix(config):
+ return GCodeMacro(config)