Scott Lahteine пре 3 година
родитељ
комит
b65cdbed91
No account linked to committer's email address

+ 7
- 11
Marlin/src/MarlinCore.cpp Прегледај датотеку

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
  * Printing is paused according to SD or host indicators
344
  * Printing is paused according to SD or host indicators
367
 
363
 
368
   inline void abortSDPrinting() {
364
   inline void abortSDPrinting() {
369
     IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel());
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
     queue.clear();
368
     queue.clear();
373
     quickstop_stepper();
369
     quickstop_stepper();
748
 
744
 
749
   // Handle Power-Loss Recovery
745
   // Handle Power-Loss Recovery
750
   #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
746
   #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
751
-    if (printJobOngoing()) recovery.outage();
747
+    if (IS_SD_PRINTING()) recovery.outage();
752
   #endif
748
   #endif
753
 
749
 
754
   // Run StallGuard endstop checks
750
   // Run StallGuard endstop checks
901
     thermalManager.set_fans_paused(false); // Un-pause fans for safety
897
     thermalManager.set_fans_paused(false); // Un-pause fans for safety
902
   #endif
898
   #endif
903
 
899
 
904
-  if (IsRunning()) {
900
+  if (!IsStopped()) {
905
     SERIAL_ERROR_MSG(STR_ERR_STOPPED);
901
     SERIAL_ERROR_MSG(STR_ERR_STOPPED);
906
     LCD_MESSAGEPGM(MSG_STOPPED);
902
     LCD_MESSAGEPGM(MSG_STOPPED);
907
     safe_delay(350);       // allow enough time for messages to get out before stopping
903
     safe_delay(350);       // allow enough time for messages to get out before stopping

+ 1
- 0
Marlin/src/MarlinCore.h Прегледај датотеку

70
 inline bool IsStopped() { return marlin_state == MF_STOPPED; }
70
 inline bool IsStopped() { return marlin_state == MF_STOPPED; }
71
 
71
 
72
 bool printingIsActive();
72
 bool printingIsActive();
73
+bool printJobOngoing();
73
 bool printingIsPaused();
74
 bool printingIsPaused();
74
 void startOrResumeJob();
75
 void startOrResumeJob();
75
 
76
 

+ 1
- 1
Marlin/src/feature/pause.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/feature/powerloss.cpp Прегледај датотеку

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

+ 2
- 1
Marlin/src/gcode/queue.cpp Прегледај датотеку

550
   inline void GCodeQueue::get_sdcard_commands() {
550
   inline void GCodeQueue::get_sdcard_commands() {
551
     static uint8_t sd_input_state = PS_NORMAL;
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
     int sd_count = 0;
556
     int sd_count = 0;
556
     while (!ring_buffer.full() && !card.eof()) {
557
     while (!ring_buffer.full() && !card.eof()) {

+ 6
- 0
Marlin/src/gcode/sd/M1001.cpp Прегледај датотеку

25
 #if ENABLED(SDSUPPORT)
25
 #if ENABLED(SDSUPPORT)
26
 
26
 
27
 #include "../gcode.h"
27
 #include "../gcode.h"
28
+#include "../../module/planner.h"
28
 #include "../../module/printcounter.h"
29
 #include "../../module/printcounter.h"
29
 
30
 
30
 #if DISABLED(NO_SD_AUTOSTART)
31
 #if DISABLED(NO_SD_AUTOSTART)
64
  * M1001: Execute actions for SD print completion
65
  * M1001: Execute actions for SD print completion
65
  */
66
  */
66
 void GcodeSuite::M1001() {
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
   // If there's another auto#.g file to run...
73
   // If there's another auto#.g file to run...
68
   if (TERN(NO_SD_AUTOSTART, false, card.autofile_check())) return;
74
   if (TERN(NO_SD_AUTOSTART, false, card.autofile_check())) return;
69
 
75
 

+ 1
- 1
Marlin/src/gcode/sd/M24_M25.cpp Прегледај датотеку

70
   #endif
70
   #endif
71
 
71
 
72
   if (card.isFileOpen()) {
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
     startOrResumeJob();               // Start (or resume) the print job timer
74
     startOrResumeJob();               // Start (or resume) the print job timer
75
     TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
75
     TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
76
   }
76
   }

+ 1
- 1
Marlin/src/gcode/sd/M27.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/gcode/sd/M32.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/gcode/sd/M524.cpp Прегледај датотеку

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

+ 2
- 2
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Прегледај датотеку

755
   char buffer[14];
755
   char buffer[14];
756
 
756
 
757
   #if ENABLED(SHOW_REMAINING_TIME)
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
     if (show_remain) {
759
     if (show_remain) {
760
       #if ENABLED(USE_M73_REMAINING_TIME)
760
       #if ENABLED(USE_M73_REMAINING_TIME)
761
         duration_t remaining = ui.get_remaining_time();
761
         duration_t remaining = ui.get_remaining_time();
889
 
889
 
890
           #else // !HAS_DUAL_MIXING
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
             if (show_e_total) {
894
             if (show_e_total) {
895
               #if ENABLED(LCD_SHOW_E_TOTAL)
895
               #if ENABLED(LCD_SHOW_E_TOTAL)

+ 2
- 2
Marlin/src/lcd/dogm/status_screen_DOGM.cpp Прегледај датотеку

41
 #include "../../gcode/parser.h" // for units (and volumetric)
41
 #include "../../gcode/parser.h" // for units (and volumetric)
42
 
42
 
43
 #if ENABLED(LCD_SHOW_E_TOTAL)
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
 #endif
45
 #endif
46
 
46
 
47
 #if ENABLED(FILAMENT_LCD_DISPLAY)
47
 #if ENABLED(FILAMENT_LCD_DISPLAY)
464
     #endif
464
     #endif
465
   #endif
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
   // At the first page, generate new display values
469
   // At the first page, generate new display values
470
   if (first_page) {
470
   if (first_page) {

+ 2
- 2
Marlin/src/lcd/dwin/e3v2/dwin.cpp Прегледај датотеку

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

+ 3
- 4
Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp Прегледај датотеку

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

+ 5
- 5
Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp Прегледај датотеку

91
         cur_name = strrchr(list_file.file_name[sel_id], '/');
91
         cur_name = strrchr(list_file.file_name[sel_id], '/');
92
 
92
 
93
         SdFile file, *curDir;
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
         if (!fname) return;
96
         if (!fname) return;
97
         if (file.open(curDir, fname, O_READ)) {
97
         if (file.open(curDir, fname, O_READ)) {
98
           gCfgItems.curFilesize = file.fileSize();
98
           gCfgItems.curFilesize = file.fileSize();
108
             planner.flow_percentage[1] = 100;
108
             planner.flow_percentage[1] = 100;
109
             planner.e_factor[1]        = planner.flow_percentage[1] * 0.01f;
109
             planner.e_factor[1]        = planner.flow_percentage[1] * 0.01f;
110
           #endif
110
           #endif
111
-          card.startFileprint();
111
+          card.startOrResumeFilePrinting();
112
           #if ENABLED(POWER_LOSS_RECOVERY)
112
           #if ENABLED(POWER_LOSS_RECOVERY)
113
             recovery.prepare();
113
             recovery.prepare();
114
           #endif
114
           #endif
124
     lv_draw_ready_print();
124
     lv_draw_ready_print();
125
 
125
 
126
     #if ENABLED(SDSUPPORT)
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
     #endif
129
     #endif
130
   }
130
   }
131
   else if (DIALOG_IS(TYPE_FINISH_PRINT)) {
131
   else if (DIALOG_IS(TYPE_FINISH_PRINT)) {

+ 3
- 5
Marlin/src/lcd/extui/mks_ui/draw_ui.cpp Прегледај датотеку

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

+ 9
- 11
Marlin/src/lcd/extui/mks_ui/wifi_module.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp Прегледај датотеку

625
 
625
 
626
 // Try to upload the given file at the given address
626
 // Try to upload the given file at the given address
627
 void SendUpdateFile(const char *file, uint32_t address) {
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
   if (!update_file.open(update_curDir, fname, O_READ)) return;
629
   if (!update_file.open(update_curDir, fname, O_READ)) return;
630
 
630
 
631
   esp_upload.fileSize = update_file.fileSize();
631
   esp_upload.fileSize = update_file.fileSize();

+ 5
- 17
Marlin/src/lcd/extui/ui_api.cpp Прегледај датотеку

54
 #include "../../module/printcounter.h"
54
 #include "../../module/printcounter.h"
55
 #include "../../libs/duration_t.h"
55
 #include "../../libs/duration_t.h"
56
 #include "../../HAL/shared/Delay.h"
56
 #include "../../HAL/shared/Delay.h"
57
+#include "../../MarlinCore.h"
57
 #include "../../sd/cardreader.h"
58
 #include "../../sd/cardreader.h"
58
 
59
 
59
 #if ENABLED(PRINTCOUNTER)
60
 #if ENABLED(PRINTCOUNTER)
106
     #if ENABLED(JOYSTICK)
107
     #if ENABLED(JOYSTICK)
107
       uint8_t jogging : 1;
108
       uint8_t jogging : 1;
108
     #endif
109
     #endif
109
-    #if ENABLED(SDSUPPORT)
110
-      uint8_t was_sd_printing : 1;
111
-    #endif
112
   } flags;
110
   } flags;
113
 
111
 
114
   #ifdef __SAM3X8E__
112
   #ifdef __SAM3X8E__
1017
   void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }
1015
   void setUserConfirmed() { TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); }
1018
 
1016
 
1019
   void printFile(const char *filename) {
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
   bool isPrintingFromMediaPaused() {
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
   bool isPrinting() {
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
   bool isPrintingPaused() {
1031
   bool isPrintingPaused() {

+ 1
- 1
Marlin/src/lcd/marlinui.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/module/endstops.cpp Прегледај датотеку

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

+ 38
- 26
Marlin/src/sd/cardreader.cpp Прегледај датотеку

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

+ 39
- 21
Marlin/src/sd/cardreader.h Прегледај датотеку

70
   bool saving:1,
70
   bool saving:1,
71
        logging:1,
71
        logging:1,
72
        sdprinting:1,
72
        sdprinting:1,
73
+       sdprintdone:1,
73
        mounted:1,
74
        mounted:1,
74
        filenameIsDir:1,
75
        filenameIsDir:1,
75
        workDirIsRoot:1,
76
        workDirIsRoot:1,
147
 
148
 
148
   // Select a file
149
   // Select a file
149
   static void selectFileByIndex(const uint16_t nr);
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
   // Print job
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
   static void report_status();
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
   #if HAS_PRINT_PROGRESS_PERMYRIAD
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
   #endif
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
   // Helper for open and remove
179
   // Helper for open and remove
169
   static const char* diveToFile(const bool update_cwd, SdFile* &curDir, const char * const path, const bool echo=false);
180
   static const char* diveToFile(const bool update_cwd, SdFile* &curDir, const char * const path, const bool echo=false);
186
     static void removeJobRecoveryFile();
197
     static void removeJobRecoveryFile();
187
   #endif
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
   static inline int16_t write(void *buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }
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
   // TODO: rename to diskIODriver()
215
   // TODO: rename to diskIODriver()
200
   static DiskIODriver* diskIODriver() { return driver; }
216
   static DiskIODriver* diskIODriver() { return driver; }
318
   #define IS_SD_INSERTED() true
334
   #define IS_SD_INSERTED() true
319
 #endif
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
 #define IS_SD_PAUSED()    card.isPaused()
339
 #define IS_SD_PAUSED()    card.isPaused()
323
 #define IS_SD_FILE_OPEN() card.isFileOpen()
340
 #define IS_SD_FILE_OPEN() card.isFileOpen()
324
 
341
 
327
 #else // !SDSUPPORT
344
 #else // !SDSUPPORT
328
 
345
 
329
 #define IS_SD_PRINTING()  false
346
 #define IS_SD_PRINTING()  false
347
+#define IS_SD_FETCHING()  false
330
 #define IS_SD_PAUSED()    false
348
 #define IS_SD_PAUSED()    false
331
 #define IS_SD_FILE_OPEN() false
349
 #define IS_SD_FILE_OPEN() false
332
 
350
 

Loading…
Откажи
Сачувај