gcode: Handle M117 and M118 commands that start with a special character

Commit 7ef7bf60 broke the special handling for M117 commands that
start with a number or special character.  Fix that support and extend
to M118 as well.

Also improve handling of commands not separated by a space (eg,
"M117HELLO").

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-01-18 11:21:53 -05:00
parent 02d5f9754f
commit f97fd7c6e3
1 changed files with 10 additions and 11 deletions

View File

@ -27,20 +27,19 @@ class GCodeCommand:
def get_command_parameters(self): def get_command_parameters(self):
return self._params return self._params
def get_raw_command_parameters(self): def get_raw_command_parameters(self):
rawparams = self._commandline
command = self._command command = self._command
if command.startswith("M117 ") or command.startswith("M118 "):
command = command[:4]
rawparams = self._commandline
urawparams = rawparams.upper() urawparams = rawparams.upper()
if not urawparams.startswith(command): if not urawparams.startswith(command):
start = urawparams.find(command) rawparams = rawparams[urawparams.find(command):]
end = rawparams.rfind('*') end = rawparams.rfind('*')
if end >= 0: if end >= 0:
rawparams = rawparams[:end] rawparams = rawparams[:end]
rawparams = rawparams[start:] rawparams = rawparams[len(command):]
commandlen = len(command) + 1 if rawparams.startswith(' '):
if len(rawparams) > commandlen: rawparams = rawparams[1:]
rawparams = rawparams[commandlen:]
else:
rawparams = ''
return rawparams return rawparams
def ack(self, msg=None): def ack(self, msg=None):
if not self._need_ack: if not self._need_ack:
@ -277,9 +276,9 @@ class GCodeDispatch:
if cmdline: if cmdline:
logging.debug(cmdline) logging.debug(cmdline)
return return
if cmd.startswith("M117 "): if cmd.startswith("M117 ") or cmd.startswith("M118 "):
# Handle M117 gcode with numeric and special characters # Handle M117/M118 gcode with numeric and special characters
handler = self.gcode_handlers.get("M117", None) handler = self.gcode_handlers.get(cmd[:4], None)
if handler is not None: if handler is not None:
handler(gcmd) handler(gcmd)
return return