Browse Source

Commit last SD line before fileHasFinished

Scott Lahteine 4 years ago
parent
commit
29ec868c4b
3 changed files with 20 additions and 24 deletions
  1. 18
    22
      Marlin/src/gcode/queue.cpp
  2. 1
    1
      Marlin/src/sd/cardreader.cpp
  3. 1
    1
      Marlin/src/sd/cardreader.h

+ 18
- 22
Marlin/src/gcode/queue.cpp View File

@@ -526,42 +526,38 @@ void GCodeQueue::get_serial_commands() {
526 526
     while (length < BUFSIZE && !card_eof) {
527 527
       const int16_t n = card.get();
528 528
       card_eof = card.eof();
529
+      if (n < 0) { SERIAL_ERROR_MSG(MSG_SD_ERR_READ); continue; }
529 530
       const char sd_char = (char)n;
530
-      if (card_eof || n < 0 || sd_char == '\n' || sd_char == '\r') {
531
+      if (sd_char == '\n' || sd_char == '\r' || card_eof) {
532
+
533
+        // Reset stream state, terminate the buffer, and commit a non-empty command
534
+        if (!process_line_done(sd_input_state, command_buffer[index_w], sd_count)) {
535
+          _commit_command(false);                     // The file was not terminated with a newline
536
+          #if ENABLED(POWER_LOSS_RECOVERY)
537
+            recovery.cmd_sdpos = card.getIndex();     // Prime for the next _commit_command
538
+          #endif
539
+        }
540
+
531 541
         if (card_eof) {
532 542
 
533
-          card.printingHasFinished();
543
+          card.fileHasFinished();                     // Handle end of file reached
534 544
 
535
-          if (IS_SD_PRINTING())
536
-            sd_count = 0; // If a sub-file was printing, continue from call point
537
-          else {
538
-            SERIAL_ECHOLNPGM(MSG_FILE_PRINTED);
545
+          if (!IS_SD_PRINTING()) {                    // Was it the main job file?
546
+            SERIAL_ECHOLNPGM(MSG_FILE_PRINTED);       // Tell the host the file is printed.
539 547
             #if ENABLED(PRINTER_EVENT_LEDS)
540
-              printerEventLEDs.onPrintCompleted();
548
+              printerEventLEDs.onPrintCompleted();    // Change LED color for Print Completed
541 549
               #if HAS_RESUME_CONTINUE
542
-                enqueue_now_P(PSTR("M0 S"
550
+                enqueue_now_P(PSTR("M0 S"             // Display "Click to Continue..."
543 551
                   #if HAS_LCD_MENU
544
-                    "1800"
552
+                    "1800"                            // ...for 30 minutes with LCD
545 553
                   #else
546
-                    "60"
554
+                    "60"                              // ...for 1 minute with no LCD
547 555
                   #endif
548 556
                 ));
549 557
               #endif
550 558
             #endif
551 559
           }
552 560
         }
553
-        else if (n < 0)
554
-          SERIAL_ERROR_MSG(MSG_SD_ERR_READ);
555
-
556
-        // Terminate the buffer, reset the input state, continue for empty line
557
-        if (process_line_done(sd_input_state, command_buffer[index_w], sd_count))
558
-          continue;
559
-
560
-        _commit_command(false);
561
-
562
-        #if ENABLED(POWER_LOSS_RECOVERY)
563
-          recovery.cmd_sdpos = card.getIndex(); // Prime for the next _commit_command
564
-        #endif
565 561
       }
566 562
       else
567 563
         process_stream_char(sd_char, sd_input_state, command_buffer[index_w], sd_count);

+ 1
- 1
Marlin/src/sd/cardreader.cpp View File

@@ -1063,7 +1063,7 @@ uint16_t CardReader::get_num_Files() {
1063 1063
 //
1064 1064
 // Return from procedure or close out the Print Job
1065 1065
 //
1066
-void CardReader::printingHasFinished() {
1066
+void CardReader::fileHasFinished() {
1067 1067
   planner.synchronize();
1068 1068
   file.close();
1069 1069
   if (file_subcall_ctr > 0) { // Resume calling file after closing procedure

+ 1
- 1
Marlin/src/sd/cardreader.h View File

@@ -106,7 +106,7 @@ public:
106 106
 
107 107
   // Print job
108 108
   static void openAndPrintFile(const char *name);   // (working directory)
109
-  static void printingHasFinished();
109
+  static void fileHasFinished();
110 110
   static void getAbsFilename(char *dst);
111 111
   static void startFileprint();
112 112
   static void printFilename();

Loading…
Cancel
Save