From b9db623b38b1c662dcff037746e8d5b2648185fb Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Oct 2022 10:51:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20M118=20command=20to=20virtual?= =?UTF-8?q?=20printer=20(#4567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add M118 echo command on the virtual printer update string format by using format function for command M117 * clean up * Update src/octoprint/plugins/virtual_printer/virtual.py Add reg ex to match all , need to be tested Co-authored-by: Gina Häußge * fix regex suggestion Co-authored-by: Gina Häußge --- .../plugins/virtual_printer/virtual.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 09a1b3a66..979af71bb 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -700,10 +700,27 @@ class VirtualPrinter: # we'll just use this to echo a message, to allow playing around with pause triggers if self._echoOnM117: try: - self._send("echo:%s" % re.search(r"M117\s+(.*)", data).group(1)) + result = re.search(r"M117\s+(.*)", data).group(1) + self._send(f"echo:{result}") except AttributeError: self._send("echo:") + def _gcode_M118(self, data: str) -> None: + match = re.search(r"M118 (?:(?PA1|E1|Pn[012])\s)?(?P.*)", data) + if not match: + self._send("Unrecognized command parameters for M118") + else: + result = match.groupdict() + text = result["text"] + parameter = result["parameter"] + + if parameter == "A1": + self._send(f"//{text}") + elif parameter == "E1": + self._send(f"echo:{text}") + else: + self._send(text) + def _gcode_M154(self, data: str) -> None: matchS = re.search(r"S([0-9]+)", data) if matchS is not None: