Browse Source

Wait for end of line before invoking action

Scott Lahteine 8 years ago
parent
commit
bd5a825b8b
1 changed files with 20 additions and 9 deletions
  1. 20
    9
      Marlin/MarlinSerial.cpp

+ 20
- 9
Marlin/MarlinSerial.cpp View File

329
       state_M,
329
       state_M,
330
       state_M1,
330
       state_M1,
331
       state_M10,
331
       state_M10,
332
+      state_M108,
332
       state_M11,
333
       state_M11,
334
+      state_M112,
333
       state_M4,
335
       state_M4,
334
       state_M41,
336
       state_M41,
337
+      state_M410,
335
       state_IGNORE // to '\n'
338
       state_IGNORE // to '\n'
336
     };
339
     };
337
 
340
 
338
     static e_parser_state state = state_RESET;
341
     static e_parser_state state = state_RESET;
339
 
342
 
340
-    if (c == '\n') state = state_IGNORE;
341
-
342
     switch (state) {
343
     switch (state) {
343
       case state_RESET:
344
       case state_RESET:
344
         switch (c) {
345
         switch (c) {
378
         break;
379
         break;
379
 
380
 
380
       case state_M10:
381
       case state_M10:
381
-        if (c == '8') wait_for_heatup = false; // M108
382
-        state = state_IGNORE;
382
+        state = (c == '8') ? state_M108 : state_IGNORE;
383
         break;
383
         break;
384
 
384
 
385
       case state_M11:
385
       case state_M11:
386
-        if (c == '2') kill(PSTR(MSG_KILLED));  // M112
387
-        state = state_IGNORE;
386
+        state = (c == '2') ? state_M112 : state_IGNORE;
388
         break;
387
         break;
389
 
388
 
390
       case state_M4:
389
       case state_M4:
392
         break;
391
         break;
393
 
392
 
394
       case state_M41:
393
       case state_M41:
395
-        if (c == '0') quickstop_stepper();     // M410
396
-        state = state_IGNORE;
394
+        state = (c == '0') ? state_M410 : state_IGNORE;
397
         break;
395
         break;
398
 
396
 
399
       case state_IGNORE:
397
       case state_IGNORE:
401
         break;
399
         break;
402
 
400
 
403
       default:
401
       default:
404
-        state = state_RESET;
402
+        if (c == '\n') {
403
+          switch (state) {
404
+            case state_M108:
405
+              wait_for_heatup = false;
406
+              break;
407
+            case state_M112:
408
+              kill(PSTR(MSG_KILLED));
409
+              break;
410
+            case state_M410:
411
+              quickstop_stepper();
412
+              break;
413
+          }
414
+          state = state_RESET;
415
+        }
405
     }
416
     }
406
   }
417
   }
407
 #endif
418
 #endif

Loading…
Cancel
Save