Browse Source

Merge pull request #1423 from MoonCactus/Development

Multi-line G-code commands
Scott Lahteine 9 years ago
parent
commit
8cfdd3e8a4
4 changed files with 80 additions and 36 deletions
  1. 3
    2
      Marlin/Marlin.h
  2. 56
    26
      Marlin/Marlin_main.cpp
  3. 2
    2
      Marlin/cardreader.cpp
  4. 19
    6
      Marlin/ultralcd.cpp

+ 3
- 2
Marlin/Marlin.h View File

201
 
201
 
202
 bool IsStopped();
202
 bool IsStopped();
203
 
203
 
204
-void enquecommand(const char *cmd); //put an ASCII command at the end of the current buffer.
205
-void enquecommand_P(const char *cmd); //put an ASCII command at the end of the current buffer, read from flash
204
+bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
205
+void enquecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
206
+
206
 void prepare_arc_move(char isclockwise);
207
 void prepare_arc_move(char isclockwise);
207
 void clamp_to_software_endstops(float target[3]);
208
 void clamp_to_software_endstops(float target[3]);
208
 
209
 

+ 56
- 26
Marlin/Marlin_main.cpp View File

385
 static boolean comment_mode = false;
385
 static boolean comment_mode = false;
386
 static char *strchr_pointer; ///< A pointer to find chars in the command string (X, Y, Z, E, etc.)
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
 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
390
 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
389
 
391
 
390
 // Inactivity shutdown
392
 // Inactivity shutdown
448
   }
450
   }
449
 #endif //!SDSUPPORT
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
 void setup_killpin()
511
 void setup_killpin()
485
 {
512
 {
486
   #if defined(KILL_PIN) && KILL_PIN > -1
513
   #if defined(KILL_PIN) && KILL_PIN > -1
684
 
711
 
685
 void get_command()
712
 void get_command()
686
 {
713
 {
714
+  if(drain_queued_commands_P()) // priority is given to non-serial commands
715
+    return;
716
+  
687
   while( MYSERIAL.available() > 0  && buflen < BUFSIZE) {
717
   while( MYSERIAL.available() > 0  && buflen < BUFSIZE) {
688
     serial_char = MYSERIAL.read();
718
     serial_char = MYSERIAL.read();
689
     if(serial_char == '\n' ||
719
     if(serial_char == '\n' ||
4459
     {
4489
     {
4460
        if (homeDebounceCount == 0)
4490
        if (homeDebounceCount == 0)
4461
        {
4491
        {
4462
-          enquecommand_P((PSTR("G28")));
4492
+          enquecommands_P((PSTR("G28")));
4463
           homeDebounceCount++;
4493
           homeDebounceCount++;
4464
           LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
4494
           LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
4465
        }
4495
        }

+ 2
- 2
Marlin/cardreader.cpp View File

532
 
532
 
533
       sprintf_P(cmd, PSTR("M23 %s"), autoname);
533
       sprintf_P(cmd, PSTR("M23 %s"), autoname);
534
       enquecommand(cmd);
534
       enquecommand(cmd);
535
-      enquecommand_P(PSTR("M24"));
535
+      enquecommands_P(PSTR("M24"));
536
       found=true;
536
       found=true;
537
     }
537
     }
538
   }
538
   }
637
       if(SD_FINISHED_STEPPERRELEASE)
637
       if(SD_FINISHED_STEPPERRELEASE)
638
       {
638
       {
639
           //finishAndDisableSteppers();
639
           //finishAndDisableSteppers();
640
-          enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
640
+          enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
641
       }
641
       }
642
       autotempShutdown();
642
       autotempShutdown();
643
     }
643
     }

+ 19
- 6
Marlin/ultralcd.cpp View File

324
     quickStop();
324
     quickStop();
325
     if(SD_FINISHED_STEPPERRELEASE)
325
     if(SD_FINISHED_STEPPERRELEASE)
326
     {
326
     {
327
-        enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
327
+        enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
328
     }
328
     }
329
     autotempShutdown();
329
     autotempShutdown();
330
 
330
 
347
         MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
347
         MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
348
 #endif // DELTA_CALIBRATION_MENU
348
 #endif // DELTA_CALIBRATION_MENU
349
     }
349
     }
350
+/*JFR TEST*/            MENU_ITEM(gcode, "test multiline", PSTR("G4 S3\nM104 S50\nG4 S1\nM104 S200\nG4 S2\nM104 S0"));  // SD-card changed by user
350
     MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
351
     MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
351
 #ifdef SDSUPPORT
352
 #ifdef SDSUPPORT
352
     if (card.cardOK)
353
     if (card.cardOK)
394
     plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
395
     plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
395
 
396
 
396
     // Audio feedback
397
     // Audio feedback
397
-    enquecommand_P(PSTR("M300 S659 P200"));
398
-    enquecommand_P(PSTR("M300 S698 P200"));
398
+    enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
399
     lcd_return_to_status();
399
     lcd_return_to_status();
400
 }
400
 }
401
 
401
 
677
     }
677
     }
678
 #endif
678
 #endif
679
     MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
679
     MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
680
+		
681
+    // JFR for RMud delta printer
682
+    MENU_ITEM(gcode, "Calibrate bed", PSTR("M702\nG28\nG1 X-77.94 Y-45 Z36 F8000\nG4 S3\nM701 P0\nG1 X77.94 Y-45 Z36\nG4 S3\nM701 P1\nG1 X0 Y90 Z36\nG4 S3\nM701 P2\nM700\nG1 X0 Y0 Z100 F8000"));
683
+    MENU_ITEM(gcode, "Check level", PSTR("G28\nG1 X0 Y0 Z1 F4000\nG1 X-77.94 Y-45 Z1\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG4 S2\nG1 X-77.94 Y-45 Z0.3 F2000\nG1 X-77.94 Y-45\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG1 X0 Y0 Z0"));
684
+    MENU_ITEM(gcode, "Retract filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E-800"));
685
+    MENU_ITEM(gcode, "Insert filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E60"));
686
+    MENU_ITEM(gcode, "Finalize filament", PSTR("G1 F4000 E790"));
680
     END_MENU();
687
     END_MENU();
681
 }
688
 }
682
 
689
 
1148
     lcd_move_y();
1155
     lcd_move_y();
1149
 	}
1156
 	}
1150
 	static void reprapworld_keypad_move_home() {
1157
 	static void reprapworld_keypad_move_home() {
1151
-		enquecommand_P((PSTR("G28"))); // move all axis home
1158
+		enquecommands_P((PSTR("G28"))); // move all axis home
1152
 	}
1159
 	}
1153
 #endif
1160
 #endif
1154
 
1161
 
1164
 /** Menu action functions **/
1171
 /** Menu action functions **/
1165
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1172
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1166
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1173
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1167
-static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
1174
+
1175
+static void menu_action_gcode(const char* pgcode)
1176
+{
1177
+    enquecommands_P(pgcode);
1178
+}
1179
+
1180
+
1168
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1181
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1169
 static void menu_action_sdfile(const char* filename, char* longFilename)
1182
 static void menu_action_sdfile(const char* filename, char* longFilename)
1170
 {
1183
 {
1174
     for(c = &cmd[4]; *c; c++)
1187
     for(c = &cmd[4]; *c; c++)
1175
         *c = tolower(*c);
1188
         *c = tolower(*c);
1176
     enquecommand(cmd);
1189
     enquecommand(cmd);
1177
-    enquecommand_P(PSTR("M24"));
1190
+    enquecommands_P(PSTR("M24"));
1178
     lcd_return_to_status();
1191
     lcd_return_to_status();
1179
 }
1192
 }
1180
 static void menu_action_sddirectory(const char* filename, char* longFilename)
1193
 static void menu_action_sddirectory(const char* filename, char* longFilename)

Loading…
Cancel
Save