Browse Source

Rebuild SD file sort array on Stop SD Print (#9976)

Thanks Chuck Hellebuyck.
Scott Lahteine 7 years ago
parent
commit
22a017a856
No account linked to committer's email address

+ 6
- 2
Marlin/src/lcd/malyanlcd.cpp View File

228
     case 'X':
228
     case 'X':
229
       // cancel print
229
       // cancel print
230
       write_to_lcd_P(PSTR("{SYS:CANCELING}"));
230
       write_to_lcd_P(PSTR("{SYS:CANCELING}"));
231
-      card.stopSDPrint();
231
+      card.stopSDPrint(
232
+        #if SD_RESORT
233
+          true
234
+        #endif
235
+      );
232
       clear_command_queue();
236
       clear_command_queue();
233
       quickstop_stepper();
237
       quickstop_stepper();
234
       print_job_timer.stop();
238
       print_job_timer.stop();
448
   write_to_lcd(message_buffer);
452
   write_to_lcd(message_buffer);
449
 }
453
 }
450
 
454
 
451
-#endif // Malyan LCD
455
+#endif // MALYAN_LCD

+ 5
- 1
Marlin/src/lcd/ultralcd.cpp View File

856
     }
856
     }
857
 
857
 
858
     void lcd_sdcard_stop() {
858
     void lcd_sdcard_stop() {
859
-      card.stopSDPrint();
859
+      card.stopSDPrint(
860
+        #if SD_RESORT
861
+          true
862
+        #endif
863
+      );
860
       clear_command_queue();
864
       clear_command_queue();
861
       quickstop_stepper();
865
       quickstop_stepper();
862
       print_job_timer.stop();
866
       print_job_timer.stop();

+ 11
- 5
Marlin/src/sd/cardreader.cpp View File

328
   }
328
   }
329
 }
329
 }
330
 
330
 
331
-void CardReader::stopSDPrint() {
331
+void CardReader::stopSDPrint(
332
+  #if SD_RESORT
333
+    const bool re_sort/*=false*/
334
+  #endif
335
+) {
332
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
336
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
333
     did_pause_print = 0;
337
     did_pause_print = 0;
334
   #endif
338
   #endif
335
   sdprinting = false;
339
   sdprinting = false;
336
   if (isFileOpen()) file.close();
340
   if (isFileOpen()) file.close();
341
+  #if SD_RESORT
342
+    if (re_sort) presort();
343
+  #endif
337
 }
344
 }
338
 
345
 
339
 void CardReader::openLogFile(char* name) {
346
 void CardReader::openLogFile(char* name) {
700
    */
707
    */
701
   void CardReader::presort() {
708
   void CardReader::presort() {
702
 
709
 
710
+    // Throw away old sort index
711
+    flush_presort();
712
+
703
     // Sorting may be turned off
713
     // Sorting may be turned off
704
     #if ENABLED(SDSORT_GCODE)
714
     #if ENABLED(SDSORT_GCODE)
705
       if (!sort_alpha) return;
715
       if (!sort_alpha) return;
706
     #endif
716
     #endif
707
 
717
 
708
-    // Throw away old sort index
709
-    flush_presort();
710
-
711
     // If there are files, sort up to the limit
718
     // If there are files, sort up to the limit
712
     uint16_t fileCnt = getnrfilenames();
719
     uint16_t fileCnt = getnrfilenames();
713
     if (fileCnt > 0) {
720
     if (fileCnt > 0) {
940
     #if ENABLED(SDCARD_SORT_ALPHA)
947
     #if ENABLED(SDCARD_SORT_ALPHA)
941
       presort();
948
       presort();
942
     #endif
949
     #endif
943
-
944
     #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
950
     #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
945
       lcd_reselect_last_file();
951
       lcd_reselect_last_file();
946
     #endif
952
     #endif

+ 16
- 6
Marlin/src/sd/cardreader.h View File

23
 #ifndef _CARDREADER_H_
23
 #ifndef _CARDREADER_H_
24
 #define _CARDREADER_H_
24
 #define _CARDREADER_H_
25
 
25
 
26
+#include "../inc/MarlinConfig.h"
27
+
28
+#if ENABLED(SDSUPPORT)
29
+
30
+#define SD_RESORT ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_DYNAMIC_RAM)
31
+
26
 #define MAX_DIR_DEPTH 10          // Maximum folder depth
32
 #define MAX_DIR_DEPTH 10          // Maximum folder depth
27
 
33
 
28
 #include "SdFile.h"
34
 #include "SdFile.h"
29
 
35
 
30
-#include "../inc/MarlinConfig.h"
31
-
32
 class CardReader {
36
 class CardReader {
33
 public:
37
 public:
34
   CardReader();
38
   CardReader();
48
   void release();
52
   void release();
49
   void openAndPrintFile(const char *name);
53
   void openAndPrintFile(const char *name);
50
   void startFileprint();
54
   void startFileprint();
51
-  void stopSDPrint();
55
+  void stopSDPrint(
56
+    #if SD_RESORT
57
+      const bool re_sort=false
58
+    #endif
59
+  );
52
   void getStatus(
60
   void getStatus(
53
     #if NUM_SERIAL > 1
61
     #if NUM_SERIAL > 1
54
       const int8_t port = -1
62
       const int8_t port = -1
217
     #define IS_SD_INSERTED (READ(SD_DETECT_PIN) == LOW)
225
     #define IS_SD_INSERTED (READ(SD_DETECT_PIN) == LOW)
218
   #endif
226
   #endif
219
 #else
227
 #else
220
-  //No card detect line? Assume the card is inserted.
228
+  // No card detect line? Assume the card is inserted.
221
   #define IS_SD_INSERTED true
229
   #define IS_SD_INSERTED true
222
 #endif
230
 #endif
223
 
231
 
232
+extern CardReader card;
233
+
234
+#endif // SDSUPPORT
235
+
224
 #if ENABLED(SDSUPPORT)
236
 #if ENABLED(SDSUPPORT)
225
   #define IS_SD_PRINTING (card.sdprinting)
237
   #define IS_SD_PRINTING (card.sdprinting)
226
   #define IS_SD_FILE_OPEN (card.isFileOpen())
238
   #define IS_SD_FILE_OPEN (card.isFileOpen())
229
   #define IS_SD_FILE_OPEN (false)
241
   #define IS_SD_FILE_OPEN (false)
230
 #endif
242
 #endif
231
 
243
 
232
-extern CardReader card;
233
-
234
 #endif // _CARDREADER_H_
244
 #endif // _CARDREADER_H_

Loading…
Cancel
Save