MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / CheckForUrgentCommand

Method CheckForUrgentCommand

src/GCodes/GCodeInput.cpp:118–204  ·  view source on GitHub ↗

Check a character for urgent commands: M112 (emergency stop), M122 (diagnostics) and M108 (cancel wait for temperature). Return true if an urgent command was handled and the buffer was reset

Source from the content-addressed store, hash-verified

116// Check a character for urgent commands: M112 (emergency stop), M122 (diagnostics) and M108 (cancel wait for temperature).
117// Return true if an urgent command was handled and the buffer was reset
118bool RegularGCodeInput::CheckForUrgentCommand(char c) noexcept
119{
120 if (writingFile)
121 {
122 return false;
123 }
124
125 switch (state)
126 {
127 case GCodeInputState::idle:
128 if (c > ' ')
129 {
130 state = (c == 'M' || c == 'm') ? GCodeInputState::doingMCode : GCodeInputState::doingCode;
131 }
132 break;
133
134 case GCodeInputState::doingCode:
135 if (c == 0 || c == '\r' || c == '\n')
136 {
137 state = GCodeInputState::idle;
138 }
139 break;
140
141 case GCodeInputState::doingMCode:
142 state = (c == '1') ? GCodeInputState::doingMCode1 : GCodeInputState::doingCode;
143 break;
144
145 case GCodeInputState::doingMCode1:
146 state = (c == '0') ? GCodeInputState::doingMCode10
147 : (c == '1') ? GCodeInputState::doingMCode11
148 : (c == '2') ? GCodeInputState::doingMCode12
149 : GCodeInputState::doingCode;
150 break;
151
152 case GCodeInputState::doingMCode10:
153 state = (c == '8') ? GCodeInputState::doingMCode108 : GCodeInputState::doingCode;
154 break;
155
156 case GCodeInputState::doingMCode11:
157 state = (c == '2') ? GCodeInputState::doingMCode112 : GCodeInputState::doingCode;
158 break;
159
160 case GCodeInputState::doingMCode12:
161 state = (c == '2') ? GCodeInputState::doingMCode122 : GCodeInputState::doingCode;
162 break;
163
164 case GCodeInputState::doingMCode108:
165 if (c < ' ' || c == ';')
166 {
167 reprap.GetGCodes().CancelWaitForTemperatures(false);
168 // Normally we would call Reset and then return here to prevent the command being executed twice.
169 // However, the host may be expecting an empty response, which we can't always send from here.
170 // So we allow the command to be queued and executed again, which is harmless.
171 }
172 state = GCodeInputState::doingCode;
173 break;
174
175 case GCodeInputState::doingMCode112:

Callers

nothing calls this directly

Calls 4

DeferredDiagnosticsMethod · 0.80
EmergencyStopMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected