|
@@ -173,7 +173,7 @@ void GcodeSuite::dwell(millis_t time) {
|
173
|
173
|
* Process the parsed command and dispatch it to its handler
|
174
|
174
|
*/
|
175
|
175
|
void GcodeSuite::process_parsed_command(
|
176
|
|
- #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
|
|
176
|
+ #if USE_EXECUTE_COMMANDS_IMMEDIATE
|
177
|
177
|
const bool no_ok
|
178
|
178
|
#endif
|
179
|
179
|
) {
|
|
@@ -698,7 +698,7 @@ void GcodeSuite::process_parsed_command(
|
698
|
698
|
|
699
|
699
|
KEEPALIVE_STATE(NOT_BUSY);
|
700
|
700
|
|
701
|
|
- #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
|
|
701
|
+ #if USE_EXECUTE_COMMANDS_IMMEDIATE
|
702
|
702
|
if (!no_ok)
|
703
|
703
|
#endif
|
704
|
704
|
ok_to_send();
|
|
@@ -725,35 +725,43 @@ void GcodeSuite::process_next_command() {
|
725
|
725
|
process_parsed_command();
|
726
|
726
|
}
|
727
|
727
|
|
728
|
|
-#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
|
|
728
|
+#if USE_EXECUTE_COMMANDS_IMMEDIATE
|
|
729
|
+
|
729
|
730
|
/**
|
730
|
731
|
* Run a series of commands, bypassing the command queue to allow
|
731
|
732
|
* G-code "macros" to be called from within other G-code handlers.
|
732
|
733
|
*/
|
|
734
|
+
|
733
|
735
|
void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
|
734
|
|
- // Save the parser state
|
735
|
|
- char * const saved_cmd = parser.command_ptr;
|
736
|
|
-
|
737
|
|
- // Process individual commands in string
|
738
|
|
- while (pgm_read_byte_near(pgcode)) {
|
739
|
|
- // Break up string at '\n' delimiters
|
740
|
|
- PGM_P const delim = strchr_P(pgcode, '\n');
|
741
|
|
- size_t len = delim ? delim - pgcode : strlen_P(pgcode);
|
742
|
|
- char cmd[len + 1];
|
743
|
|
- strncpy_P(cmd, pgcode, len);
|
744
|
|
- cmd[len] = '\0';
|
745
|
|
- pgcode += len;
|
746
|
|
- if (delim) pgcode++;
|
747
|
|
-
|
748
|
|
- // Parse the next command in the string
|
749
|
|
- parser.parse(cmd);
|
750
|
|
- process_parsed_command(true);
|
|
736
|
+ char * const saved_cmd = parser.command_ptr; // Save the parser state
|
|
737
|
+ for (;;) {
|
|
738
|
+ PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline
|
|
739
|
+ const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length
|
|
740
|
+ char cmd[len + 1]; // Allocate a stack buffer
|
|
741
|
+ strncpy_P(cmd, pgcode, len); // Copy the command to the stack
|
|
742
|
+ cmd[len] = '\0'; // End with a nul
|
|
743
|
+ parser.parse(cmd); // Parse the command
|
|
744
|
+ process_parsed_command(true); // Process it
|
|
745
|
+ if (!delim) break; // Last command?
|
|
746
|
+ pgcode = delim + 1; // Get the next command
|
751
|
747
|
}
|
|
748
|
+ parser.parse(saved_cmd); // Restore the parser state
|
|
749
|
+ }
|
752
|
750
|
|
753
|
|
- // Restore the parser state
|
754
|
|
- parser.parse(saved_cmd);
|
|
751
|
+ void GcodeSuite::process_subcommands_now(char * gcode) {
|
|
752
|
+ char * const saved_cmd = parser.command_ptr; // Save the parser state
|
|
753
|
+ for (;;) {
|
|
754
|
+ const char * const delim = strchr(gcode, '\n'); // Get address of next newline
|
|
755
|
+ if (delim) *delim = '\0'; // Replace with nul
|
|
756
|
+ parser.parse(gcode); // Parse the current command
|
|
757
|
+ process_parsed_command(true); // Process it
|
|
758
|
+ if (!delim) break; // Last command?
|
|
759
|
+ gcode = delim + 1; // Get the next command
|
|
760
|
+ }
|
|
761
|
+ parser.parse(saved_cmd); // Restore the parser state
|
755
|
762
|
}
|
756
|
|
-#endif
|
|
763
|
+
|
|
764
|
+#endif // USE_EXECUTE_COMMANDS_IMMEDIATE
|
757
|
765
|
|
758
|
766
|
#if ENABLED(HOST_KEEPALIVE_FEATURE)
|
759
|
767
|
|