Cleanup to emergency parser

Followup to #10516
This commit is contained in:
Scott Lahteine 2018-04-25 06:54:17 -05:00
parent 2242b98248
commit 8cc31d1b2e
2 changed files with 42 additions and 42 deletions

View file

@ -33,7 +33,7 @@
extern volatile bool wait_for_user, wait_for_heatup; extern volatile bool wait_for_user, wait_for_heatup;
void quickstop_stepper(); void quickstop_stepper();
EmergencyParser::State EmergencyParser::state = EmergencyParser::State::RESET; EmergencyParser::State EmergencyParser::state = EP_RESET;
bool EmergencyParser::killed_by_M112; // = false bool EmergencyParser::killed_by_M112; // = false
EmergencyParser emergency_parser; EmergencyParser emergency_parser;
@ -41,79 +41,79 @@ EmergencyParser emergency_parser;
void EmergencyParser::update(const uint8_t c) { void EmergencyParser::update(const uint8_t c) {
switch (state) { switch (state) {
case EmergencyParser::State::RESET: case EP_RESET:
switch (c) { switch (c) {
case ' ': break; case ' ': break;
case 'N': state = EmergencyParser::State::N; break; case 'N': state = EP_N; break;
case 'M': state = EmergencyParser::State::M; break; case 'M': state = EP_M; break;
default: state = EmergencyParser::State::IGNORE; default: state = EP_IGNORE;
} }
break; break;
case EmergencyParser::State::N: case EP_N:
switch (c) { switch (c) {
case '0': case '1': case '2': case '0': case '1': case '2':
case '3': case '4': case '5': case '3': case '4': case '5':
case '6': case '7': case '8': case '6': case '7': case '8':
case '9': case '-': case ' ': break; case '9': case '-': case ' ': break;
case 'M': state = EmergencyParser::State::M; break; case 'M': state = EP_M; break;
default: state = EmergencyParser::State::IGNORE; default: state = EP_IGNORE;
} }
break; break;
case EmergencyParser::State::M: case EP_M:
switch (c) { switch (c) {
case ' ': break; case ' ': break;
case '1': state = EmergencyParser::State::M1; break; case '1': state = EP_M1; break;
case '4': state = EmergencyParser::State::M4; break; case '4': state = EP_M4; break;
default: state = EmergencyParser::State::IGNORE; default: state = EP_IGNORE;
} }
break; break;
case EmergencyParser::State::M1: case EP_M1:
switch (c) { switch (c) {
case '0': state = EmergencyParser::State::M10; break; case '0': state = EP_M10; break;
case '1': state = EmergencyParser::State::M11; break; case '1': state = EP_M11; break;
default: state = EmergencyParser::State::IGNORE; default: state = EP_IGNORE;
} }
break; break;
case EmergencyParser::State::M10: case EP_M10:
state = (c == '8') ? EmergencyParser::State::M108 : EmergencyParser::State::IGNORE; state = (c == '8') ? EP_M108 : EP_IGNORE;
break; break;
case EmergencyParser::State::M11: case EP_M11:
state = (c == '2') ? EmergencyParser::State::M112 : EmergencyParser::State::IGNORE; state = (c == '2') ? EP_M112 : EP_IGNORE;
break; break;
case EmergencyParser::State::M4: case EP_M4:
state = (c == '1') ? EmergencyParser::State::M41 : EmergencyParser::State::IGNORE; state = (c == '1') ? EP_M41 : EP_IGNORE;
break; break;
case EmergencyParser::State::M41: case EP_M41:
state = (c == '0') ? EmergencyParser::State::M410 : EmergencyParser::State::IGNORE; state = (c == '0') ? EP_M410 : EP_IGNORE;
break; break;
case EmergencyParser::State::IGNORE: case EP_IGNORE:
if (c == '\n') state = EmergencyParser::State::RESET; if (c == '\n') state = EP_RESET;
break; break;
default: default:
if (c == '\n') { if (c == '\n') {
switch (state) { switch (state) {
case EmergencyParser::State::M108: case EP_M108:
wait_for_user = wait_for_heatup = false; wait_for_user = wait_for_heatup = false;
break; break;
case EmergencyParser::State::M112: case EP_M112:
killed_by_M112 = true; killed_by_M112 = true;
break; break;
case EmergencyParser::State::M410: case EP_M410:
quickstop_stepper(); quickstop_stepper();
break; break;
default: default:
break; break;
} }
state = EmergencyParser::State::RESET; state = EP_RESET;
} }
} }
} }

View file

@ -31,18 +31,18 @@ class EmergencyParser {
// Currently looking for: M108, M112, M410 // Currently looking for: M108, M112, M410
enum State : char { enum State : char {
RESET, EP_RESET,
N, EP_N,
M, EP_M,
M1, EP_M1,
M10, EP_M10,
M108, EP_M108,
M11, EP_M11,
M112, EP_M112,
M4, EP_M4,
M41, EP_M41,
M410, EP_M410,
IGNORE // to '\n' EP_IGNORE // to '\n'
}; };
public: public: