소스 검색

Signal SD completion later (#21840)

Scott Lahteine 3 년 전
부모
커밋
b65cdbed91
No account linked to committer's email address

+ 7
- 11
Marlin/src/MarlinCore.cpp 파일 보기

@@ -331,18 +331,14 @@ void disable_all_steppers() {
331 331
 }
332 332
 
333 333
 /**
334
- * A Print Job exists when the timer is running or SD printing
334
+ * A Print Job exists when the timer is running or SD is printing
335 335
  */
336
-bool printJobOngoing() {
337
-  return print_job_timer.isRunning() || IS_SD_PRINTING();
338
-}
336
+bool printJobOngoing() { return print_job_timer.isRunning() || IS_SD_PRINTING(); }
339 337
 
340 338
 /**
341
- * Printing is active when the print job timer is running
339
+ * Printing is active when a job is underway but not paused
342 340
  */
343
-bool printingIsActive() {
344
-  return !did_pause_print && (print_job_timer.isRunning() || IS_SD_PRINTING());
345
-}
341
+bool printingIsActive() { return !did_pause_print && printJobOngoing(); }
346 342
 
347 343
 /**
348 344
  * Printing is paused according to SD or host indicators
@@ -367,7 +363,7 @@ void startOrResumeJob() {
367 363
 
368 364
   inline void abortSDPrinting() {
369 365
     IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel());
370
-    card.endFilePrint(TERN_(SD_RESORT, true));
366
+    card.abortFilePrintNow(TERN_(SD_RESORT, true));
371 367
 
372 368
     queue.clear();
373 369
     quickstop_stepper();
@@ -748,7 +744,7 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
748 744
 
749 745
   // Handle Power-Loss Recovery
750 746
   #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
751
-    if (printJobOngoing()) recovery.outage();
747
+    if (IS_SD_PRINTING()) recovery.outage();
752 748
   #endif
753 749
 
754 750
   // Run StallGuard endstop checks
@@ -901,7 +897,7 @@ void stop() {
901 897
     thermalManager.set_fans_paused(false); // Un-pause fans for safety
902 898
   #endif
903 899
 
904
-  if (IsRunning()) {
900
+  if (!IsStopped()) {
905 901
     SERIAL_ERROR_MSG(STR_ERR_STOPPED);
906 902
     LCD_MESSAGEPGM(MSG_STOPPED);
907 903
     safe_delay(350);       // allow enough time for messages to get out before stopping

+ 1
- 0
Marlin/src/MarlinCore.h 파일 보기

@@ -70,6 +70,7 @@ inline bool IsRunning() { return marlin_state >= MF_RUNNING; }
70 70
 inline bool IsStopped() { return marlin_state == MF_STOPPED; }
71 71
 
72 72
 bool printingIsActive();
73
+bool printJobOngoing();
73 74
 bool printingIsPaused();
74 75
 void startOrResumeJob();
75 76
 

+ 1
- 1
Marlin/src/feature/pause.cpp 파일 보기

@@ -649,7 +649,7 @@ void resume_print(const_float_t slow_load_length/*=0*/, const_float_t fast_load_
649 649
   #if ENABLED(SDSUPPORT)
650 650
     if (did_pause_print) {
651 651
       --did_pause_print;
652
-      card.startFileprint();
652
+      card.startOrResumeFilePrinting();
653 653
       // Write PLR now to update the z axis value
654 654
       TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true));
655 655
     }

+ 1
- 1
Marlin/src/feature/powerloss.cpp 파일 보기

@@ -137,7 +137,7 @@ void PrintJobRecovery::load() {
137 137
  * Set info fields that won't change
138 138
  */
139 139
 void PrintJobRecovery::prepare() {
140
-  card.getAbsFilename(info.sd_filename);  // SD filename
140
+  card.getAbsFilenameInCWD(info.sd_filename);  // SD filename
141 141
   cmd_sdpos = 0;
142 142
 }
143 143
 

+ 2
- 1
Marlin/src/gcode/queue.cpp 파일 보기

@@ -550,7 +550,8 @@ void GCodeQueue::get_serial_commands() {
550 550
   inline void GCodeQueue::get_sdcard_commands() {
551 551
     static uint8_t sd_input_state = PS_NORMAL;
552 552
 
553
-    if (!IS_SD_PRINTING()) return;
553
+    // Get commands if there are more in the file
554
+    if (!IS_SD_FETCHING()) return;
554 555
 
555 556
     int sd_count = 0;
556 557
     while (!ring_buffer.full() && !card.eof()) {

+ 6
- 0
Marlin/src/gcode/sd/M1001.cpp 파일 보기

@@ -25,6 +25,7 @@
25 25
 #if ENABLED(SDSUPPORT)
26 26
 
27 27
 #include "../gcode.h"
28
+#include "../../module/planner.h"
28 29
 #include "../../module/printcounter.h"
29 30
 
30 31
 #if DISABLED(NO_SD_AUTOSTART)
@@ -64,6 +65,11 @@
64 65
  * M1001: Execute actions for SD print completion
65 66
  */
66 67
 void GcodeSuite::M1001() {
68
+  planner.synchronize();
69
+
70
+  // SD Printing is finished when the queue reaches M1001
71
+  card.flag.sdprinting = card.flag.sdprintdone = false;
72
+
67 73
   // If there's another auto#.g file to run...
68 74
   if (TERN(NO_SD_AUTOSTART, false, card.autofile_check())) return;
69 75
 

+ 1
- 1
Marlin/src/gcode/sd/M24_M25.cpp 파일 보기

@@ -70,7 +70,7 @@ void GcodeSuite::M24() {
70 70
   #endif
71 71
 
72 72
   if (card.isFileOpen()) {
73
-    card.startFileprint();            // SD card will now be read for commands
73
+    card.startOrResumeFilePrinting();            // SD card will now be read for commands
74 74
     startOrResumeJob();               // Start (or resume) the print job timer
75 75
     TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
76 76
   }

+ 1
- 1
Marlin/src/gcode/sd/M27.cpp 파일 보기

@@ -35,7 +35,7 @@
35 35
 void GcodeSuite::M27() {
36 36
   if (parser.seen('C')) {
37 37
     SERIAL_ECHOPGM("Current file: ");
38
-    card.printFilename();
38
+    card.printSelectedFilename();
39 39
     return;
40 40
   }
41 41
 

+ 1
- 1
Marlin/src/gcode/sd/M32.cpp 파일 보기

@@ -49,7 +49,7 @@ void GcodeSuite::M32() {
49 49
 
50 50
     if (parser.seenval('S')) card.setIndex(parser.value_long());
51 51
 
52
-    card.startFileprint();
52
+    card.startOrResumeFilePrinting();
53 53
 
54 54
     // Procedure calls count as normal print time.
55 55
     if (!call_procedure) startOrResumeJob();

+ 1
- 1
Marlin/src/gcode/sd/M524.cpp 파일 보기

@@ -33,7 +33,7 @@
33 33
 void GcodeSuite::M524() {
34 34
 
35 35
   if (IS_SD_PRINTING())
36
-    card.flag.abort_sd_printing = true;
36
+    card.abortFilePrintSoon();
37 37
   else if (card.isMounted())
38 38
     card.closefile();
39 39
 

+ 2
- 2
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp 파일 보기

@@ -755,7 +755,7 @@ inline uint8_t draw_elapsed_or_remaining_time(uint8_t timepos, const bool blink)
755 755
   char buffer[14];
756 756
 
757 757
   #if ENABLED(SHOW_REMAINING_TIME)
758
-    const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && (printingIsActive() || marlin_state == MF_SD_COMPLETE);
758
+    const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && printingIsActive();
759 759
     if (show_remain) {
760 760
       #if ENABLED(USE_M73_REMAINING_TIME)
761 761
         duration_t remaining = ui.get_remaining_time();
@@ -889,7 +889,7 @@ void MarlinUI::draw_status_screen() {
889 889
 
890 890
           #else // !HAS_DUAL_MIXING
891 891
 
892
-            const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);
892
+            const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());
893 893
 
894 894
             if (show_e_total) {
895 895
               #if ENABLED(LCD_SHOW_E_TOTAL)

+ 2
- 2
Marlin/src/lcd/dogm/status_screen_DOGM.cpp 파일 보기

@@ -41,7 +41,7 @@
41 41
 #include "../../gcode/parser.h" // for units (and volumetric)
42 42
 
43 43
 #if ENABLED(LCD_SHOW_E_TOTAL)
44
-  #include "../../MarlinCore.h" // for printingIsActive(), marlin_state and MF_SD_COMPLETE
44
+  #include "../../MarlinCore.h" // for printingIsActive()
45 45
 #endif
46 46
 
47 47
 #if ENABLED(FILAMENT_LCD_DISPLAY)
@@ -464,7 +464,7 @@ void MarlinUI::draw_status_screen() {
464 464
     #endif
465 465
   #endif
466 466
 
467
-  const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);
467
+  const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());
468 468
 
469 469
   // At the first page, generate new display values
470 470
   if (first_page) {

+ 2
- 2
Marlin/src/lcd/dwin/e3v2/dwin.cpp 파일 보기

@@ -1891,7 +1891,7 @@ void HMI_SDCardUpdate() {
1891 1891
       else if (checkkey == PrintProcess || checkkey == Tune || printingIsActive()) {
1892 1892
         // TODO: Move card removed abort handling
1893 1893
         //       to CardReader::manage_media.
1894
-        card.flag.abort_sd_printing = true;
1894
+        card.abortFilePrintSoon();
1895 1895
         wait_for_heatup = wait_for_user = false;
1896 1896
         dwin_abort_flag = true; // Reset feedrate, return to Home
1897 1897
       }
@@ -2311,7 +2311,7 @@ void HMI_PauseOrStop() {
2311 2311
         checkkey = Back_Main;
2312 2312
         if (HMI_flag.home_flag) planner.synchronize(); // Wait for planner moves to finish!
2313 2313
         wait_for_heatup = wait_for_user = false;       // Stop waiting for heating/user
2314
-        card.flag.abort_sd_printing = true;            // Let the main loop handle SD abort
2314
+        card.abortFilePrintSoon();                     // Let the main loop handle SD abort
2315 2315
         dwin_abort_flag = true;                        // Reset feedrate, return to Home
2316 2316
         #ifdef ACTION_ON_CANCEL
2317 2317
           host_action_cancel();

+ 3
- 4
Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp 파일 보기

@@ -289,7 +289,7 @@ void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) {
289 289
   // if robin nano is printing. when it is, dgus will enter the printing
290 290
   // page to continue print;
291 291
   //
292
-  //if (print_job_timer.isRunning() || print_job_timer.isPaused()) {
292
+  //if (printJobOngoing() || printingIsPaused()) {
293 293
   //  if (target == MKSLCD_PAUSE_SETTING_MOVE || target == MKSLCD_PAUSE_SETTING_EX
294 294
   //    || target == MKSLCD_SCREEN_PRINT || target == MKSLCD_SCREEN_PAUSE
295 295
   //  ) {
@@ -324,7 +324,7 @@ void DGUSScreenHandler::ScreenBackChange(DGUS_VP_Variable &var, void *val_ptr) {
324 324
 
325 325
 void DGUSScreenHandler::ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr) {
326 326
   settings.save();
327
-  if (print_job_timer.isRunning())
327
+  if (printJobOngoing())
328 328
     GotoScreen(MKSLCD_SCREEN_PRINT);
329 329
   else if (print_job_timer.isPaused)
330 330
     GotoScreen(MKSLCD_SCREEN_PAUSE);
@@ -1442,8 +1442,7 @@ bool DGUSScreenHandler::loop() {
1442 1442
     }
1443 1443
 
1444 1444
     #if ENABLED(DGUS_MKS_RUNOUT_SENSOR)
1445
-      if (booted && (IS_SD_PRINTING() || IS_SD_PAUSED()))
1446
-        DGUS_Runout_Idle();
1445
+      if (booted && printingIsActive()) DGUS_Runout_Idle();
1447 1446
     #endif
1448 1447
   #endif // SHOW_BOOTSCREEN
1449 1448
 

+ 5
- 5
Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp 파일 보기

@@ -91,8 +91,8 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
91 91
         cur_name = strrchr(list_file.file_name[sel_id], '/');
92 92
 
93 93
         SdFile file, *curDir;
94
-        card.endFilePrint();
95
-        const char * const fname = card.diveToFile(true, curDir, cur_name);
94
+        card.abortFilePrintNow();
95
+        const char * const fname = card.diveToFile(false, curDir, cur_name);
96 96
         if (!fname) return;
97 97
         if (file.open(curDir, fname, O_READ)) {
98 98
           gCfgItems.curFilesize = file.fileSize();
@@ -108,7 +108,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
108 108
             planner.flow_percentage[1] = 100;
109 109
             planner.e_factor[1]        = planner.flow_percentage[1] * 0.01f;
110 110
           #endif
111
-          card.startFileprint();
111
+          card.startOrResumeFilePrinting();
112 112
           #if ENABLED(POWER_LOSS_RECOVERY)
113 113
             recovery.prepare();
114 114
           #endif
@@ -124,8 +124,8 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
124 124
     lv_draw_ready_print();
125 125
 
126 126
     #if ENABLED(SDSUPPORT)
127
-      uiCfg.print_state           = IDLE;
128
-      card.flag.abort_sd_printing = true;
127
+      uiCfg.print_state = IDLE;
128
+      card.abortFilePrintSoon();
129 129
     #endif
130 130
   }
131 131
   else if (DIALOG_IS(TYPE_FINISH_PRINT)) {

+ 3
- 5
Marlin/src/lcd/extui/mks_ui/draw_ui.cpp 파일 보기

@@ -638,19 +638,18 @@ char *creat_title_text() {
638 638
         W25QXX.SPI_FLASH_BufferWrite(bmp_public_buf, BAK_VIEW_ADDR_TFT35 + row * 400, 400);
639 639
       #endif
640 640
       row++;
641
+      card.abortFilePrintNow();
641 642
       if (row >= 200) {
642 643
         size = 809;
643 644
         row  = 0;
644 645
 
645 646
         gcode_preview_over = false;
646 647
 
647
-        card.closefile();
648 648
         char *cur_name = strrchr(list_file.file_name[sel_id], '/');
649 649
 
650 650
         SdFile file;
651 651
         SdFile *curDir;
652
-        card.endFilePrint();
653
-        const char * const fname = card.diveToFile(true, curDir, cur_name);
652
+        const char * const fname = card.diveToFile(false, curDir, cur_name);
654 653
         if (!fname) return;
655 654
         if (file.open(curDir, fname, O_READ)) {
656 655
           gCfgItems.curFilesize = file.fileSize();
@@ -667,13 +666,12 @@ char *creat_title_text() {
667 666
             planner.flow_percentage[1] = 100;
668 667
             planner.e_factor[1]        = planner.flow_percentage[1] * 0.01;
669 668
           #endif
670
-          card.startFileprint();
669
+          card.startOrResumeFilePrinting();
671 670
           TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
672 671
           once_flag = false;
673 672
         }
674 673
         return;
675 674
       }
676
-      card.closefile();
677 675
     #endif // SDSUPPORT
678 676
   }
679 677
 

+ 9
- 11
Marlin/src/lcd/extui/mks_ui/wifi_module.cpp 파일 보기

@@ -505,7 +505,7 @@ int write_to_file(char *buf, int len) {
505 505
 
506 506
       if (res == -1) {
507 507
         upload_file.close();
508
-        const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
508
+        const char * const fname = card.diveToFile(false, upload_curDir, saveFilePath);
509 509
 
510 510
         if (upload_file.open(upload_curDir, fname, O_WRITE)) {
511 511
           upload_file.setpos(&pos);
@@ -732,12 +732,10 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
732 732
                 if (!gcode_preview_over) {
733 733
                   char *cur_name = strrchr(list_file.file_name[sel_id], '/');
734 734
 
735
-                  card.endFilePrint();
736
-
737 735
                   SdFile file;
738 736
                   SdFile *curDir;
739
-                  card.endFilePrint();
740
-                  const char * const fname = card.diveToFile(true, curDir, cur_name);
737
+                  card.abortFilePrintNow();
738
+                  const char * const fname = card.diveToFile(false, curDir, cur_name);
741 739
                   if (!fname) return;
742 740
                   if (file.open(curDir, fname, O_READ)) {
743 741
                     gCfgItems.curFilesize = file.fileSize();
@@ -754,7 +752,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
754 752
                       planner.flow_percentage[1] = 100;
755 753
                       planner.e_factor[1] = planner.flow_percentage[1] * 0.01f;
756 754
                     #endif
757
-                    card.startFileprint();
755
+                    card.startOrResumeFilePrinting();
758 756
                     TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
759 757
                     once_flag = false;
760 758
                   }
@@ -814,7 +812,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
814 812
             clear_cur_ui();
815 813
             #if ENABLED(SDSUPPORT)
816 814
               uiCfg.print_state = IDLE;
817
-              card.flag.abort_sd_printing = true;
815
+              card.abortFilePrintSoon();
818 816
             #endif
819 817
 
820 818
             lv_draw_ready_print();
@@ -1317,7 +1315,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
1317 1315
 
1318 1316
     card.cdroot();
1319 1317
     upload_file.close();
1320
-    const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
1318
+    const char * const fname = card.diveToFile(false, upload_curDir, saveFilePath);
1321 1319
 
1322 1320
     if (!upload_file.open(upload_curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
1323 1321
       clear_cur_ui();
@@ -1370,7 +1368,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
1370 1368
       int res = upload_file.write(public_buf, file_writer.write_index);
1371 1369
       if (res == -1) {
1372 1370
         upload_file.close();
1373
-        const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
1371
+        const char * const fname = card.diveToFile(false, upload_curDir, saveFilePath);
1374 1372
         if (upload_file.open(upload_curDir, fname, O_WRITE)) {
1375 1373
           upload_file.setpos(&pos);
1376 1374
           res = upload_file.write(public_buf, file_writer.write_index);
@@ -1378,7 +1376,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
1378 1376
       }
1379 1377
       upload_file.close();
1380 1378
       SdFile file, *curDir;
1381
-      const char * const fname = card.diveToFile(true, curDir, saveFilePath);
1379
+      const char * const fname = card.diveToFile(false, curDir, saveFilePath);
1382 1380
       if (file.open(curDir, fname, O_RDWR)) {
1383 1381
         gCfgItems.curFilesize = file.fileSize();
1384 1382
         file.close();
@@ -1744,7 +1742,7 @@ void mks_wifi_firmware_update() {
1744 1742
     if (wifi_upload(0) >= 0) {
1745 1743
       card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
1746 1744
       SdFile file, *curDir;
1747
-      const char * const fname = card.diveToFile(true, curDir, ESP_FIRMWARE_FILE);
1745
+      const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE);
1748 1746
       if (file.open(curDir, fname, O_READ)) {
1749 1747
         file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME);
1750 1748
         file.close();

+ 1
- 1
Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp 파일 보기

@@ -625,7 +625,7 @@ void upload_spin() {
625 625
 
626 626
 // Try to upload the given file at the given address
627 627
 void SendUpdateFile(const char *file, uint32_t address) {
628
-  const char * const fname = card.diveToFile(true, update_curDir, ESP_FIRMWARE_FILE);
628
+  const char * const fname = card.diveToFile(false, update_curDir, ESP_FIRMWARE_FILE);
629 629
   if (!update_file.open(update_curDir, fname, O_READ)) return;
630 630
 
631 631
   esp_upload.fileSize = update_file.fileSize();

+ 5
- 17
Marlin/src/lcd/extui/ui_api.cpp 파일 보기

@@ -54,6 +54,7 @@
54 54
 #include "../../module/printcounter.h"
55 55
 #include "../../libs/duration_t.h"
56 56
 #include "../../HAL/shared/Delay.h"
57
+#include "../../MarlinCore.h"
57 58
 #include "../../sd/cardreader.h"
58 59
 
59 60
 #if ENABLED(PRINTCOUNTER)
@@ -106,9 +107,6 @@ namespace ExtUI {
106 107
     #if ENABLED(JOYSTICK)
107 108
       uint8_t jogging : 1;
108 109
     #endif
109
-    #if ENABLED(SDSUPPORT)
110
-      uint8_t was_sd_printing : 1;
111
-    #endif
112 110
   } flags;
113 111
 
114 112
   #ifdef __SAM3X8E__
@@ -1017,27 +1015,17 @@ namespace ExtUI {
1017 1015
   void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }
1018 1016
 
1019 1017
   void printFile(const char *filename) {
1020
-    UNUSED(filename);
1021
-    TERN_(SDSUPPORT, card.openAndPrintFile(filename));
1018
+    TERN(SDSUPPORT, card.openAndPrintFile(filename), UNUSED(filename));
1022 1019
   }
1023 1020
 
1024 1021
   bool isPrintingFromMediaPaused() {
1025
-    return TERN0(SDSUPPORT, isPrintingFromMedia() && !IS_SD_PRINTING());
1022
+    return TERN0(SDSUPPORT, isPrintingFromMedia() && printingIsPaused());
1026 1023
   }
1027 1024
 
1028
-  bool isPrintingFromMedia() {
1029
-    #if ENABLED(SDSUPPORT)
1030
-      // Account for when IS_SD_PRINTING() reports the end of the
1031
-      // print when there is still SD card data in the planner.
1032
-      flags.was_sd_printing = card.isFileOpen() || (flags.was_sd_printing && commandsInQueue());
1033
-      return flags.was_sd_printing;
1034
-    #else
1035
-      return false;
1036
-    #endif
1037
-  }
1025
+  bool isPrintingFromMedia() { return IS_SD_PRINTING(); }
1038 1026
 
1039 1027
   bool isPrinting() {
1040
-    return (commandsInQueue() || isPrintingFromMedia() || TERN0(SDSUPPORT, IS_SD_PRINTING())) || print_job_timer.isRunning() || print_job_timer.isPaused();
1028
+    return commandsInQueue() || isPrintingFromMedia() || printJobOngoing() || printingIsPaused();
1041 1029
   }
1042 1030
 
1043 1031
   bool isPrintingPaused() {

+ 1
- 1
Marlin/src/lcd/marlinui.cpp 파일 보기

@@ -1487,7 +1487,7 @@ void MarlinUI::update() {
1487 1487
   void MarlinUI::abort_print() {
1488 1488
     #if ENABLED(SDSUPPORT)
1489 1489
       wait_for_heatup = wait_for_user = false;
1490
-      card.flag.abort_sd_printing = true;
1490
+      card.abortFilePrintSoon();
1491 1491
     #endif
1492 1492
     #ifdef ACTION_ON_CANCEL
1493 1493
       host_action_cancel();

+ 1
- 1
Marlin/src/module/endstops.cpp 파일 보기

@@ -395,7 +395,7 @@ void Endstops::event_handler() {
395 395
 
396 396
     #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
397 397
       if (planner.abort_on_endstop_hit) {
398
-        card.endFilePrint();
398
+        card.abortFilePrintNow();
399 399
         quickstop_stepper();
400 400
         thermalManager.disable_all_heaters();
401 401
         print_job_timer.stop();

+ 38
- 26
Marlin/src/sd/cardreader.cpp 파일 보기

@@ -161,7 +161,7 @@ CardReader::CardReader() {
161 161
     #endif
162 162
   #endif
163 163
 
164
-  flag.sdprinting = flag.mounted = flag.saving = flag.logging = false;
164
+  flag.sdprinting = flag.sdprintdone = flag.mounted = flag.saving = flag.logging = false;
165 165
   filesize = sdpos = 0;
166 166
 
167 167
   TERN_(HAS_MEDIA_SUBCALLS, file_subcall_ctr = 0);
@@ -379,7 +379,7 @@ void CardReader::ls() {
379 379
 //
380 380
 // Echo the DOS 8.3 filename (and long filename, if any)
381 381
 //
382
-void CardReader::printFilename() {
382
+void CardReader::printSelectedFilename() {
383 383
   if (file.isOpen()) {
384 384
     char dosFilename[FILENAME_LENGTH];
385 385
     file.getDosName(dosFilename);
@@ -487,9 +487,9 @@ void CardReader::manage_media() {
487 487
 void CardReader::release() {
488 488
   // Card removed while printing? Abort!
489 489
   if (IS_SD_PRINTING())
490
-    card.flag.abort_sd_printing = true;
490
+    abortFilePrintSoon();
491 491
   else
492
-    endFilePrint();
492
+    endFilePrintNow();
493 493
 
494 494
   flag.mounted = false;
495 495
   flag.workDirIsRoot = true;
@@ -516,9 +516,10 @@ void CardReader::openAndPrintFile(const char *name) {
516 516
  * since you cannot browse files during active printing.
517 517
  * Used by M24 and anywhere Start / Resume applies.
518 518
  */
519
-void CardReader::startFileprint() {
519
+void CardReader::startOrResumeFilePrinting() {
520 520
   if (isMounted()) {
521 521
     flag.sdprinting = true;
522
+    flag.sdprintdone = false;
522 523
     TERN_(SD_RESORT, flush_presort());
523 524
   }
524 525
 }
@@ -526,14 +527,19 @@ void CardReader::startFileprint() {
526 527
 //
527 528
 // Run tasks upon finishing or aborting a file print.
528 529
 //
529
-void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
530
+void CardReader::endFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
530 531
   TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
531 532
   TERN_(DWIN_CREALITY_LCD, HMI_flag.print_finish = flag.sdprinting);
532
-  flag.sdprinting = flag.abort_sd_printing = false;
533
+  flag.abort_sd_printing = false;
533 534
   if (isFileOpen()) file.close();
534 535
   TERN_(SD_RESORT, if (re_sort) presort());
535 536
 }
536 537
 
538
+void CardReader::abortFilePrintNow(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
539
+  flag.sdprinting = flag.sdprintdone = false;
540
+  endFilePrintNow(TERN_(SD_RESORT, re_sort));
541
+}
542
+
537 543
 void CardReader::openLogFile(const char * const path) {
538 544
   flag.logging = DISABLED(SDCARD_READONLY);
539 545
   IF_DISABLED(SDCARD_READONLY, openFileWrite(path));
@@ -542,7 +548,7 @@ void CardReader::openLogFile(const char * const path) {
542 548
 //
543 549
 // Get the root-relative DOS path of the selected file
544 550
 //
545
-void CardReader::getAbsFilename(char *dst) {
551
+void CardReader::getAbsFilenameInCWD(char *dst) {
546 552
   *dst++ = '/';
547 553
   uint8_t cnt = 1;
548 554
 
@@ -608,7 +614,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
608 614
         }
609 615
 
610 616
         // Store current filename (based on workDirParents) and position
611
-        getAbsFilename(proc_filenames[file_subcall_ctr]);
617
+        getAbsFilenameInCWD(proc_filenames[file_subcall_ctr]);
612 618
         filespos[file_subcall_ctr] = sdpos;
613 619
 
614 620
         // For sub-procedures say 'SUBROUTINE CALL target: "..." parent: "..." pos12345'
@@ -623,7 +629,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
623 629
     #endif
624 630
   }
625 631
 
626
-  endFilePrint();
632
+  abortFilePrintNow();
627 633
 
628 634
   SdFile *diveDir;
629 635
   const char * const fname = diveToFile(true, diveDir, path);
@@ -659,7 +665,7 @@ void CardReader::openFileWrite(const char * const path) {
659 665
   announceOpen(2, path);
660 666
   TERN_(HAS_MEDIA_SUBCALLS, file_subcall_ctr = 0);
661 667
 
662
-  endFilePrint();
668
+  abortFilePrintNow();
663 669
 
664 670
   SdFile *diveDir;
665 671
   const char * const fname = diveToFile(false, diveDir, path);
@@ -712,7 +718,7 @@ bool CardReader::fileExists(const char * const path) {
712 718
 void CardReader::removeFile(const char * const name) {
713 719
   if (!isMounted()) return;
714 720
 
715
-  //endFilePrint();
721
+  //abortFilePrintNow();
716 722
 
717 723
   SdFile *curDir;
718 724
   const char * const fname = diveToFile(false, curDir, name);
@@ -856,6 +862,9 @@ uint16_t CardReader::countFilesInWorkDir() {
856 862
 /**
857 863
  * Dive to the given DOS 8.3 file path, with optional echo of the dive paths.
858 864
  *
865
+ * On entry:
866
+ *  - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...)
867
+ *
859 868
  * On exit:
860 869
  *  - Your curDir pointer contains an SdFile reference to the file's directory.
861 870
  *  - If update_cwd was 'true' the workDir now points to the file's directory.
@@ -865,6 +874,8 @@ uint16_t CardReader::countFilesInWorkDir() {
865 874
  * A nullptr result indicates an unrecoverable error.
866 875
  */
867 876
 const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, const char * const path, const bool echo/*=false*/) {
877
+  DEBUG_SECTION(est, "diveToFile", true);
878
+
868 879
   // Track both parent and subfolder
869 880
   static SdFile newDir1, newDir2;
870 881
   SdFile *sub = &newDir1, *startDir;
@@ -872,12 +883,12 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, cons
872 883
   // Parsing the path string
873 884
   const char *item_name_adr = path;
874 885
 
875
-  DEBUG_ECHOLNPAIR("diveToFile: path = '", path, "'");
886
+  DEBUG_ECHOLNPAIR(" path = '", path, "'");
876 887
 
877 888
   if (path[0] == '/') {               // Starting at the root directory?
878 889
     diveDir = &root;
879 890
     item_name_adr++;
880
-    DEBUG_ECHOLNPAIR("diveToFile: CWD to root: ", hex_address((void*)diveDir));
891
+    DEBUG_ECHOLNPAIR(" CWD to root: ", hex_address((void*)diveDir));
881 892
     if (update_cwd) workDirDepth = 0; // The cwd can be updated for the benefit of sub-programs
882 893
   }
883 894
   else
@@ -885,7 +896,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, cons
885 896
 
886 897
   startDir = diveDir;
887 898
 
888
-  DEBUG_ECHOLNPAIR("diveToFile: startDir = ", hex_address((void*)startDir));
899
+  DEBUG_ECHOLNPAIR(" startDir = ", hex_address((void*)startDir));
889 900
 
890 901
   while (item_name_adr) {
891 902
     // Find next subdirectory delimiter
@@ -902,7 +913,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, cons
902 913
 
903 914
     if (echo) SERIAL_ECHOLN(dosSubdirname);
904 915
 
905
-    DEBUG_ECHOLNPAIR("diveToFile: sub = ", hex_address((void*)sub));
916
+    DEBUG_ECHOLNPAIR(" sub = ", hex_address((void*)sub));
906 917
 
907 918
     // Open diveDir (closing first)
908 919
     sub->close();
@@ -914,24 +925,24 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, cons
914 925
 
915 926
     // Close diveDir if not at starting-point
916 927
     if (diveDir != startDir) {
917
-      DEBUG_ECHOLNPAIR("diveToFile: closing diveDir: ", hex_address((void*)diveDir));
928
+      DEBUG_ECHOLNPAIR(" closing diveDir: ", hex_address((void*)diveDir));
918 929
       diveDir->close();
919 930
     }
920 931
 
921 932
     // diveDir now subDir
922 933
     diveDir = sub;
923
-    DEBUG_ECHOLNPAIR("diveToFile: diveDir = sub: ", hex_address((void*)diveDir));
934
+    DEBUG_ECHOLNPAIR(" diveDir = sub: ", hex_address((void*)diveDir));
924 935
 
925 936
     // Update workDirParents and workDirDepth
926 937
     if (update_cwd) {
927
-      DEBUG_ECHOLNPAIR("diveToFile: update_cwd");
938
+      DEBUG_ECHOLNPAIR(" update_cwd");
928 939
       if (workDirDepth < MAX_DIR_DEPTH)
929 940
         workDirParents[workDirDepth++] = *diveDir;
930 941
     }
931 942
 
932 943
     // Point sub at the other scratch object
933 944
     sub = (diveDir != &newDir1) ? &newDir1 : &newDir2;
934
-    DEBUG_ECHOLNPAIR("diveToFile: swapping sub = ", hex_address((void*)sub));
945
+    DEBUG_ECHOLNPAIR(" swapping sub = ", hex_address((void*)sub));
935 946
 
936 947
     // Next path atom address
937 948
     item_name_adr = name_end + 1;
@@ -939,11 +950,12 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &diveDir, cons
939 950
 
940 951
   if (update_cwd) {
941 952
     workDir = *diveDir;
942
-    DEBUG_ECHOLNPAIR("diveToFile: final workDir = ", hex_address((void*)diveDir));
953
+    DEBUG_ECHOLNPAIR(" final workDir = ", hex_address((void*)diveDir));
943 954
     flag.workDirIsRoot = (workDirDepth == 0);
944 955
     TERN_(SDCARD_SORT_ALPHA, presort());
945 956
   }
946 957
 
958
+  DEBUG_ECHOLNPAIR(" returning string ", item_name_adr ?: "nullptr");
947 959
   return item_name_adr;
948 960
 }
949 961
 
@@ -1225,21 +1237,21 @@ uint16_t CardReader::get_num_Files() {
1225 1237
 // Return from procedure or close out the Print Job
1226 1238
 //
1227 1239
 void CardReader::fileHasFinished() {
1228
-  planner.synchronize();
1229 1240
   file.close();
1230
-
1231 1241
   #if HAS_MEDIA_SUBCALLS
1232 1242
     if (file_subcall_ctr > 0) { // Resume calling file after closing procedure
1233 1243
       file_subcall_ctr--;
1234 1244
       openFileRead(proc_filenames[file_subcall_ctr], 2); // 2 = Returning from sub-procedure
1235 1245
       setIndex(filespos[file_subcall_ctr]);
1236
-      startFileprint();
1246
+      startOrResumeFilePrinting();
1237 1247
       return;
1238 1248
     }
1239 1249
   #endif
1240 1250
 
1241
-  endFilePrint(TERN_(SD_RESORT, true));
1242
-  marlin_state = MF_SD_COMPLETE;
1251
+  endFilePrintNow(TERN_(SD_RESORT, true));
1252
+
1253
+  flag.sdprintdone = true;        // Stop getting bytes from the SD card
1254
+  marlin_state = MF_SD_COMPLETE;  // Tell Marlin to enqueue M1001 soon
1243 1255
 }
1244 1256
 
1245 1257
 #if ENABLED(AUTO_REPORT_SD_STATUS)

+ 39
- 21
Marlin/src/sd/cardreader.h 파일 보기

@@ -70,6 +70,7 @@ typedef struct {
70 70
   bool saving:1,
71 71
        logging:1,
72 72
        sdprinting:1,
73
+       sdprintdone:1,
73 74
        mounted:1,
74 75
        filenameIsDir:1,
75 76
        workDirIsRoot:1,
@@ -147,23 +148,33 @@ public:
147 148
 
148 149
   // Select a file
149 150
   static void selectFileByIndex(const uint16_t nr);
150
-  static void selectFileByName(const char * const match);
151
+  static void selectFileByName(const char * const match);  // (working directory only)
151 152
 
152 153
   // Print job
153
-  static void openAndPrintFile(const char *name);   // (working directory)
154
-  static void fileHasFinished();
155
-  static void getAbsFilename(char *dst);
156
-  static void printFilename();
157
-  static void startFileprint();
158
-  static void endFilePrint(TERN_(SD_RESORT, const bool re_sort=false));
159 154
   static void report_status();
160
-  static inline void pauseSDPrint() { flag.sdprinting = false; }
161
-  static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; }
162
-  static inline bool isPrinting() { return flag.sdprinting; }
155
+  static void getAbsFilenameInCWD(char *dst);
156
+  static void printSelectedFilename();
157
+  static void openAndPrintFile(const char *name);   // (working directory or full path)
158
+  static void startOrResumeFilePrinting();
159
+  static void endFilePrintNow(TERN_(SD_RESORT, const bool re_sort=false));
160
+  static void abortFilePrintNow(TERN_(SD_RESORT, const bool re_sort=false));
161
+  static void fileHasFinished();
162
+  static inline void abortFilePrintSoon() { flag.abort_sd_printing = true; }
163
+  static inline void pauseSDPrint()       { flag.sdprinting = false; }
164
+  static inline bool isPrinting()         { return flag.sdprinting; }
165
+  static inline bool isPaused()           { return isFileOpen() && !isPrinting(); }
163 166
   #if HAS_PRINT_PROGRESS_PERMYRIAD
164
-    static inline uint16_t permyriadDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 9999) / 10000) : 0; }
167
+    static inline uint16_t permyriadDone() {
168
+      if (flag.sdprintdone) return 10000;
169
+      if (isFileOpen() && filesize) return sdpos / ((filesize + 9999) / 10000);
170
+      return 0;
171
+    }
165 172
   #endif
166
-  static inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
173
+  static inline uint8_t percentDone() {
174
+    if (flag.sdprintdone) return 100;
175
+    if (isFileOpen() && filesize) return sdpos / ((filesize + 99) / 100);
176
+    return 0;
177
+  }
167 178
 
168 179
   // Helper for open and remove
169 180
   static const char* diveToFile(const bool update_cwd, SdFile* &curDir, const char * const path, const bool echo=false);
@@ -186,15 +197,20 @@ public:
186 197
     static void removeJobRecoveryFile();
187 198
   #endif
188 199
 
189
-  static inline bool isFileOpen() { return isMounted() && file.isOpen(); }
190
-  static inline uint32_t getIndex() { return sdpos; }
191
-  static inline uint32_t getFileSize() { return filesize; }
192
-  static inline bool eof() { return sdpos >= filesize; }
193
-  static inline void setIndex(const uint32_t index) { file.seekSet((sdpos = index)); }
194
-  static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; }
195
-  static inline int16_t get() { int16_t out = (int16_t)file.read(); sdpos = file.curPosition(); return out; }
196
-  static inline int16_t read(void *buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; }
200
+  // Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...)
201
+  static inline char* getWorkDirName()  { workDir.getDosName(filename); return filename; }
202
+
203
+  // Print File stats
204
+  static inline uint32_t getFileSize()  { return filesize; }
205
+  static inline uint32_t getIndex()     { return sdpos; }
206
+  static inline bool isFileOpen()       { return isMounted() && file.isOpen(); }
207
+  static inline bool eof()              { return getIndex() >= getFileSize(); }
208
+
209
+  // File data operations
210
+  static inline int16_t get()                            { int16_t out = (int16_t)file.read(); sdpos = file.curPosition(); return out; }
211
+  static inline int16_t read(void *buf, uint16_t nbyte)  { return file.isOpen() ? file.read(buf, nbyte) : -1; }
197 212
   static inline int16_t write(void *buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
213
+  static inline void setIndex(const uint32_t index)      { file.seekSet((sdpos = index)); }
198 214
 
199 215
   // TODO: rename to diskIODriver()
200 216
   static DiskIODriver* diskIODriver() { return driver; }
@@ -318,7 +334,8 @@ private:
318 334
   #define IS_SD_INSERTED() true
319 335
 #endif
320 336
 
321
-#define IS_SD_PRINTING()  card.flag.sdprinting
337
+#define IS_SD_PRINTING()  (card.flag.sdprinting && !card.flag.abort_sd_printing)
338
+#define IS_SD_FETCHING()  (!card.flag.sdprintdone && IS_SD_PRINTING())
322 339
 #define IS_SD_PAUSED()    card.isPaused()
323 340
 #define IS_SD_FILE_OPEN() card.isFileOpen()
324 341
 
@@ -327,6 +344,7 @@ extern CardReader card;
327 344
 #else // !SDSUPPORT
328 345
 
329 346
 #define IS_SD_PRINTING()  false
347
+#define IS_SD_FETCHING()  false
330 348
 #define IS_SD_PAUSED()    false
331 349
 #define IS_SD_FILE_OPEN() false
332 350
 

Loading…
취소
저장