From 767c87810bee492c6cc5a2611b8f08c2a295926f Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Fri, 4 Oct 2024 07:19:42 +1300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20GCODE=5FCASE=5FINSENSITIVE=20for?= =?UTF-8?q?=20Emergency=20Parser=20(#27449)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/feature/e_parser.cpp | 26 +++++++++----------------- Marlin/src/gcode/parser.cpp | 4 +--- Marlin/src/gcode/parser.h | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Marlin/src/feature/e_parser.cpp b/Marlin/src/feature/e_parser.cpp index da193ed30aba..e249d819690c 100644 --- a/Marlin/src/feature/e_parser.cpp +++ b/Marlin/src/feature/e_parser.cpp @@ -61,9 +61,13 @@ extern bool wait_for_user, wait_for_heatup; #endif void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) { + auto uppercase = [](char c) { + return TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')) ? c + 'A' - 'a' : c; + }; + switch (state) { case EP_RESET: - switch (c) { + switch (uppercase(c)) { case ' ': case '\n': case '\r': break; case 'N': state = EP_N; break; case 'M': state = EP_M; break; @@ -81,7 +85,7 @@ void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) { break; case EP_N: - switch (c) { + switch (uppercase(c)) { case '0' ... '9': case '-': case ' ': break; case 'M': state = EP_M; break; @@ -152,20 +156,8 @@ void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) { #endif #if ENABLED(EP_BABYSTEPPING) - case EP_M2: - switch (c) { - case '9': state = EP_M29; break; - default: state = EP_IGNORE; - } - break; - - case EP_M29: - switch (c) { - case '3': state = EP_M293; break; - case '4': state = EP_M294; break; - default: state = EP_IGNORE; - } - break; + case EP_M2: state = (c == '9') ? EP_M29 : EP_IGNORE; break; + case EP_M29: state = (c == '3') ? EP_M293 : (c == '4') ? EP_M294 : EP_IGNORE; break; #endif #if ENABLED(HOST_PROMPT_SUPPORT) @@ -174,7 +166,7 @@ void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) { case EP_M87: state = (c == '6') ? EP_M876 : EP_IGNORE; break; case EP_M876: - switch (c) { + switch (uppercase(c)) { case ' ': break; case 'S': state = EP_M876S; break; default: state = EP_IGNORE; break; diff --git a/Marlin/src/gcode/parser.cpp b/Marlin/src/gcode/parser.cpp index 3975cea50488..54ae8028631d 100644 --- a/Marlin/src/gcode/parser.cpp +++ b/Marlin/src/gcode/parser.cpp @@ -115,9 +115,7 @@ void GCodeParser::parse(char *p) { reset(); // No codes to report auto uppercase = [](char c) { - if (TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z'))) - c += 'A' - 'a'; - return c; + return TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')) ? c + 'A' - 'a' : c; }; // Skip spaces diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 94c5b284e06f..51ecaf15e9ad 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -192,7 +192,7 @@ class GCodeParser { #if ENABLED(GCODE_CASE_INSENSITIVE) FORCE_INLINE static char* strgchr(char *p, char g) { auto uppercase = [](char c) { - return c + (WITHIN(c, 'a', 'z') ? 'A' - 'a' : 0); + return TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')) ? c + 'A' - 'a' : c; }; const char d = uppercase(g); for (char cc; (cc = uppercase(*p)); p++) if (cc == d) return p;