drain_queued_commands_P now returns true if there are more

master
Scott Lahteine 9 years ago
parent 8fe7420310
commit 80277cc9c8

@ -463,29 +463,28 @@ extern "C" {
#endif //!SDSUPPORT #endif //!SDSUPPORT
/** /**
* Inject the next command from the command queue, when possible * Inject the next "immediate" command, when possible.
* Return false only if no command was pending * Return true if any immediate commands remain to inject.
*/ */
static bool drain_queued_commands_P() { static bool drain_queued_commands_P() {
if (!queued_commands_P) return false; if (queued_commands_P != NULL) {
// Get the next gcode to run
// Get the next 30 chars from the sequence of gcodes to run size_t i = 0;
char cmd[30]; char c;
strncpy_P(cmd, queued_commands_P, sizeof(cmd) - 1); while ((c = queued_commands_P[i++]) && c != '\n') { };
cmd[sizeof(cmd) - 1] = '\0'; if (i > 1) {
char cmd[i];
// Look for the end of line, or the end of sequence strncpy_P(cmd, queued_commands_P, i - 1);
size_t i = 0; cmd[i - 1] = '\0';
char c; if (enqueue_and_echo_command(cmd)) { // buffer was not full (else we will retry later)
while ((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command if (c)
cmd[i] = '\0'; queued_commands_P += i; // move to next command
if (enqueue_and_echo_command(cmd)) { // buffer was not full (else we will retry later) else
if (c) queued_commands_P = NULL; // no more commands in the sequence
queued_commands_P += i + 1; // move to next command }
else }
queued_commands_P = NULL; // will have no more commands in the sequence
} }
return true; return (queued_commands_P != NULL); // any more left to add?
} }
/** /**

Loading…
Cancel
Save