Browse Source

drain_queued_commands_P now returns true if there are more

Scott Lahteine 9 years ago
parent
commit
80277cc9c8
1 changed files with 19 additions and 20 deletions
  1. 19
    20
      Marlin/Marlin_main.cpp

+ 19
- 20
Marlin/Marlin_main.cpp View File

@@ -463,29 +463,28 @@ extern "C" {
463 463
 #endif //!SDSUPPORT
464 464
 
465 465
 /**
466
- * Inject the next command from the command queue, when possible
467
- * Return false only if no command was pending
466
+ * Inject the next "immediate" command, when possible.
467
+ * Return true if any immediate commands remain to inject.
468 468
  */
469 469
 static bool drain_queued_commands_P() {
470
-  if (!queued_commands_P) return false;
471
-
472
-  // Get the next 30 chars from the sequence of gcodes to run
473
-  char cmd[30];
474
-  strncpy_P(cmd, queued_commands_P, sizeof(cmd) - 1);
475
-  cmd[sizeof(cmd) - 1] = '\0';
476
-
477
-  // Look for the end of line, or the end of sequence
478
-  size_t i = 0;
479
-  char c;
480
-  while ((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command
481
-  cmd[i] = '\0';
482
-  if (enqueue_and_echo_command(cmd)) {      // buffer was not full (else we will retry later)
483
-    if (c)
484
-      queued_commands_P += i + 1; // move to next command
485
-    else
486
-      queued_commands_P = NULL;   // will have no more commands in the sequence
470
+  if (queued_commands_P != NULL) {
471
+    // Get the next gcode to run
472
+    size_t i = 0;
473
+    char c;
474
+    while ((c = queued_commands_P[i++]) && c != '\n') { };
475
+    if (i > 1) {
476
+      char cmd[i];
477
+      strncpy_P(cmd, queued_commands_P, i - 1);
478
+      cmd[i - 1] = '\0';
479
+      if (enqueue_and_echo_command(cmd)) {      // buffer was not full (else we will retry later)
480
+        if (c)
481
+          queued_commands_P += i;     // move to next command
482
+        else
483
+          queued_commands_P = NULL;   // no more commands in the sequence
484
+      }
485
+    }
487 486
   }
488
-  return true;
487
+  return (queued_commands_P != NULL); // any more left to add?
489 488
 }
490 489
 
491 490
 /**

Loading…
Cancel
Save