Browse Source

Fix parser value handling

Scott Lahteine 7 years ago
parent
commit
eacb6b6e8b
1 changed files with 16 additions and 6 deletions
  1. 16
    6
      Marlin/gcode.cpp

+ 16
- 6
Marlin/gcode.cpp View File

167
    * For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
167
    * For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
168
    */
168
    */
169
   string_arg = NULL;
169
   string_arg = NULL;
170
-  while (char code = *p++) {                    // Get the next parameter. A NUL ends the loop
170
+  while (const char code = *p++) {                    // Get the next parameter. A NUL ends the loop
171
 
171
 
172
     // Special handling for M32 [P] !/path/to/file.g#
172
     // Special handling for M32 [P] !/path/to/file.g#
173
     // The path must be the last parameter
173
     // The path must be the last parameter
188
     if (PARAM_TEST) {
188
     if (PARAM_TEST) {
189
 
189
 
190
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
190
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
191
-      const bool has_num = DECIMAL_SIGNED(*p);  // The parameter has a number [-+0-9.]
191
+
192
+      const bool has_num = NUMERIC(p[0])                            // [0-9]
193
+                        || (p[0] == '.' && NUMERIC(p[1]))           // .[0-9]
194
+                        || (
195
+                              (p[0] == '-' || p[0] == '+') && (     // [-+]
196
+                                NUMERIC(p[1])                       //     [0-9]
197
+                                || (p[1] == '.' && NUMERIC(p[2]))   //     .[0-9]
198
+                              )
199
+                            );
192
 
200
 
193
       #if ENABLED(DEBUG_GCODE_PARSER)
201
       #if ENABLED(DEBUG_GCODE_PARSER)
194
         if (debug) {
202
         if (debug) {
195
-          SERIAL_ECHOPAIR("Got letter ", code); // DEBUG
196
-          SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1)); // DEBUG
203
+          SERIAL_ECHOPAIR("Got letter ", code);
204
+          SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1));
197
           if (has_num) SERIAL_ECHOPGM(" (has_num)");
205
           if (has_num) SERIAL_ECHOPGM(" (has_num)");
198
         }
206
         }
199
       #endif
207
       #endif
210
       #endif
218
       #endif
211
 
219
 
212
       #if ENABLED(FASTER_GCODE_PARSER)
220
       #if ENABLED(FASTER_GCODE_PARSER)
221
+      {
213
         set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
222
         set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
214
           #if ENABLED(DEBUG_GCODE_PARSER)
223
           #if ENABLED(DEBUG_GCODE_PARSER)
215
             , debug
224
             , debug
216
           #endif
225
           #endif
217
         );
226
         );
227
+      }
218
       #endif
228
       #endif
219
     }
229
     }
220
     else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg
230
     else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg
224
       #endif
234
       #endif
225
     }
235
     }
226
 
236
 
227
-    if (!WITHIN(*p, 'A', 'Z')) {
228
-      while (*p && NUMERIC(*p)) p++;            // Skip over the value section of a parameter
237
+    if (!WITHIN(*p, 'A', 'Z')) {                // Another parameter right away?
238
+      while (*p && DECIMAL_SIGNED(*p)) p++;     // Skip over the value section of a parameter
229
       while (*p == ' ') p++;                    // Skip over all spaces
239
       while (*p == ' ') p++;                    // Skip over all spaces
230
     }
240
     }
231
   }
241
   }

Loading…
Cancel
Save