|
|
|
@ -27,8 +27,14 @@
|
|
|
|
|
#ifndef _EMERGENCY_PARSER_H_
|
|
|
|
|
#define _EMERGENCY_PARSER_H_
|
|
|
|
|
|
|
|
|
|
// External references
|
|
|
|
|
extern volatile bool wait_for_user, wait_for_heatup;
|
|
|
|
|
void quickstop_stepper();
|
|
|
|
|
|
|
|
|
|
class EmergencyParser {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// Currently looking for: M108, M112, M410
|
|
|
|
|
enum State : char {
|
|
|
|
|
EP_RESET,
|
|
|
|
@ -45,14 +51,90 @@ class EmergencyParser {
|
|
|
|
|
EP_IGNORE // to '\n'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
static EmergencyParser::State state;
|
|
|
|
|
static bool killed_by_M112;
|
|
|
|
|
|
|
|
|
|
EmergencyParser() {}
|
|
|
|
|
|
|
|
|
|
static void update(const uint8_t c);
|
|
|
|
|
__attribute__((always_inline)) inline
|
|
|
|
|
static void update(State &state, const uint8_t c) {
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case EP_RESET:
|
|
|
|
|
switch (c) {
|
|
|
|
|
case ' ': break;
|
|
|
|
|
case 'N': state = EP_N; break;
|
|
|
|
|
case 'M': state = EP_M; break;
|
|
|
|
|
default: state = EP_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_N:
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '0': case '1': case '2':
|
|
|
|
|
case '3': case '4': case '5':
|
|
|
|
|
case '6': case '7': case '8':
|
|
|
|
|
case '9': case '-': case ' ': break;
|
|
|
|
|
case 'M': state = EP_M; break;
|
|
|
|
|
default: state = EP_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M:
|
|
|
|
|
switch (c) {
|
|
|
|
|
case ' ': break;
|
|
|
|
|
case '1': state = EP_M1; break;
|
|
|
|
|
case '4': state = EP_M4; break;
|
|
|
|
|
default: state = EP_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M1:
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '0': state = EP_M10; break;
|
|
|
|
|
case '1': state = EP_M11; break;
|
|
|
|
|
default: state = EP_IGNORE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M10:
|
|
|
|
|
state = (c == '8') ? EP_M108 : EP_IGNORE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M11:
|
|
|
|
|
state = (c == '2') ? EP_M112 : EP_IGNORE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M4:
|
|
|
|
|
state = (c == '1') ? EP_M41 : EP_IGNORE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_M41:
|
|
|
|
|
state = (c == '0') ? EP_M410 : EP_IGNORE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EP_IGNORE:
|
|
|
|
|
if (c == '\n') state = EP_RESET;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (c == '\n') {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case EP_M108:
|
|
|
|
|
wait_for_user = wait_for_heatup = false;
|
|
|
|
|
break;
|
|
|
|
|
case EP_M112:
|
|
|
|
|
killed_by_M112 = true;
|
|
|
|
|
break;
|
|
|
|
|
case EP_M410:
|
|
|
|
|
quickstop_stepper();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
state = EP_RESET;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|