|
@@ -385,6 +385,8 @@ static int serial_count = 0;
|
385
|
385
|
static boolean comment_mode = false;
|
386
|
386
|
static char *strchr_pointer; ///< A pointer to find chars in the command string (X, Y, Z, E, etc.)
|
387
|
387
|
|
|
388
|
+const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
|
|
389
|
+
|
388
|
390
|
const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
|
389
|
391
|
|
390
|
392
|
// Inactivity shutdown
|
|
@@ -448,39 +450,64 @@ void serial_echopair_P(const char *s_P, unsigned long v)
|
448
|
450
|
}
|
449
|
451
|
#endif //!SDSUPPORT
|
450
|
452
|
|
451
|
|
-//adds an command to the main command buffer
|
452
|
|
-//thats really done in a non-safe way.
|
453
|
|
-//needs overworking someday
|
454
|
|
-void enquecommand(const char *cmd)
|
|
453
|
+//Injects the next command from the pending sequence of commands, when possible
|
|
454
|
+//Return false if and only if no command was pending
|
|
455
|
+static bool drain_queued_commands_P()
|
455
|
456
|
{
|
456
|
|
- if(buflen < BUFSIZE)
|
|
457
|
+ char cmd[30];
|
|
458
|
+ if(!queued_commands_P)
|
|
459
|
+ return false;
|
|
460
|
+ // Get the next 30 chars from the sequence of gcodes to run
|
|
461
|
+ strncpy_P(cmd, queued_commands_P, sizeof(cmd)-1);
|
|
462
|
+ cmd[sizeof(cmd)-1]= 0;
|
|
463
|
+ // Look for the end of line, or the end of sequence
|
|
464
|
+ size_t i= 0;
|
|
465
|
+ char c;
|
|
466
|
+ while( (c= cmd[i]) && c!='\n' )
|
|
467
|
+ ++i; // look for the end of this gcode command
|
|
468
|
+ cmd[i]= 0;
|
|
469
|
+ if(enquecommand(cmd)) // buffer was not full (else we will retry later)
|
457
|
470
|
{
|
458
|
|
- //this is dangerous if a mixing of serial and this happens
|
459
|
|
- strcpy(&(cmdbuffer[bufindw][0]),cmd);
|
460
|
|
- SERIAL_ECHO_START;
|
461
|
|
- SERIAL_ECHOPGM(MSG_Enqueing);
|
462
|
|
- SERIAL_ECHO(cmdbuffer[bufindw]);
|
463
|
|
- SERIAL_ECHOLNPGM("\"");
|
464
|
|
- bufindw= (bufindw + 1)%BUFSIZE;
|
465
|
|
- buflen += 1;
|
|
471
|
+ if(c)
|
|
472
|
+ queued_commands_P+= i+1; // move to next command
|
|
473
|
+ else
|
|
474
|
+ queued_commands_P= NULL; // will have no more commands in the sequence
|
466
|
475
|
}
|
|
476
|
+ return true;
|
467
|
477
|
}
|
468
|
478
|
|
469
|
|
-void enquecommand_P(const char *cmd)
|
|
479
|
+//Record one or many commands to run from program memory.
|
|
480
|
+//Aborts the current queue, if any.
|
|
481
|
+//Note: drain_queued_commands_P() must be called repeatedly to drain the commands afterwards
|
|
482
|
+void enquecommands_P(const char* pgcode)
|
470
|
483
|
{
|
471
|
|
- if(buflen < BUFSIZE)
|
472
|
|
- {
|
473
|
|
- //this is dangerous if a mixing of serial and this happens
|
474
|
|
- strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
|
475
|
|
- SERIAL_ECHO_START;
|
476
|
|
- SERIAL_ECHOPGM(MSG_Enqueing);
|
477
|
|
- SERIAL_ECHO(cmdbuffer[bufindw]);
|
478
|
|
- SERIAL_ECHOLNPGM("\"");
|
479
|
|
- bufindw= (bufindw + 1)%BUFSIZE;
|
480
|
|
- buflen += 1;
|
481
|
|
- }
|
|
484
|
+ queued_commands_P= pgcode;
|
|
485
|
+ drain_queued_commands_P(); // first command exectuted asap (when possible)
|
482
|
486
|
}
|
483
|
487
|
|
|
488
|
+//adds a single command to the main command buffer, from RAM
|
|
489
|
+//that is really done in a non-safe way.
|
|
490
|
+//needs overworking someday
|
|
491
|
+//Returns false if it failed to do so
|
|
492
|
+bool enquecommand(const char *cmd)
|
|
493
|
+{
|
|
494
|
+ if(*cmd==';')
|
|
495
|
+ return false;
|
|
496
|
+ if(buflen >= BUFSIZE)
|
|
497
|
+ return false;
|
|
498
|
+ //this is dangerous if a mixing of serial and this happens
|
|
499
|
+ strcpy(&(cmdbuffer[bufindw][0]),cmd);
|
|
500
|
+ SERIAL_ECHO_START;
|
|
501
|
+ SERIAL_ECHOPGM(MSG_Enqueing);
|
|
502
|
+ SERIAL_ECHO(cmdbuffer[bufindw]);
|
|
503
|
+ SERIAL_ECHOLNPGM("\"");
|
|
504
|
+ bufindw= (bufindw + 1)%BUFSIZE;
|
|
505
|
+ buflen += 1;
|
|
506
|
+ return true;
|
|
507
|
+}
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
484
|
511
|
void setup_killpin()
|
485
|
512
|
{
|
486
|
513
|
#if defined(KILL_PIN) && KILL_PIN > -1
|
|
@@ -684,6 +711,9 @@ void loop()
|
684
|
711
|
|
685
|
712
|
void get_command()
|
686
|
713
|
{
|
|
714
|
+ if(drain_queued_commands_P()) // priority is given to non-serial commands
|
|
715
|
+ return;
|
|
716
|
+
|
687
|
717
|
while( MYSERIAL.available() > 0 && buflen < BUFSIZE) {
|
688
|
718
|
serial_char = MYSERIAL.read();
|
689
|
719
|
if(serial_char == '\n' ||
|
|
@@ -4459,7 +4489,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
|
4459
|
4489
|
{
|
4460
|
4490
|
if (homeDebounceCount == 0)
|
4461
|
4491
|
{
|
4462
|
|
- enquecommand_P((PSTR("G28")));
|
|
4492
|
+ enquecommands_P((PSTR("G28")));
|
4463
|
4493
|
homeDebounceCount++;
|
4464
|
4494
|
LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
|
4465
|
4495
|
}
|