소스 검색

New feature: SDCARD_SORT_ALPHA

Scott Lahteine 8 년 전
부모
커밋
a561bd5e3a

+ 9
- 0
.travis.yml 파일 보기

@@ -298,6 +298,15 @@ script:
298 298
   - opt_enable G3D_PANEL SDSUPPORT
299 299
   - build_marlin
300 300
   #
301
+  # Add SDCARD_SORT_ALPHA, test G3D_PANEL again
302
+  #
303
+  - opt_enable_adv SDCARD_SORT_ALPHA
304
+  - opt_set_adv SDSORT_GCODE true
305
+  - opt_set_adv SDSORT_USES_RAM true
306
+  - opt_set_adv SDSORT_USES_STACK true
307
+  - opt_set_adv SDSORT_CACHE_NAMES true
308
+  - build_marlin
309
+  #
301 310
   # REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
302 311
   #
303 312
   - restore_configs

+ 4
- 0
Marlin/Conditionals_post.h 파일 보기

@@ -722,4 +722,8 @@
722 722
     #define DELTA_ENDSTOP_ADJ { 0 }
723 723
   #endif
724 724
 
725
+  #if ENABLED(SDCARD_SORT_ALPHA)
726
+    #define HAS_FOLDER_SORTING (FOLDER_SORTING || ENABLED(SDSORT_GCODE))
727
+  #endif
728
+
725 729
 #endif // CONDITIONALS_POST_H

+ 34
- 0
Marlin/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 20
- 0
Marlin/Marlin_main.cpp 파일 보기

@@ -91,6 +91,7 @@
91 91
  *        Use P to run other files as sub-programs: "M32 P !filename#"
92 92
  *        The '#' is necessary when calling from within sd files, as it stops buffer prereading
93 93
  * M33  - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT)
94
+ * M34  - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA)
94 95
  * M42  - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted.
95 96
  * M43  - Monitor pins & report changes - report active pins
96 97
  * M48  - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST)
@@ -4843,6 +4844,20 @@ inline void gcode_M31() {
4843 4844
 
4844 4845
   #endif
4845 4846
 
4847
+  #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE)
4848
+    /**
4849
+     * M34: Set SD Card Sorting Options
4850
+     */
4851
+    inline void gcode_M34() {
4852
+      if (code_seen('S')) card.setSortOn(code_value_bool());
4853
+      if (code_seen('F')) {
4854
+        int v = code_value_long();
4855
+        card.setSortFolders(v < 0 ? -1 : v > 0 ? 1 : 0);
4856
+      }
4857
+      //if (code_seen('R')) card.setSortReverse(code_value_bool());
4858
+    }
4859
+  #endif // SDCARD_SORT_ALPHA && SDSORT_GCODE
4860
+
4846 4861
   /**
4847 4862
    * M928: Start SD Write
4848 4863
    */
@@ -8289,6 +8304,11 @@ void process_next_command() {
8289 8304
             gcode_M33(); break;
8290 8305
         #endif
8291 8306
 
8307
+        #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE)
8308
+          case 34: //M34 - Set SD card sorting options
8309
+            gcode_M34(); break;
8310
+        #endif // SDCARD_SORT_ALPHA && SDSORT_GCODE
8311
+
8292 8312
         case 928: // M928: Start SD write
8293 8313
           gcode_M928(); break;
8294 8314
       #endif //SDSUPPORT

+ 13
- 0
Marlin/SanityCheck.h 파일 보기

@@ -206,6 +206,19 @@
206 206
 #endif
207 207
 
208 208
 /**
209
+ * SD File Sorting
210
+ */
211
+#if ENABLED(SDCARD_SORT_ALPHA)
212
+  #if SDSORT_LIMIT > 256
213
+    #error "SDSORT_LIMIT must be 256 or smaller."
214
+  #elif SDSORT_LIMIT < 10
215
+    #error "SDSORT_LIMIT should be greater than 9 to be useful."
216
+  #elif DISABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES)
217
+    #error "SDSORT_CACHE_NAMES requires SDSORT_USES_RAM (which reads the directory into RAM)."
218
+  #endif
219
+#endif
220
+
221
+/**
209 222
  * Delta requirements
210 223
  */
211 224
 #if ENABLED(DELTA)

+ 215
- 2
Marlin/cardreader.cpp 파일 보기

@@ -30,7 +30,17 @@
30 30
 
31 31
 #if ENABLED(SDSUPPORT)
32 32
 
33
+#define LONGEST_FILENAME (longFilename[0] ? longFilename : filename)
34
+
33 35
 CardReader::CardReader() {
36
+  #if ENABLED(SDCARD_SORT_ALPHA)
37
+    sort_count = 0;
38
+    #if ENABLED(SDSORT_GCODE)
39
+      sort_alpha = true;
40
+      sort_folders = FOLDER_SORTING;
41
+      //sort_reverse = false;
42
+    #endif
43
+  #endif
34 44
   sdprinting = cardOK = saving = logging = false;
35 45
   filesize = 0;
36 46
   sdpos = 0;
@@ -243,6 +253,9 @@ void CardReader::initsd() {
243 253
   }
244 254
   workDir = root;
245 255
   curDir = &root;
256
+  #if ENABLED(SDCARD_SORT_ALPHA)
257
+    presort();
258
+  #endif
246 259
   /**
247 260
   if (!workDir.openRoot(&volume)) {
248 261
     SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
@@ -256,6 +269,9 @@ void CardReader::setroot() {
256 269
   }*/
257 270
   workDir = root;
258 271
   curDir = &workDir;
272
+  #if ENABLED(SDCARD_SORT_ALPHA)
273
+    presort();
274
+  #endif
259 275
 }
260 276
 
261 277
 void CardReader::release() {
@@ -272,7 +288,12 @@ void CardReader::openAndPrintFile(const char *name) {
272 288
 }
273 289
 
274 290
 void CardReader::startFileprint() {
275
-  if (cardOK) sdprinting = true;
291
+  if (cardOK) {
292
+    sdprinting = true;
293
+    #if ENABLED(SDCARD_SORT_ALPHA)
294
+      flush_presort();
295
+    #endif
296
+  }
276 297
 }
277 298
 
278 299
 void CardReader::stopSDPrint() {
@@ -463,6 +484,9 @@ void CardReader::removeFile(char* name) {
463 484
     SERIAL_PROTOCOLPGM("File deleted:");
464 485
     SERIAL_PROTOCOLLN(fname);
465 486
     sdpos = 0;
487
+    #if ENABLED(SDCARD_SORT_ALPHA)
488
+      presort();
489
+    #endif
466 490
   }
467 491
   else {
468 492
     SERIAL_PROTOCOLPGM("Deletion failed, File: ");
@@ -551,6 +575,20 @@ void CardReader::closefile(bool store_location) {
551 575
  * Get the name of a file in the current directory by index
552 576
  */
553 577
 void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
578
+  #if ENABLED(SDSORT_CACHE_NAMES)
579
+    if (match != NULL) {
580
+      while (nr < sort_count) {
581
+        if (strcasecmp(match, sortshort[nr]) == 0) break;
582
+        nr++;
583
+      }
584
+    }
585
+    if (nr < sort_count) {
586
+      strcpy(filename, sortshort[nr]);
587
+      strcpy(longFilename, sortnames[nr]);
588
+      filenameIsDir = TEST(isDir[nr>>3], nr & 0x07);
589
+      return;
590
+    }
591
+  #endif // SDSORT_CACHE_NAMES
554 592
   curDir = &workDir;
555 593
   lsAction = LS_GetFilename;
556 594
   nrFiles = nr;
@@ -583,14 +621,186 @@ void CardReader::chdir(const char * relpath) {
583 621
     if (workDirDepth < MAX_DIR_DEPTH)
584 622
       workDirParents[workDirDepth++] = *parent;
585 623
     workDir = newfile;
624
+    #if ENABLED(SDCARD_SORT_ALPHA)
625
+      presort();
626
+    #endif
586 627
   }
587 628
 }
588 629
 
589 630
 void CardReader::updir() {
590
-  if (workDirDepth > 0)
631
+  if (workDirDepth > 0) {
591 632
     workDir = workDirParents[--workDirDepth];
633
+    #if ENABLED(SDCARD_SORT_ALPHA)
634
+      presort();
635
+    #endif
636
+  }
592 637
 }
593 638
 
639
+#if ENABLED(SDCARD_SORT_ALPHA)
640
+
641
+  /**
642
+   * Get the name of a file in the current directory by sort-index
643
+   */
644
+  void CardReader::getfilename_sorted(const uint16_t nr) {
645
+    getfilename(
646
+      #if ENABLED(SDSORT_GCODE)
647
+        sort_alpha &&
648
+      #endif
649
+      (nr < sort_count) ? sort_order[nr] : nr
650
+    );
651
+  }
652
+
653
+  /**
654
+   * Read all the files and produce a sort key
655
+   *
656
+   * We can do this in 3 ways...
657
+   *  - Minimal RAM: Read two filenames at a time sorting along...
658
+   *  - Some RAM: Buffer the directory just for this sort
659
+   *  - Most RAM: Buffer the directory and return filenames from RAM
660
+   */
661
+  void CardReader::presort() {
662
+
663
+    // Sorting may be turned off
664
+    #if ENABLED(SDSORT_GCODE)
665
+      if (!sort_alpha) return;
666
+    #endif
667
+
668
+    // Throw away old sort index
669
+    flush_presort();
670
+
671
+    // If there are files, sort up to the limit
672
+    uint16_t fileCnt = getnrfilenames();
673
+    if (fileCnt > 0) {
674
+
675
+      // Never sort more than the max allowed
676
+      // If you use folders to organize, 20 may be enough
677
+      if (fileCnt > SDSORT_LIMIT) fileCnt = SDSORT_LIMIT;
678
+
679
+      // Use RAM to store the entire directory during pre-sort.
680
+      // SDSORT_LIMIT should be set to prevent over-allocation.
681
+      #if ENABLED(SDSORT_USES_RAM)
682
+
683
+        #if ENABLED(SDSORT_USES_STACK)
684
+          #if DISABLED(SDSORT_CACHE_NAMES)
685
+            char sortnames[fileCnt][LONG_FILENAME_LENGTH];
686
+          #endif
687
+          // Folder sorting needs 1 bit per entry for flags.
688
+          #if HAS_FOLDER_SORTING
689
+            uint8_t isDir[(fileCnt + 7) >> 3];
690
+          #endif
691
+        #endif
692
+
693
+      #else // !SDSORT_USES_RAM
694
+
695
+        // By default re-read the names from SD for every compare
696
+        // retaining only two filenames at a time. This is very
697
+        // slow but is safest and uses minimal RAM.
698
+        char name1[LONG_FILENAME_LENGTH + 1];
699
+
700
+      #endif
701
+
702
+      if (fileCnt > 1) {
703
+
704
+        // Init sort order.
705
+        for (uint16_t i = 0; i < fileCnt; i++) {
706
+          sort_order[i] = i;
707
+          // If using RAM then read all filenames now.
708
+          #if ENABLED(SDSORT_USES_RAM)
709
+            getfilename(i);
710
+            strcpy(sortnames[i], LONGEST_FILENAME);
711
+            #if ENABLED(SDSORT_CACHE_NAMES)
712
+              strcpy(sortshort[i], filename);
713
+            #endif
714
+            // char out[30];
715
+            // sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
716
+            // SERIAL_ECHOLN(out);
717
+            #if HAS_FOLDER_SORTING
718
+              const uint16_t bit = i & 0x07, ind = i >> 3;
719
+              if (bit == 0) isDir[ind] = 0x00;
720
+              if (filenameIsDir) isDir[ind] |= _BV(bit);
721
+            #endif
722
+          #endif
723
+        }
724
+
725
+        // Bubble Sort
726
+        for (uint16_t i = fileCnt; --i;) {
727
+          bool didSwap = false;
728
+          for (uint16_t j = 0; j < i; ++j) {
729
+            const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1];
730
+
731
+            // Compare names from the array or just the two buffered names
732
+            #if ENABLED(SDSORT_USES_RAM)
733
+              #define _SORT_CMP_NODIR() (strcasecmp(sortnames[o1], sortnames[o2]) > 0)
734
+            #else
735
+              #define _SORT_CMP_NODIR() (strcasecmp(name1, name2) > 0)
736
+            #endif
737
+
738
+            #if HAS_FOLDER_SORTING
739
+              #if ENABLED(SDSORT_USES_RAM)
740
+                // Folder sorting needs an index and bit to test for folder-ness.
741
+                const uint8_t ind1 = o1 >> 3, bit1 = o1 & 0x07,
742
+                              ind2 = o2 >> 3, bit2 = o2 & 0x07;
743
+                #define _SORT_CMP_DIR(fs) \
744
+                  (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
745
+                    ? _SORT_CMP_NODIR() \
746
+                    : (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
747
+              #else
748
+                #define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
749
+              #endif
750
+            #endif
751
+
752
+            // The most economical method reads names as-needed
753
+            // throughout the loop. Slow if there are many.
754
+            #if DISABLED(SDSORT_USES_RAM)
755
+              getfilename(o1);
756
+              strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
757
+              #if HAS_FOLDER_SORTING
758
+                bool dir1 = filenameIsDir;
759
+              #endif
760
+              getfilename(o2);
761
+              char *name2 = LONGEST_FILENAME; // use the string in-place
762
+            #endif // !SDSORT_USES_RAM
763
+
764
+            // Sort the current pair according to settings.
765
+            if (
766
+              #if HAS_FOLDER_SORTING
767
+                #if ENABLED(SDSORT_GCODE)
768
+                  sort_folders ? _SORT_CMP_DIR(sort_folders) : _SORT_CMP_NODIR()
769
+                #else
770
+                  _SORT_CMP_DIR(FOLDER_SORTING)
771
+                #endif
772
+              #else
773
+                _SORT_CMP_NODIR()
774
+              #endif
775
+            ) {
776
+              sort_order[j] = o2;
777
+              sort_order[j + 1] = o1;
778
+              didSwap = true;
779
+            }
780
+          }
781
+          if (!didSwap) break;
782
+        }
783
+      }
784
+      else {
785
+        sort_order[0] = 0;
786
+        #if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES)
787
+          getfilename(0);
788
+          strcpy(sortnames[0], LONGEST_FILENAME);
789
+          strcpy(sortshort[0], filename);
790
+          isDir[0] = filenameIsDir ? 0x01 : 0x00;
791
+        #endif
792
+      }
793
+
794
+      sort_count = fileCnt;
795
+    }
796
+  }
797
+
798
+  void CardReader::flush_presort() {
799
+    sort_count = 0;
800
+  }
801
+
802
+#endif // SDCARD_SORT_ALPHA
803
+
594 804
 void CardReader::printingHasFinished() {
595 805
   stepper.synchronize();
596 806
   file.close();
@@ -607,6 +817,9 @@ void CardReader::printingHasFinished() {
607 817
     print_job_timer.stop();
608 818
     if (print_job_timer.duration() > 60)
609 819
       enqueue_and_echo_commands_P(PSTR("M31"));
820
+    #if ENABLED(SDCARD_SORT_ALPHA)
821
+      presort();
822
+    #endif
610 823
   }
611 824
 }
612 825
 

+ 46
- 0
Marlin/cardreader.h 파일 보기

@@ -69,6 +69,16 @@ public:
69 69
   void updir();
70 70
   void setroot();
71 71
 
72
+  #if ENABLED(SDCARD_SORT_ALPHA)
73
+    void presort();
74
+    void getfilename_sorted(const uint16_t nr);
75
+    #if ENABLED(SDSORT_GCODE)
76
+      FORCE_INLINE void setSortOn(bool b) { sort_alpha = b; presort(); }
77
+      FORCE_INLINE void setSortFolders(int i) { sort_folders = i; presort(); }
78
+      //FORCE_INLINE void setSortReverse(bool b) { sort_reverse = b; }
79
+    #endif
80
+  #endif
81
+
72 82
   FORCE_INLINE void pauseSDPrint() { sdprinting = false; }
73 83
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
74 84
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
@@ -84,6 +94,38 @@ public:
84 94
 private:
85 95
   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
86 96
   uint8_t workDirDepth;
97
+
98
+  // Sort files and folders alphabetically.
99
+  #if ENABLED(SDCARD_SORT_ALPHA)
100
+    uint16_t sort_count;        // Count of sorted items in the current directory
101
+    #if ENABLED(SDSORT_GCODE)
102
+      bool sort_alpha;          // Flag to enable / disable the feature
103
+      int sort_folders;         // Flag to enable / disable folder sorting
104
+      //bool sort_reverse;      // Flag to enable / disable reverse sorting
105
+    #endif
106
+
107
+    uint8_t sort_order[SDSORT_LIMIT];
108
+
109
+    // Cache filenames to speed up SD menus.
110
+    #if ENABLED(SDSORT_USES_RAM)
111
+
112
+      // If using dynamic ram for names, allocate on the heap.
113
+      #if ENABLED(SDSORT_CACHE_NAMES)
114
+        char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
115
+        char sortnames[SDSORT_LIMIT][FILENAME_LENGTH];
116
+      #elif DISABLED(SDSORT_USES_STACK)
117
+        char sortnames[SDSORT_LIMIT][FILENAME_LENGTH];
118
+      #endif
119
+
120
+      // Folder sorting uses an isDir array when caching items.
121
+      #if HAS_FOLDER_SORTING && (ENABLED(SDSORT_CACHE_NAMES) || DISABLED(SDSORT_USES_STACK))
122
+        uint8_t isDir[(SDSORT_LIMIT+7)>>3];
123
+      #endif
124
+
125
+    #endif // SDSORT_USES_RAM
126
+
127
+  #endif // SDCARD_SORT_ALPHA
128
+
87 129
   Sd2Card card;
88 130
   SdVolume volume;
89 131
   SdFile file;
@@ -103,6 +145,10 @@ private:
103 145
   uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
104 146
   char* diveDirName;
105 147
   void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
148
+
149
+  #if ENABLED(SDCARD_SORT_ALPHA)
150
+    void flush_presort();
151
+  #endif
106 152
 };
107 153
 
108 154
 extern CardReader card;

+ 34
- 0
Marlin/example_configurations/Cartesio/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/Felix/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/Hephestos/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/Hephestos_2/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/K8200/Configuration_adv.h 파일 보기

@@ -455,6 +455,40 @@
455 455
   // using:
456 456
   #define MENU_ADDAUTOSTART
457 457
 
458
+  /**
459
+   * Sort SD file listings in alphabetical order.
460
+   *
461
+   * With this option enabled, items on SD cards will be sorted
462
+   * by name for easier navigation.
463
+   *
464
+   * By default...
465
+   *
466
+   *  - Use the slowest -but safest- method for sorting.
467
+   *  - Folders are sorted to the top.
468
+   *  - The sort key is statically allocated.
469
+   *  - No added G-code (M34) support.
470
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
471
+   *
472
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
473
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
474
+   * limit is exceeded.
475
+   *
476
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
477
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
478
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
479
+   */
480
+  //#define SDCARD_SORT_ALPHA
481
+
482
+  // SD Card Sorting options
483
+  #if ENABLED(SDCARD_SORT_ALPHA)
484
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
485
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
486
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
487
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
488
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
489
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
490
+  #endif
491
+
458 492
   // Show a progress bar on HD44780 LCDs for SD printing
459 493
   #define LCD_PROGRESS_BAR
460 494
 

+ 34
- 0
Marlin/example_configurations/K8400/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/RigidBot/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/SCARA/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/TAZ4/Configuration_adv.h 파일 보기

@@ -450,6 +450,40 @@
450 450
   // using:
451 451
   //#define MENU_ADDAUTOSTART
452 452
 
453
+  /**
454
+   * Sort SD file listings in alphabetical order.
455
+   *
456
+   * With this option enabled, items on SD cards will be sorted
457
+   * by name for easier navigation.
458
+   *
459
+   * By default...
460
+   *
461
+   *  - Use the slowest -but safest- method for sorting.
462
+   *  - Folders are sorted to the top.
463
+   *  - The sort key is statically allocated.
464
+   *  - No added G-code (M34) support.
465
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
466
+   *
467
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
468
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
469
+   * limit is exceeded.
470
+   *
471
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
472
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
473
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
474
+   */
475
+  //#define SDCARD_SORT_ALPHA
476
+
477
+  // SD Card Sorting options
478
+  #if ENABLED(SDCARD_SORT_ALPHA)
479
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
480
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
481
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
482
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
483
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
484
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
485
+  #endif
486
+
453 487
   // Show a progress bar on HD44780 LCDs for SD printing
454 488
   //#define LCD_PROGRESS_BAR
455 489
 

+ 34
- 0
Marlin/example_configurations/WITBOX/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/delta/generic/Configuration_adv.h 파일 보기

@@ -444,6 +444,40 @@
444 444
   // using:
445 445
   //#define MENU_ADDAUTOSTART
446 446
 
447
+  /**
448
+   * Sort SD file listings in alphabetical order.
449
+   *
450
+   * With this option enabled, items on SD cards will be sorted
451
+   * by name for easier navigation.
452
+   *
453
+   * By default...
454
+   *
455
+   *  - Use the slowest -but safest- method for sorting.
456
+   *  - Folders are sorted to the top.
457
+   *  - The sort key is statically allocated.
458
+   *  - No added G-code (M34) support.
459
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
460
+   *
461
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
462
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
463
+   * limit is exceeded.
464
+   *
465
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
466
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
467
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
468
+   */
469
+  //#define SDCARD_SORT_ALPHA
470
+
471
+  // SD Card Sorting options
472
+  #if ENABLED(SDCARD_SORT_ALPHA)
473
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
474
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
475
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
476
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
477
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
478
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
479
+  #endif
480
+
447 481
   // Show a progress bar on HD44780 LCDs for SD printing
448 482
   //#define LCD_PROGRESS_BAR
449 483
 

+ 34
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h 파일 보기

@@ -444,6 +444,40 @@
444 444
   // using:
445 445
   //#define MENU_ADDAUTOSTART
446 446
 
447
+  /**
448
+   * Sort SD file listings in alphabetical order.
449
+   *
450
+   * With this option enabled, items on SD cards will be sorted
451
+   * by name for easier navigation.
452
+   *
453
+   * By default...
454
+   *
455
+   *  - Use the slowest -but safest- method for sorting.
456
+   *  - Folders are sorted to the top.
457
+   *  - The sort key is statically allocated.
458
+   *  - No added G-code (M34) support.
459
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
460
+   *
461
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
462
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
463
+   * limit is exceeded.
464
+   *
465
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
466
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
467
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
468
+   */
469
+  //#define SDCARD_SORT_ALPHA
470
+
471
+  // SD Card Sorting options
472
+  #if ENABLED(SDCARD_SORT_ALPHA)
473
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
474
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
475
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
476
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
477
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
478
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
479
+  #endif
480
+
447 481
   // Show a progress bar on HD44780 LCDs for SD printing
448 482
   //#define LCD_PROGRESS_BAR
449 483
 

+ 34
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h 파일 보기

@@ -449,6 +449,40 @@
449 449
   // using:
450 450
   //#define MENU_ADDAUTOSTART
451 451
 
452
+  /**
453
+   * Sort SD file listings in alphabetical order.
454
+   *
455
+   * With this option enabled, items on SD cards will be sorted
456
+   * by name for easier navigation.
457
+   *
458
+   * By default...
459
+   *
460
+   *  - Use the slowest -but safest- method for sorting.
461
+   *  - Folders are sorted to the top.
462
+   *  - The sort key is statically allocated.
463
+   *  - No added G-code (M34) support.
464
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
465
+   *
466
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
467
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
468
+   * limit is exceeded.
469
+   *
470
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
471
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
472
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
473
+   */
474
+  //#define SDCARD_SORT_ALPHA
475
+
476
+  // SD Card Sorting options
477
+  #if ENABLED(SDCARD_SORT_ALPHA)
478
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
479
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
480
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
481
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
482
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
483
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
484
+  #endif
485
+
452 486
   // Show a progress bar on HD44780 LCDs for SD printing
453 487
   //#define LCD_PROGRESS_BAR
454 488
 

+ 34
- 0
Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h 파일 보기

@@ -444,6 +444,40 @@
444 444
   // using:
445 445
   //#define MENU_ADDAUTOSTART
446 446
 
447
+  /**
448
+   * Sort SD file listings in alphabetical order.
449
+   *
450
+   * With this option enabled, items on SD cards will be sorted
451
+   * by name for easier navigation.
452
+   *
453
+   * By default...
454
+   *
455
+   *  - Use the slowest -but safest- method for sorting.
456
+   *  - Folders are sorted to the top.
457
+   *  - The sort key is statically allocated.
458
+   *  - No added G-code (M34) support.
459
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
460
+   *
461
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
462
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
463
+   * limit is exceeded.
464
+   *
465
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
466
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
467
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
468
+   */
469
+  //#define SDCARD_SORT_ALPHA
470
+
471
+  // SD Card Sorting options
472
+  #if ENABLED(SDCARD_SORT_ALPHA)
473
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
474
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
475
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
476
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
477
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
478
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
479
+  #endif
480
+
447 481
   // Show a progress bar on HD44780 LCDs for SD printing
448 482
   //#define LCD_PROGRESS_BAR
449 483
 

+ 34
- 0
Marlin/example_configurations/makibox/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 34
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h 파일 보기

@@ -442,6 +442,40 @@
442 442
   // using:
443 443
   //#define MENU_ADDAUTOSTART
444 444
 
445
+  /**
446
+   * Sort SD file listings in alphabetical order.
447
+   *
448
+   * With this option enabled, items on SD cards will be sorted
449
+   * by name for easier navigation.
450
+   *
451
+   * By default...
452
+   *
453
+   *  - Use the slowest -but safest- method for sorting.
454
+   *  - Folders are sorted to the top.
455
+   *  - The sort key is statically allocated.
456
+   *  - No added G-code (M34) support.
457
+   *  - 40 item sorting limit. (Items after the first 40 are unsorted.)
458
+   *
459
+   * SD sorting uses static allocation (as set by SDSORT_LIMIT), allowing the
460
+   * compiler to calculate the worst-case usage and throw an error if the SRAM
461
+   * limit is exceeded.
462
+   *
463
+   *  - SDSORT_USES_RAM provides faster sorting via a static directory buffer.
464
+   *  - SDSORT_USES_STACK does the same, but uses a local stack-based buffer.
465
+   *  - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
466
+   */
467
+  //#define SDCARD_SORT_ALPHA
468
+
469
+  // SD Card Sorting options
470
+  #if ENABLED(SDCARD_SORT_ALPHA)
471
+    #define SDSORT_LIMIT       40     // Maximum number of sorted items (10-256).
472
+    #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
473
+    #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
474
+    #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
475
+    #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
476
+    #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
477
+  #endif
478
+
445 479
   // Show a progress bar on HD44780 LCDs for SD printing
446 480
   //#define LCD_PROGRESS_BAR
447 481
 

+ 11
- 6
Marlin/ultralcd.cpp 파일 보기

@@ -2277,12 +2277,17 @@ KeepDrawing:
2277 2277
 
2278 2278
       for (uint16_t i = 0; i < fileCnt; i++) {
2279 2279
         if (_menuLineNr == _thisItemNr) {
2280
-          card.getfilename(
2281
-             #if ENABLED(SDCARD_RATHERRECENTFIRST)
2282
-               fileCnt-1 -
2283
-             #endif
2284
-             i
2285
-          );
2280
+          #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
2281
+            int nr = fileCnt - 1 - i;
2282
+          #else
2283
+            int nr = i;
2284
+          #endif
2285
+
2286
+          #if ENABLED(SDCARD_SORT_ALPHA)
2287
+            card.getfilename_sorted(nr);
2288
+          #else
2289
+            card.getfilename(nr);
2290
+          #endif
2286 2291
 
2287 2292
           if (card.filenameIsDir)
2288 2293
             MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);

Loading…
취소
저장