mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-27 13:56:24 +00:00
Apply SDCARD_SORT_ALPHA changes from 2.0.x
This commit is contained in:
parent
d3b8f30818
commit
a6ee4a0468
@ -74,9 +74,12 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
|
|||||||
/**
|
/**
|
||||||
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
|
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
|
||||||
* LS_Count - Add +1 to nrFiles for every file within the parent
|
* LS_Count - Add +1 to nrFiles for every file within the parent
|
||||||
* LS_GetFilename - Get the filename of the file indexed by nrFiles
|
* LS_GetFilename - Get the filename of the file indexed by nrFile_index
|
||||||
* LS_SerialPrint - Print the full path and size of each file to serial output
|
* LS_SerialPrint - Print the full path and size of each file to serial output
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
uint16_t nrFile_index;
|
||||||
|
|
||||||
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
||||||
dir_t p;
|
dir_t p;
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
@ -130,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
|||||||
|
|
||||||
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
|
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
|
||||||
|
|
||||||
switch (lsAction) {
|
switch (lsAction) { // 1 based file count
|
||||||
case LS_Count:
|
case LS_Count:
|
||||||
nrFiles++;
|
nrFiles++;
|
||||||
break;
|
break;
|
||||||
@ -148,7 +151,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
|||||||
if (match != NULL) {
|
if (match != NULL) {
|
||||||
if (strcasecmp(match, filename) == 0) return;
|
if (strcasecmp(match, filename) == 0) return;
|
||||||
}
|
}
|
||||||
else if (cnt == nrFiles) return;
|
else if (cnt == nrFile_index) return; // 0 based index
|
||||||
cnt++;
|
cnt++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -587,7 +590,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
|
|||||||
#endif // SDSORT_CACHE_NAMES
|
#endif // SDSORT_CACHE_NAMES
|
||||||
curDir = &workDir;
|
curDir = &workDir;
|
||||||
lsAction = LS_GetFilename;
|
lsAction = LS_GetFilename;
|
||||||
nrFiles = nr;
|
nrFile_index = nr;
|
||||||
curDir->rewind();
|
curDir->rewind();
|
||||||
lsDive("", *curDir, match);
|
lsDive("", *curDir, match);
|
||||||
}
|
}
|
||||||
@ -688,7 +691,7 @@ void CardReader::updir() {
|
|||||||
sortnames = new char*[fileCnt];
|
sortnames = new char*[fileCnt];
|
||||||
#endif
|
#endif
|
||||||
#elif ENABLED(SDSORT_USES_STACK)
|
#elif ENABLED(SDSORT_USES_STACK)
|
||||||
char sortnames[fileCnt][LONG_FILENAME_LENGTH];
|
char sortnames[fileCnt][SORTED_LONGNAME_MAXLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Folder sorting needs 1 bit per entry for flags.
|
// Folder sorting needs 1 bit per entry for flags.
|
||||||
@ -727,7 +730,12 @@ void CardReader::updir() {
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
// Copy filenames into the static array
|
// Copy filenames into the static array
|
||||||
strcpy(sortnames[i], LONGEST_FILENAME);
|
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
||||||
|
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
||||||
|
sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
||||||
|
#else
|
||||||
|
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
||||||
|
#endif
|
||||||
#if ENABLED(SDSORT_CACHE_NAMES)
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
||||||
strcpy(sortshort[i], filename);
|
strcpy(sortshort[i], filename);
|
||||||
#endif
|
#endif
|
||||||
@ -818,13 +826,22 @@ void CardReader::updir() {
|
|||||||
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
||||||
sortnames = new char*[1];
|
sortnames = new char*[1];
|
||||||
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
||||||
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
||||||
sortshort = new char*[1];
|
sortshort = new char*[1];
|
||||||
sortshort[0] = strdup(filename); // malloc
|
sortshort[0] = strdup(filename); // malloc
|
||||||
|
#endif
|
||||||
isDir = new uint8_t[1];
|
isDir = new uint8_t[1];
|
||||||
#else
|
#else
|
||||||
strcpy(sortnames[0], LONGEST_FILENAME);
|
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
||||||
|
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
||||||
|
sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
||||||
|
#else
|
||||||
|
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
||||||
|
#endif
|
||||||
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
||||||
strcpy(sortshort[0], filename);
|
strcpy(sortshort[0], filename);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -852,6 +869,16 @@ void CardReader::updir() {
|
|||||||
|
|
||||||
#endif // SDCARD_SORT_ALPHA
|
#endif // SDCARD_SORT_ALPHA
|
||||||
|
|
||||||
|
uint16_t CardReader::get_num_Files() {
|
||||||
|
return
|
||||||
|
#if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
|
||||||
|
nrFiles // no need to access the SD card for filenames
|
||||||
|
#else
|
||||||
|
getnrfilenames()
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void CardReader::printingHasFinished() {
|
void CardReader::printingHasFinished() {
|
||||||
stepper.synchronize();
|
stepper.synchronize();
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -70,6 +70,8 @@ public:
|
|||||||
void updir();
|
void updir();
|
||||||
void setroot();
|
void setroot();
|
||||||
|
|
||||||
|
uint16_t get_num_Files();
|
||||||
|
|
||||||
#if ENABLED(SDCARD_SORT_ALPHA)
|
#if ENABLED(SDCARD_SORT_ALPHA)
|
||||||
void presort();
|
void presort();
|
||||||
void getfilename_sorted(const uint16_t nr);
|
void getfilename_sorted(const uint16_t nr);
|
||||||
@ -112,6 +114,12 @@ private:
|
|||||||
uint8_t sort_order[SDSORT_LIMIT];
|
uint8_t sort_order[SDSORT_LIMIT];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)
|
||||||
|
#define SORTED_LONGNAME_MAXLEN ((SDSORT_CACHE_VFATS) * (FILENAME_LENGTH) + 1)
|
||||||
|
#else
|
||||||
|
#define SORTED_LONGNAME_MAXLEN LONG_FILENAME_LENGTH
|
||||||
|
#endif
|
||||||
|
|
||||||
// Cache filenames to speed up SD menus.
|
// Cache filenames to speed up SD menus.
|
||||||
#if ENABLED(SDSORT_USES_RAM)
|
#if ENABLED(SDSORT_USES_RAM)
|
||||||
|
|
||||||
@ -121,10 +129,10 @@ private:
|
|||||||
char **sortshort, **sortnames;
|
char **sortshort, **sortnames;
|
||||||
#else
|
#else
|
||||||
char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
|
char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
|
||||||
char sortnames[SDSORT_LIMIT][SDSORT_CACHE_VFATS * FILENAME_LENGTH + 1];
|
char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
|
||||||
#endif
|
#endif
|
||||||
#elif DISABLED(SDSORT_USES_STACK)
|
#elif DISABLED(SDSORT_USES_STACK)
|
||||||
char sortnames[SDSORT_LIMIT][LONG_FILENAME_LENGTH];
|
char sortnames[SDSORT_LIMIT][SORTED_LONGNAME_MAXLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Folder sorting uses an isDir array when caching items.
|
// Folder sorting uses an isDir array when caching items.
|
||||||
|
@ -3799,7 +3799,8 @@ void kill_screen(const char* lcd_msg) {
|
|||||||
void lcd_sdcard_menu() {
|
void lcd_sdcard_menu() {
|
||||||
ENCODER_DIRECTION_MENUS();
|
ENCODER_DIRECTION_MENUS();
|
||||||
|
|
||||||
const uint16_t fileCnt = card.getnrfilenames();
|
const uint16_t fileCnt = card.get_num_Files();
|
||||||
|
|
||||||
START_MENU();
|
START_MENU();
|
||||||
MENU_BACK(MSG_MAIN);
|
MENU_BACK(MSG_MAIN);
|
||||||
card.getWorkDirName();
|
card.getWorkDirName();
|
||||||
|
Loading…
Reference in New Issue
Block a user