|
@@ -132,6 +132,7 @@ inline bool _enqueuecommand(const char* cmd, bool say_ok=false
|
132
|
132
|
|
133
|
133
|
/**
|
134
|
134
|
* Enqueue with Serial Echo
|
|
135
|
+ * Return true if the command was consumed
|
135
|
136
|
*/
|
136
|
137
|
bool enqueue_and_echo_command(const char* cmd) {
|
137
|
138
|
|
|
@@ -139,10 +140,7 @@ bool enqueue_and_echo_command(const char* cmd) {
|
139
|
140
|
//SERIAL_ECHO(cmd);
|
140
|
141
|
//SERIAL_ECHOPGM("\") \n");
|
141
|
142
|
|
142
|
|
- if (*cmd == 0 || *cmd == '\n' || *cmd == '\r') {
|
143
|
|
- //SERIAL_ECHOLNPGM("Null command found... Did not queue!");
|
144
|
|
- return true;
|
145
|
|
- }
|
|
143
|
+ if (*cmd == 0 || *cmd == '\n' || *cmd == '\r') return true;
|
146
|
144
|
|
147
|
145
|
if (_enqueuecommand(cmd)) {
|
148
|
146
|
SERIAL_ECHO_START();
|
|
@@ -152,30 +150,81 @@ bool enqueue_and_echo_command(const char* cmd) {
|
152
|
150
|
return false;
|
153
|
151
|
}
|
154
|
152
|
|
|
153
|
+#if HAS_QUEUE_FRONT
|
|
154
|
+
|
|
155
|
+ bool early_cmd; // = false
|
|
156
|
+
|
|
157
|
+ /**
|
|
158
|
+ * Insert a high Priority command from RAM into the main command buffer.
|
|
159
|
+ * Return true if the command was consumed
|
|
160
|
+ * Return false for a full buffer, or if the 'command' is a comment.
|
|
161
|
+ */
|
|
162
|
+ inline bool _enqueuecommand_front(const char* cmd) {
|
|
163
|
+ if (*cmd == 0 || *cmd == '\n' || *cmd == '\r') return true;
|
|
164
|
+ if (*cmd == ';' || commands_in_queue >= BUFSIZE) return false;
|
|
165
|
+ if (cmd_queue_index_r == 0) cmd_queue_index_r = BUFSIZE;
|
|
166
|
+ --cmd_queue_index_r;
|
|
167
|
+ strcpy(command_queue[cmd_queue_index_r], cmd);
|
|
168
|
+ send_ok[cmd_queue_index_r] = false;
|
|
169
|
+ #if NUM_SERIAL > 1
|
|
170
|
+ command_queue_port[cmd_queue_index_r] = -1;
|
|
171
|
+ #endif
|
|
172
|
+ commands_in_queue++;
|
|
173
|
+ return true;
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ /**
|
|
177
|
+ * Insert in the front of queue, one or many commands to run from program memory.
|
|
178
|
+ * Aborts the current queue, if any.
|
|
179
|
+ * Note: drain_injected_commands_P() must be called repeatedly to drain the commands afterwards
|
|
180
|
+ */
|
|
181
|
+ void enqueue_and_echo_commands_front_P(PGM_P const pgcode) {
|
|
182
|
+ early_cmd = true;
|
|
183
|
+ enqueue_and_echo_commands_P(pgcode);
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+#endif
|
|
187
|
+
|
155
|
188
|
/**
|
156
|
189
|
* Inject the next "immediate" command, when possible, onto the front of the queue.
|
157
|
190
|
* Return true if any immediate commands remain to inject.
|
|
191
|
+ * Do not inject a comment or use leading space!.
|
158
|
192
|
*/
|
159
|
193
|
static bool drain_injected_commands_P() {
|
160
|
|
- if (injected_commands_P != nullptr) {
|
|
194
|
+ while (injected_commands_P != nullptr) {
|
161
|
195
|
size_t i = 0;
|
162
|
196
|
char c, cmd[60];
|
163
|
197
|
strncpy_P(cmd, injected_commands_P, sizeof(cmd) - 1);
|
164
|
198
|
cmd[sizeof(cmd) - 1] = '\0';
|
165
|
199
|
while ((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command
|
166
|
200
|
cmd[i] = '\0';
|
167
|
|
- if (enqueue_and_echo_command(cmd)) // success?
|
|
201
|
+
|
|
202
|
+ if (
|
|
203
|
+ #if HAS_QUEUE_FRONT
|
|
204
|
+ early_cmd ? _enqueuecommand_front(cmd) :
|
|
205
|
+ #endif
|
|
206
|
+ enqueue_and_echo_command(cmd)
|
|
207
|
+ ) {
|
168
|
208
|
injected_commands_P = c ? injected_commands_P + i + 1 : nullptr; // next command or done
|
|
209
|
+ #if HAS_QUEUE_FRONT
|
|
210
|
+ if (!c) early_cmd = false;
|
|
211
|
+ #endif
|
|
212
|
+ }
|
|
213
|
+ else
|
|
214
|
+ return true; // buffer is full (or command is comment);
|
169
|
215
|
}
|
170
|
|
- return (injected_commands_P != nullptr); // return whether any more remain
|
|
216
|
+ return false; // return whether any more remain
|
171
|
217
|
}
|
172
|
218
|
|
173
|
219
|
/**
|
174
|
|
- * Record one or many commands to run from program memory.
|
|
220
|
+ * Enqueue one or many commands to run from program memory.
|
175
|
221
|
* Aborts the current queue, if any.
|
176
|
222
|
* Note: drain_injected_commands_P() must be called repeatedly to drain the commands afterwards
|
177
|
223
|
*/
|
178
|
224
|
void enqueue_and_echo_commands_P(PGM_P const pgcode) {
|
|
225
|
+ #if HAS_QUEUE_FRONT
|
|
226
|
+ early_cmd = false;
|
|
227
|
+ #endif
|
179
|
228
|
injected_commands_P = pgcode;
|
180
|
229
|
(void)drain_injected_commands_P(); // first command executed asap (when possible)
|
181
|
230
|
}
|