Skip to content

Commit

Permalink
🚸 GCODE_CASE_INSENSITIVE for Emergency Parser (#27449)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp authored Oct 3, 2024
1 parent 52b6c45 commit 767c878
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
26 changes: 9 additions & 17 deletions Marlin/src/feature/e_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/gcode/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 767c878

Please sign in to comment.