Prusa MINI Firmware overview
emergency_parser.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 /**
25  * emergency_parser.h - Intercept special commands directly in the serial stream
26  */
27 
28 #include "../inc/MarlinConfigPre.h"
29 
30 #if ENABLED(HOST_PROMPT_SUPPORT)
31  #include "host_actions.h"
32 #endif
33 
34 // External references
35 extern bool wait_for_user, wait_for_heatup;
36 void quickstop_stepper();
37 
39 
40 public:
41 
42  // Currently looking for: M108, M112, M410, M876
43  enum State : char {
55  #if ENABLED(HOST_PROMPT_SUPPORT)
56  EP_M8,
57  EP_M87,
58  EP_M876,
59  EP_M876S,
60  EP_M876SN,
61  #endif
62  EP_IGNORE // to '\n'
63  };
64 
65  static bool killed_by_M112;
66 
67  #if ENABLED(HOST_PROMPT_SUPPORT)
68  static uint8_t M876_reason;
69  #endif
70 
72 
73  FORCE_INLINE static void enable() { enabled = true; }
74 
75  FORCE_INLINE static void disable() { enabled = false; }
76 
77  FORCE_INLINE static void update(State &state, const uint8_t c) {
78  switch (state) {
79  case EP_RESET:
80  switch (c) {
81  case ' ': break;
82  case 'N': state = EP_N; break;
83  case 'M': state = EP_M; break;
84  default: state = EP_IGNORE;
85  }
86  break;
87 
88  case EP_N:
89  switch (c) {
90  case '0': case '1': case '2':
91  case '3': case '4': case '5':
92  case '6': case '7': case '8':
93  case '9': case '-': case ' ': break;
94  case 'M': state = EP_M; break;
95  default: state = EP_IGNORE;
96  }
97  break;
98 
99  case EP_M:
100  switch (c) {
101  case ' ': break;
102  case '1': state = EP_M1; break;
103  case '4': state = EP_M4; break;
104  #if ENABLED(HOST_PROMPT_SUPPORT)
105  case '8': state = EP_M8; break;
106  #endif
107  default: state = EP_IGNORE;
108  }
109  break;
110 
111  case EP_M1:
112  switch (c) {
113  case '0': state = EP_M10; break;
114  case '1': state = EP_M11; break;
115  default: state = EP_IGNORE;
116  }
117  break;
118 
119  case EP_M10:
120  state = (c == '8') ? EP_M108 : EP_IGNORE;
121  break;
122 
123  case EP_M11:
124  state = (c == '2') ? EP_M112 : EP_IGNORE;
125  break;
126 
127  case EP_M4:
128  state = (c == '1') ? EP_M41 : EP_IGNORE;
129  break;
130 
131  case EP_M41:
132  state = (c == '0') ? EP_M410 : EP_IGNORE;
133  break;
134 
135  #if ENABLED(HOST_PROMPT_SUPPORT)
136  case EP_M8:
137  state = (c == '7') ? EP_M87 : EP_IGNORE;
138  break;
139 
140  case EP_M87:
141  state = (c == '6') ? EP_M876 : EP_IGNORE;
142  break;
143 
144  case EP_M876:
145  switch (c) {
146  case ' ': break;
147  case 'S': state = EP_M876S; break;
148  default: state = EP_IGNORE; break;
149  }
150  break;
151 
152  case EP_M876S:
153  switch (c) {
154  case ' ': break;
155  case '0': case '1': case '2':
156  case '3': case '4': case '5':
157  case '6': case '7': case '8':
158  case '9':
159  state = EP_M876SN;
160  M876_reason = (uint8_t)(c - '0');
161  break;
162  }
163  break;
164  #endif
165 
166  case EP_IGNORE:
167  if (c == '\n') state = EP_RESET;
168  break;
169 
170  default:
171  if (c == '\n') {
172  if (enabled) switch (state) {
173  case EP_M108: wait_for_user = wait_for_heatup = false; break;
174  case EP_M112: killed_by_M112 = true; break;
175  case EP_M410: quickstop_stepper(); break;
176  #if ENABLED(HOST_PROMPT_SUPPORT)
177  case EP_M876SN: host_response_handler(M876_reason); break;
178  #endif
179  default: break;
180  }
181  state = EP_RESET;
182  }
183  }
184  }
185 
186 private:
187  static bool enabled;
188 };
189 
WITHIN
#define WITHIN(N, L, H)
Definition: macros.h:195
EmergencyParser::EP_N
Definition: emergency_parser.h:45
EmergencyParser::update
static FORCE_INLINE void update(State &state, const uint8_t c)
Definition: emergency_parser.h:77
host_response_handler
void host_response_handler(const uint8_t response)
Definition: marlin_server.cpp:1029
PROGMEM
#define PROGMEM
Definition: pgmspace.h:29
EmergencyParser::EmergencyParser
EmergencyParser()
Definition: emergency_parser.h:71
DIGIPOTS_I2C_SCL
#define DIGIPOTS_I2C_SCL
Definition: pins_MIGHTYBOARD_REVE.h:111
X_AXIS
Definition: types.h:37
TwoWire::beginTransmission
void beginTransmission(uint8_t)
Definition: Wire.cpp:16
digipot_i2c_set_current
void digipot_i2c_set_current(const uint8_t channel, const float current)
_MAX
#define _MAX(V...)
Definition: macros.h:346
I2C_ADDRESS
#define I2C_ADDRESS(A)
Definition: macros.h:292
EmergencyParser::EP_M11
Definition: emergency_parser.h:50
DIGIPOT_I2C_ADDRESS_A
#define DIGIPOT_I2C_ADDRESS_A
Definition: pins_AZTEEG_X5_MINI.h:85
DIGIPOTS_I2C_SDA_Z
#define DIGIPOTS_I2C_SDA_Z
Definition: pins_MIGHTYBOARD_REVE.h:114
i
uint8_t i
Definition: screen_test_graph.c:72
_MIN
#define _MIN(V...)
Definition: macros.h:333
EmergencyParser::EP_M108
Definition: emergency_parser.h:49
state
static volatile fsensor_t state
Definition: filament_sensor.c:23
EmergencyParser::EP_M
Definition: emergency_parser.h:46
DIGIPOT_I2C_ADDRESS_B
#define DIGIPOT_I2C_ADDRESS_B
Definition: pins_AZTEEG_X5_MINI.h:89
EmergencyParser::killed_by_M112
static bool killed_by_M112
Definition: emergency_parser.h:65
Wire.h
DIGIPOTS_I2C_SDA_E0
#define DIGIPOTS_I2C_SDA_E0
Definition: pins_MIGHTYBOARD_REVE.h:115
wait_for_user
bool wait_for_user
Definition: Marlin.cpp:188
emergency_parser
EmergencyParser emergency_parser
DIGIPOTS_I2C_SDA_X
#define DIGIPOTS_I2C_SDA_X
Definition: pins_MIGHTYBOARD_REVE.h:112
DIGIPOT_I2C_NUM_CHANNELS
#define DIGIPOT_I2C_NUM_CHANNELS
Definition: Configuration_A3ides_2209_MINI_adv.h:700
FORCE_INLINE
#define FORCE_INLINE
Definition: macros.h:40
TwoWire::write
virtual size_t write(uint8_t)
Definition: Wire.cpp:32
EmergencyParser::EP_M112
Definition: emergency_parser.h:51
Wire
TwoWire Wire
Definition: Wire.cpp:60
COUNT
#define COUNT(a)
Definition: macros.h:200
EmergencyParser::EP_M41
Definition: emergency_parser.h:53
DIGIPOTS_I2C_SDA_Y
#define DIGIPOTS_I2C_SDA_Y
Definition: pins_MIGHTYBOARD_REVE.h:113
TwoWire::begin
void begin(void)
Definition: Wire.cpp:13
EmergencyParser::enable
static FORCE_INLINE void enable()
Definition: emergency_parser.h:73
CEIL
#define CEIL(x)
Definition: macros.h:283
EmergencyParser::disable
static FORCE_INLINE void disable()
Definition: emergency_parser.h:75
constrain
#define constrain(amt, low, high)
Definition: wiring_constants.h:79
pgm_read_float
#define pgm_read_float(addr)
Definition: pgmspace.h:109
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
EmergencyParser::EP_M410
Definition: emergency_parser.h:54
uint8_t
const uint8_t[]
Definition: 404_html.c:3
DIGIPOT_I2C_MOTOR_CURRENTS
#define DIGIPOT_I2C_MOTOR_CURRENTS
Definition: Configuration_A3ides_2209_MINI_adv.h:703
emergency_parser.h
DIGIPOTS_I2C_SDA_E1
#define DIGIPOTS_I2C_SDA_E1
Definition: pins_MIGHTYBOARD_REVE.h:116
Y_AXIS
Definition: types.h:38
EmergencyParser::EP_IGNORE
Definition: emergency_parser.h:62
Z_AXIS
Definition: types.h:39
EmergencyParser::State
State
Definition: emergency_parser.h:43
host_actions.h
quickstop_stepper
void quickstop_stepper()
Definition: Marlin.cpp:272
EmergencyParser::EP_M1
Definition: emergency_parser.h:47
TwoWire::endTransmission
uint8_t endTransmission(void)
Definition: Wire.cpp:20
EmergencyParser::EP_M10
Definition: emergency_parser.h:48
EmergencyParser::EP_RESET
Definition: emergency_parser.h:44
E_AXIS
Definition: types.h:40
EmergencyParser::EP_M4
Definition: emergency_parser.h:52
wait_for_heatup
bool wait_for_heatup
Definition: Marlin.cpp:184
byte
uint8_t byte
Definition: wiring_constants.h:112
createSpeedLookupTable.b
list b
Definition: createSpeedLookupTable.py:30
digipot_i2c_init
void digipot_i2c_init()
Stream.h
EmergencyParser
Definition: emergency_parser.h:38