From 4c8751727acf20cb8d3dece88df1c8bf4d3f8cd3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 12 Apr 2018 19:10:04 -0500 Subject: [PATCH] Fix M118 parameter handling Fix #10388 --- Marlin/src/gcode/host/M118.cpp | 15 ++++++++++++--- Marlin/src/gcode/parser.cpp | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Marlin/src/gcode/host/M118.cpp b/Marlin/src/gcode/host/M118.cpp index aadf2d06c5..674ad6b802 100644 --- a/Marlin/src/gcode/host/M118.cpp +++ b/Marlin/src/gcode/host/M118.cpp @@ -29,7 +29,16 @@ * E1 Have the host 'echo:' the text */ void GcodeSuite::M118() { - if (parser.seenval('E') && parser.value_bool()) SERIAL_ECHO_START(); - if (parser.seenval('A') && parser.value_bool()) SERIAL_ECHOPGM("// "); - SERIAL_ECHOLN(parser.string_arg); + bool hasE = false, hasA = false; + char *p = parser.string_arg; + for (uint8_t i = 2; i--;) + if ((p[0] == 'A' || p[0] == 'E') && p[1] == '1') { + if (p[0] == 'A') hasA = true; + if (p[0] == 'E') hasE = true; + p += 2; + while (*p == ' ') ++p; + } + if (hasE) SERIAL_ECHO_START(); + if (hasA) SERIAL_ECHOPGM("// "); + SERIAL_ECHOLN(p); } diff --git a/Marlin/src/gcode/parser.cpp b/Marlin/src/gcode/parser.cpp index 339e225d52..392532646c 100644 --- a/Marlin/src/gcode/parser.cpp +++ b/Marlin/src/gcode/parser.cpp @@ -155,7 +155,7 @@ void GCodeParser::parse(char *p) { #endif // Only use string_arg for these M codes - if (letter == 'M') switch (codenum) { case 23: case 28: case 30: case 117: case 928: string_arg = p; return; default: break; } + if (letter == 'M') switch (codenum) { case 23: case 28: case 30: case 117: case 118: case 928: string_arg = p; return; default: break; } #if ENABLED(DEBUG_GCODE_PARSER) const bool debug = codenum == 800;