Browse Source

Tweak and use SD_ORDER

Scott Lahteine 5 years ago
parent
commit
e90bbb37d4

+ 10
- 8
Marlin/src/lcd/dwin/dwin.cpp View File

1547
 inline void Init_Shift_Name() {
1547
 inline void Init_Shift_Name() {
1548
   const bool is_subdir = !card.flag.workDirIsRoot;
1548
   const bool is_subdir = !card.flag.workDirIsRoot;
1549
   const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
1549
   const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
1550
-  if (WITHIN(filenum, 0, card.get_num_Files() - 1)) {
1551
-    card.getfilename_sorted(filenum);
1550
+  const uint16_t fileCnt = card.get_num_Files();
1551
+  if (WITHIN(filenum, 0, fileCnt - 1)) {
1552
+    card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
1552
     char * const name = card.longest_filename();
1553
     char * const name = card.longest_filename();
1553
     make_name_without_ext(shift_name, name, 100);
1554
     make_name_without_ext(shift_name, name, 100);
1554
   }
1555
   }
1561
 }
1562
 }
1562
 
1563
 
1563
 /**
1564
 /**
1564
-* Display an SD item, adding a CDUP for subfolders.
1565
-*/
1565
+ * Display an SD item, adding a CDUP for subfolders.
1566
+ */
1566
 inline void Draw_SDItem(const uint16_t item, int16_t row=-1) {
1567
 inline void Draw_SDItem(const uint16_t item, int16_t row=-1) {
1567
   if (row < 0) row = item + 1 + MROWS - index_file;
1568
   if (row < 0) row = item + 1 + MROWS - index_file;
1568
   const bool is_subdir = !card.flag.workDirIsRoot;
1569
   const bool is_subdir = !card.flag.workDirIsRoot;
1617
 
1618
 
1618
   // As many files as will fit
1619
   // As many files as will fit
1619
   LOOP_L_N(i, _MIN(nr_sd_menu_items(), MROWS))
1620
   LOOP_L_N(i, _MIN(nr_sd_menu_items(), MROWS))
1620
-  Draw_SDItem(i, i + 1);
1621
+    Draw_SDItem(i, i + 1);
1621
 
1622
 
1622
   Init_SDItem_Shift();
1623
   Init_SDItem_Shift();
1623
 }
1624
 }
1898
     }
1899
     }
1899
     else {
1900
     else {
1900
       const uint16_t filenum = select_file.now - 1 - hasUpDir;
1901
       const uint16_t filenum = select_file.now - 1 - hasUpDir;
1901
-      card.getfilename_sorted(filenum);
1902
+      card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
1902
 
1903
 
1903
       // Enter that folder!
1904
       // Enter that folder!
1904
       if (card.flag.filenameIsDir) {
1905
       if (card.flag.filenameIsDir) {
3415
       DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
3416
       DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
3416
     };
3417
     };
3417
 
3418
 
3418
-    LOOP_L_N(i, card.get_num_Files()) {
3419
+    const uint16_t fileCnt = card.get_num_Files();
3420
+    for (uint16_t i = 0; i < fileCnt; i++) {
3419
       // TODO: Resume print via M1000 then update the UI
3421
       // TODO: Resume print via M1000 then update the UI
3420
       // with the active filename which can come from CardReader.
3422
       // with the active filename which can come from CardReader.
3421
-      card.getfilename_sorted(i);
3423
+      card.getfilename_sorted(SD_ORDER(i, fileCnt));
3422
       if (!strcmp(card.filename, &recovery.info.sd_filename[1])) { // Resume print before power failure while have the same file
3424
       if (!strcmp(card.filename, &recovery.info.sd_filename[1])) { // Resume print before power failure while have the same file
3423
         recovery_flag = 1;
3425
         recovery_flag = 1;
3424
         HMI_flag.select_flag = 1;
3426
         HMI_flag.select_flag = 1;

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

126
 
126
 
127
   if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
127
   if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
128
     if (_menuLineNr == _thisItemNr) {
128
     if (_menuLineNr == _thisItemNr) {
129
-      card.getfilename_sorted(i);
129
+      card.getfilename_sorted(SD_ORDER(i, fileCnt));
130
       if (card.flag.filenameIsDir)
130
       if (card.flag.filenameIsDir)
131
         MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
131
         MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
132
       else
132
       else

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

947
 
947
 
948
         // Init sort order.
948
         // Init sort order.
949
         for (uint16_t i = 0; i < fileCnt; i++) {
949
         for (uint16_t i = 0; i < fileCnt; i++) {
950
-          sort_order[i] = SD_ORDER(i, fileCnt);
950
+          sort_order[i] = i;
951
           // If using RAM then read all filenames now.
951
           // If using RAM then read all filenames now.
952
           #if ENABLED(SDSORT_USES_RAM)
952
           #if ENABLED(SDSORT_USES_RAM)
953
             selectFileByIndex(i);
953
             selectFileByIndex(i);

+ 5
- 1
Marlin/src/sd/cardreader.h View File

31
   #define SD_RESORT 1
31
   #define SD_RESORT 1
32
 #endif
32
 #endif
33
 
33
 
34
-#define SD_ORDER(N,C) (TERN(SDCARD_RATHERRECENTFIRST, C - 1 - (N), N))
34
+#if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
35
+  #define SD_ORDER(N,C) ((C) - 1 - (N))
36
+#else
37
+  #define SD_ORDER(N,C) N
38
+#endif
35
 
39
 
36
 #define MAX_DIR_DEPTH     10       // Maximum folder depth
40
 #define MAX_DIR_DEPTH     10       // Maximum folder depth
37
 #define MAXDIRNAMELENGTH   8       // DOS folder name size
41
 #define MAXDIRNAMELENGTH   8       // DOS folder name size

Loading…
Cancel
Save