Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Klipper3d/klipper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Lamas <pedrolamas@gmail.com>2022-07-04 11:37:24 +0300
committerKevinOConnor <kevin@koconnor.net>2022-07-19 19:48:16 +0300
commit6be114d728b6a243bb7af990cf03a879ea74c0b8 (patch)
treea00bbeeae9cc51d66e7f803b2900050972c3b7ad
parent50b4d4c43c263d3e00252e3eafb418bf91055193 (diff)
docs: fix rawparams example by truncating comments
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
-rw-r--r--config/sample-macros.cfg23
-rw-r--r--docs/Command_Templates.md19
2 files changed, 28 insertions, 14 deletions
diff --git a/config/sample-macros.cfg b/config/sample-macros.cfg
index 97e39016b..3590268c3 100644
--- a/config/sample-macros.cfg
+++ b/config/sample-macros.cfg
@@ -175,6 +175,29 @@ gcode:
sensor.temperature,
sensor.humidity))}
+######################################################################
+# Override M117 command with rawparams
+######################################################################
+
+# The macro below will override the default M117 command to echo the message.
+#
+# It uses the rawparams pseudo-variable that contains the full unparsed
+# parameters that was passed to the M117 command.
+#
+# As this can include comments, we are trimming the text when a `;` or `#` is
+# found, and escaping any existing `"`
+
+[gcode_macro M117]
+rename_existing: M117.1
+gcode:
+ {% if rawparams %}
+ {% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
+ SET_DISPLAY_TEXT MSG="{escaped_msg}"
+ RESPOND TYPE=command MSG="{escaped_msg}"
+ {% else %}
+ SET_DISPLAY_TEXT
+ {% endif %}
+
# SDCard 'looping' (aka Marlin M808 commands) support
#
# Support SDCard looping
diff --git a/docs/Command_Templates.md b/docs/Command_Templates.md
index c89d85bc5..3435d6c16 100644
--- a/docs/Command_Templates.md
+++ b/docs/Command_Templates.md
@@ -130,22 +130,13 @@ gcode:
### The "rawparams" variable
-The full unparsed parameters for the running macro can be access via the `rawparams` pseudo-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:
+Note that this will include any comments that were part of the original command.
-```
-[gcode_macro M117]
-rename_existing: M117.1
-gcode:
- {% if rawparams %}
- {% set escaped_msg = rawparams|replace('"', '\\"') %}
- SET_DISPLAY_TEXT MSG="{escaped_msg}"
- RESPOND TYPE=command MSG="{escaped_msg}"
- {% else %}
- SET_DISPLAY_TEXT
- {% endif %}
-```
+See the [sample-macros.cfg](../config/sample-macros.cfg) file for an example
+showing how to override the `M117` command using `rawparams`.
### The "printer" Variable