@@ -149,13 +149,31 @@ void GCodeParser::parse(char *p) {
149149 #define SIGNED_CODENUM 1
150150 #endif
151151
152+ /* *
153+ * Screen for good command letters.
154+ * With Realtime Reporting, commands S000, P000, and R000 are allowed.
155+ */
156+ #if ENABLED(REALTIME_REPORTING_COMMANDS)
157+ switch (letter) {
158+ case ' P' : case ' R' ... ' S' : {
159+ uint8_t digits = 0 ;
160+ char *a = p;
161+ while (*a++ == ' 0' ) digits++; // Count up '0' characters
162+ if (digits == 3 ) { // Three '0' digits is a good command
163+ codenum = 0 ;
164+ command_letter = letter;
165+ return ;
166+ }
167+ }
168+ }
169+ #endif
170+
152171 /* *
153172 * Screen for good command letters. G, M, and T are always accepted.
154173 * With Motion Modes enabled any axis letter can come first.
155- * With Realtime Reporting, commands S000, P000, and R000 are allowed.
156174 */
157175 switch (letter) {
158- case ' G' : case ' M' : case ' T' : TERN_ (MARLIN_DEV_MODE, case ' D' :)
176+ case ' G' : case ' M' : case ' T' : TERN_ (MARLIN_DEV_MODE, case ' D' :) {
159177 // Skip spaces to get the numeric part
160178 while (*p == ' ' ) p++;
161179
@@ -177,20 +195,18 @@ void GCodeParser::parse(char *p) {
177195 // A '?' signifies an unknown command
178196 command_letter = letter;
179197
180- {
181- #if ENABLED(SIGNED_CODENUM)
182- int sign = 1 ; // Allow for a negative code like D-1 or T-1
183- if (*p == ' -' ) { sign = -1 ; ++p; }
184- #endif
198+ #if ENABLED(SIGNED_CODENUM)
199+ int sign = 1 ; // Allow for a negative code like D-1 or T-1
200+ if (*p == ' -' ) { sign = -1 ; ++p; }
201+ #endif
185202
186- // Get the code number - integer digits only
187- codenum = 0 ;
203+ // Get the code number - integer digits only
204+ codenum = 0 ;
188205
189- do { codenum = codenum * 10 + *p++ - ' 0' ; } while (NUMERIC (*p));
206+ do { codenum = codenum * 10 + *p++ - ' 0' ; } while (NUMERIC (*p));
190207
191- // Apply the sign, if any
192- TERN_ (SIGNED_CODENUM, codenum *= sign);
193- }
208+ // Apply the sign, if any
209+ TERN_ (SIGNED_CODENUM, codenum *= sign);
194210
195211 // Allow for decimal point in command
196212 #if USE_GCODE_SUBCODES
@@ -213,57 +229,46 @@ void GCodeParser::parse(char *p) {
213229 }
214230 #endif
215231
216- break ;
232+ } break ;
217233
218234 #if ENABLED(GCODE_MOTION_MODES)
219- case ' I' ... ' J' :
220- if (motion_mode_codenum != 5 && \
221- TERN1 (ARC_SUPPORT, motion_mode_codenum != 2 && motion_mode_codenum != 3 )) return ;
222- case ' Q' :
223- if (motion_mode_codenum != 5 ) return ;
235+
236+ #if EITHER(BEZIER_CURVE_SUPPORT, ARC_SUPPORT)
237+ case ' I' ... ' J' : case ' P' :
238+ if (TERN1 (BEZIER_CURVE_SUPPORT, motion_mode_codenum != 5 )
239+ && TERN1 (ARC_P_CIRCLES, !WITHIN (motion_mode_codenum, 2 , 3 ))
240+ ) return ;
241+ #endif
242+
243+ #if ENABLED(BEZIER_CURVE_SUPPORT)
244+ case ' Q' : if (motion_mode_codenum != 5 ) return ;
245+ #endif
246+
247+ #if ENABLED(ARC_SUPPORT)
248+ case ' R' : if (!WITHIN (motion_mode_codenum, 2 , 3 )) return ;
249+ #endif
250+
224251 case ' X' ... ' Z' : case ' E' ... ' F' :
225252 if (motion_mode_codenum < 0 ) return ;
226253 command_letter = ' G' ;
227254 codenum = motion_mode_codenum;
228255 TERN_ (USE_GCODE_SUBCODES, subcode = motion_mode_subcode);
229256 p--; // Back up one character to use the current parameter
230- break ;
231- #endif
257+ break ;
232258
233- #if ENABLED(REALTIME_REPORTING_COMMANDS)
234- case ' P' : case ' R' : {
235- if (letter == ' R' ) {
236- #if ENABLED(GCODE_MOTION_MODES)
237- if (ENABLED (ARC_SUPPORT) && !WITHIN (motion_mode_codenum, 2 , 3 )) return ;
238- #endif
239- }
240- else if (TERN0 (GCODE_MOTION_MODES, motion_mode_codenum != 5 )) return ;
241- } // fall-thru
242- case ' S' : {
243- codenum = 0 ; // The only valid codenum is 0
244- uint8_t digits = 0 ;
245- while (*p++ == ' 0' ) digits++; // Count up '0' characters
246- command_letter = (digits == 3 ) ? letter : ' ?' ; // Three '0' digits is a good command
247- } return ; // No parameters needed, so return now
248259 #endif
249260
250261 default : return ;
251262 }
252263
253264 // The command parameters (if any) start here, for sure!
254265
255- #if DISABLED(FASTER_GCODE_PARSER)
256- command_args = p; // Scan for parameters in seen()
257- #endif
266+ IF_DISABLED (FASTER_GCODE_PARSER, command_args = p); // Scan for parameters in seen()
258267
259268 // Only use string_arg for these M codes
260269 if (letter == ' M' ) switch (codenum) {
261- #if ENABLED(GCODE_MACROS)
262- case 810 ... 819 :
263- #endif
264- #if ENABLED(EXPECTED_PRINTER_CHECK)
265- case 16 :
266- #endif
270+ TERN_ (GCODE_MACROS, case 810 ... 819 :)
271+ TERN_ (EXPECTED_PRINTER_CHECK, case 16 :)
267272 case 23 : case 28 : case 30 : case 117 ... 118 : case 928 :
268273 string_arg = unescape_string (p);
269274 return ;
0 commit comments