✨ Add M118 command to virtual printer (#4567)

* 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 <gina@octoprint.org>

* fix regex suggestion

Co-authored-by: Gina Häußge <gina@octoprint.org>
This commit is contained in:
ChristianandGina Häußge authored and GitHub committed 2022-10-26 11:51:41 +02:00
1 parent c32ac84982
commit b9db623b38
1 file changed
+18 -1
@@ -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 (?:(?P<parameter>A1|E1|Pn[012])\s)?(?P<text>.*)", 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: