Browse Source

Add root flag to CardReader (#15275)

Robby Candra 5 years ago
parent
commit
98233b1de0

+ 1
- 2
Marlin/src/lcd/extensible_ui/ui_api.cpp View File

975
 
975
 
976
   bool FileList::isAtRootDir() {
976
   bool FileList::isAtRootDir() {
977
     #if ENABLED(SDSUPPORT)
977
     #if ENABLED(SDSUPPORT)
978
-      card.getWorkDirName();
979
-      return card.filename[0] == '/';
978
+      card.flag.workDirIsRoot;
980
     #else
979
     #else
981
       return true;
980
       return true;
982
     #endif
981
     #endif

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

127
 
127
 
128
   #if HAS_GRAPHICAL_LCD
128
   #if HAS_GRAPHICAL_LCD
129
     static uint16_t fileCnt;
129
     static uint16_t fileCnt;
130
-    static bool at_root;
131
-    if (ui.first_page) {
132
-      fileCnt = card.get_num_Files();
133
-      card.getWorkDirName();
134
-      at_root = card.filename[0] == '/';
135
-    }
130
+    if (ui.first_page) fileCnt = card.get_num_Files();
136
   #else
131
   #else
137
     const uint16_t fileCnt = card.get_num_Files();
132
     const uint16_t fileCnt = card.get_num_Files();
138
-    card.getWorkDirName();
139
-    const bool at_root = card.filename[0] == '/';
140
   #endif
133
   #endif
141
 
134
 
142
   START_MENU();
135
   START_MENU();
143
   MENU_BACK(MSG_MAIN);
136
   MENU_BACK(MSG_MAIN);
144
-  if (at_root) {
137
+  if (card.flag.workDirIsRoot) {
145
     #if !PIN_EXISTS(SD_DETECT)
138
     #if !PIN_EXISTS(SD_DETECT)
146
       MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
139
       MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
147
     #endif
140
     #endif

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

629
   lsDive(nullptr, workDir, match);
629
   lsDive(nullptr, workDir, match);
630
 }
630
 }
631
 
631
 
632
-uint16_t CardReader::getnrfilenames() {
632
+uint16_t CardReader::countFilesInWorkDir() {
633
   lsAction = LS_Count;
633
   lsAction = LS_Count;
634
   nrFiles = 0;
634
   nrFiles = 0;
635
   workDir.rewind();
635
   workDir.rewind();
707
 
707
 
708
   if (newDir.open(parent, relpath, O_READ)) {
708
   if (newDir.open(parent, relpath, O_READ)) {
709
     workDir = newDir;
709
     workDir = newDir;
710
+    flag.workDirIsRoot = false;
710
     if (workDirDepth < MAX_DIR_DEPTH)
711
     if (workDirDepth < MAX_DIR_DEPTH)
711
       workDirParents[workDirDepth++] = workDir;
712
       workDirParents[workDirDepth++] = workDir;
712
     #if ENABLED(SDCARD_SORT_ALPHA)
713
     #if ENABLED(SDCARD_SORT_ALPHA)
726
       presort();
727
       presort();
727
     #endif
728
     #endif
728
   }
729
   }
730
+  if (!workDirDepth) flag.workDirIsRoot = true;
729
   return workDirDepth;
731
   return workDirDepth;
730
 }
732
 }
731
 
733
 
732
 void CardReader::setroot() {
734
 void CardReader::setroot() {
733
-  /*if (!workDir.openRoot(&volume)) {
734
-    SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
735
-  }*/
736
   workDir = root;
735
   workDir = root;
736
+  flag.workDirIsRoot = true;
737
   #if ENABLED(SDCARD_SORT_ALPHA)
737
   #if ENABLED(SDCARD_SORT_ALPHA)
738
     presort();
738
     presort();
739
   #endif
739
   #endif
801
     #endif
801
     #endif
802
 
802
 
803
     // If there are files, sort up to the limit
803
     // If there are files, sort up to the limit
804
-    uint16_t fileCnt = getnrfilenames();
804
+    uint16_t fileCnt = countFilesInWorkDir();
805
     if (fileCnt > 0) {
805
     if (fileCnt > 0) {
806
 
806
 
807
       // Never sort more than the max allowed
807
       // Never sort more than the max allowed
981
     #if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
981
     #if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
982
       nrFiles // no need to access the SD card for filenames
982
       nrFiles // no need to access the SD card for filenames
983
     #else
983
     #else
984
-      getnrfilenames()
984
+      countFilesInWorkDir()
985
     #endif
985
     #endif
986
   ;
986
   ;
987
 }
987
 }

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

41
        sdprinting:1,
41
        sdprinting:1,
42
        mounted:1,
42
        mounted:1,
43
        filenameIsDir:1,
43
        filenameIsDir:1,
44
+       workDirIsRoot:1,
44
        abort_sd_printing:1
45
        abort_sd_printing:1
45
        #if ENABLED(BINARY_FILE_TRANSFER)
46
        #if ENABLED(BINARY_FILE_TRANSFER)
46
          , binary_mode:1
47
          , binary_mode:1
79
   #endif
80
   #endif
80
 
81
 
81
   static void getfilename(uint16_t nr, const char* const match=nullptr);
82
   static void getfilename(uint16_t nr, const char* const match=nullptr);
82
-  static uint16_t getnrfilenames();
83
+  static uint16_t countFilesInWorkDir();
83
 
84
 
84
   static void getAbsFilename(char *t);
85
   static void getAbsFilename(char *t);
85
 
86
 

Loading…
Cancel
Save