Browse Source

Do SD sort order in CardReader

Scott Lahteine 4 years ago
parent
commit
967c1d8534

+ 1
- 7
Marlin/src/lcd/extui/ui_api.cpp View File

@@ -1039,13 +1039,7 @@ namespace ExtUI {
1039 1039
   bool FileList::seek(const uint16_t pos, const bool skip_range_check) {
1040 1040
     #if ENABLED(SDSUPPORT)
1041 1041
       if (!skip_range_check && (pos + 1) > count()) return false;
1042
-      const uint16_t nr =
1043
-        #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
1044
-          count() - 1 -
1045
-        #endif
1046
-      pos;
1047
-
1048
-      card.getfilename_sorted(nr);
1042
+      card.getfilename_sorted(SD_ORDER(pos, count()));
1049 1043
       return card.filename[0] != '\0';
1050 1044
     #else
1051 1045
       UNUSED(pos);

+ 1
- 8
Marlin/src/lcd/menu/menu_media.cpp View File

@@ -140,14 +140,7 @@ void menu_media() {
140 140
 
141 141
   if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
142 142
     if (_menuLineNr == _thisItemNr) {
143
-      const uint16_t nr =
144
-        #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
145
-          fileCnt - 1 -
146
-        #endif
147
-      i;
148
-
149
-      card.getfilename_sorted(nr);
150
-
143
+      card.getfilename_sorted(SD_ORDER(i, fileCnt));
151 144
       if (card.flag.filenameIsDir)
152 145
         MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
153 146
       else

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

@@ -924,7 +924,7 @@ void CardReader::cdroot() {
924 924
 
925 925
         // Init sort order.
926 926
         for (uint16_t i = 0; i < fileCnt; i++) {
927
-          sort_order[i] = TERN(SDCARD_RATHERRECENTFIRST, fileCnt - 1 - i, i);
927
+          sort_order[i] = SD_ORDER(i, fileCnt);
928 928
           // If using RAM then read all filenames now.
929 929
           #if ENABLED(SDSORT_USES_RAM)
930 930
             selectFileByIndex(i);

+ 2
- 0
Marlin/src/sd/cardreader.h View File

@@ -29,6 +29,8 @@
29 29
   #define SD_RESORT 1
30 30
 #endif
31 31
 
32
+#define SD_ORDER(N,C) (TERN(SDCARD_RATHERRECENTFIRST, C - 1 - (N), N))
33
+
32 34
 #define MAX_DIR_DEPTH     10       // Maximum folder depth
33 35
 #define MAXDIRNAMELENGTH   8       // DOS folder name size
34 36
 #define MAXPATHNAMELENGTH  (1 + (MAXDIRNAMELENGTH + 1) * (MAX_DIR_DEPTH) + 1 + FILENAME_LENGTH) // "/" + N * ("ADIRNAME/") + "filename.ext"

Loading…
Cancel
Save