aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Lamas <pedrolamas@gmail.com>2021-10-22 18:24:16 +0100
committerKevinOConnor <kevin@koconnor.net>2021-11-19 11:22:36 -0500
commit7ef7bf608a2e784505439e50c443f24e03f2f3cf (patch)
treec6b876414a92b9a23edc12df487a5afde60532ab
parenta5ec751406c12f063eb464bc4f577279452181ad (diff)
downloadkutter-7ef7bf608a2e784505439e50c443f24e03f2f3cf.tar.gz
kutter-7ef7bf608a2e784505439e50c443f24e03f2f3cf.tar.xz
kutter-7ef7bf608a2e784505439e50c443f24e03f2f3cf.zip
gcode_macro: Add "rawparams" pseudo-variable
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
-rw-r--r--docs/Command_Templates.md14
-rw-r--r--klippy/extras/display_status.py15
-rw-r--r--klippy/extras/gcode_macro.py1
-rw-r--r--klippy/extras/respond.py12
-rw-r--r--klippy/gcode.py16
5 files changed, 34 insertions, 24 deletions
diff --git a/docs/Command_Templates.md b/docs/Command_Templates.md
index f5c670ef..732ed1a1 100644
--- a/docs/Command_Templates.md
+++ b/docs/Command_Templates.md
@@ -129,6 +129,20 @@ gcode:
M140 S{bed_temp}
```
+### The "rawparams" variable
+
+The full unparsed parameters for the running macro can be access via the `rawparams` pseudo-variable.
+
+This is quite useful if you want to change the behavior of certain commands like the `M117`. For example:
+
+```
+[gcode_macro M117]
+rename_existing: M117.1
+gcode:
+ M117.1 { rawparams }
+ M118 { rawparams }
+```
+
### The "printer" Variable
It is possible to inspect (and alter) the current state of the printer
diff --git a/klippy/extras/display_status.py b/klippy/extras/display_status.py
index 05eca0a9..16a8878d 100644
--- a/klippy/extras/display_status.py
+++ b/klippy/extras/display_status.py
@@ -35,19 +35,8 @@ class DisplayStatus:
curtime = self.printer.get_reactor().monotonic()
self.expire_progress = curtime + M73_TIMEOUT
def cmd_M117(self, gcmd):
- msg = gcmd.get_commandline()
- umsg = msg.upper()
- if not umsg.startswith('M117'):
- # Parse out additional info if M117 recd during a print
- start = umsg.find('M117')
- end = msg.rfind('*')
- if end >= 0:
- msg = msg[:end]
- msg = msg[start:]
- if len(msg) > 5:
- self.message = msg[5:]
- else:
- self.message = None
+ msg = gcmd.get_raw_command_parameters() or None
+ self.message = msg
def load_config(config):
return DisplayStatus(config)
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py
index 8d55db3b..4f50c75a 100644
--- a/klippy/extras/gcode_macro.py
+++ b/klippy/extras/gcode_macro.py
@@ -180,6 +180,7 @@ class GCodeMacro:
kwparams = dict(self.variables)
kwparams.update(self.template.create_template_context())
kwparams['params'] = gcmd.get_command_parameters()
+ kwparams['rawparams'] = gcmd.get_raw_command_parameters()
self.in_script = True
try:
self.template.run_gcode_from_command(kwparams)
diff --git a/klippy/extras/respond.py b/klippy/extras/respond.py
index 0adbc4bf..fb6eb194 100644
--- a/klippy/extras/respond.py
+++ b/klippy/extras/respond.py
@@ -22,17 +22,7 @@ class HostResponder:
gcode.register_command('RESPOND', self.cmd_RESPOND, True,
desc=self.cmd_RESPOND_help)
def cmd_M118(self, gcmd):
- msg = gcmd.get_commandline()
- umsg = msg.upper()
- if not umsg.startswith('M118'):
- # Parse out additional info if M118 recd during a print
- start = umsg.find('M118')
- end = msg.rfind('*')
- msg = msg[start:end]
- if len(msg) > 5:
- msg = msg[5:]
- else:
- msg = ''
+ msg = gcmd.get_raw_command_parameters()
gcmd.respond_raw("%s %s" % (self.default_prefix, msg))
cmd_RESPOND_help = ("Echo the message prepended with a prefix")
def cmd_RESPOND(self, gcmd):
diff --git a/klippy/gcode.py b/klippy/gcode.py
index 66fc623c..0cd08d9e 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -26,6 +26,22 @@ class GCodeCommand:
return self._commandline
def get_command_parameters(self):
return self._params
+ def get_raw_command_parameters(self):
+ rawparams = self._commandline
+ command = self._command
+ urawparams = rawparams.upper()
+ if not urawparams.startswith(command):
+ start = urawparams.find(command)
+ end = rawparams.rfind('*')
+ if end >= 0:
+ rawparams = rawparams[:end]
+ rawparams = rawparams[start:]
+ commandlen = len(command) + 1
+ if len(rawparams) > commandlen:
+ rawparams = rawparams[commandlen:]
+ else:
+ rawparams = ''
+ return rawparams
def ack(self, msg=None):
if not self._need_ack:
return False