Tweak and use SD_ORDER

This commit is contained in:
Scott Lahteine 2020-07-16 22:20:55 -05:00
parent 6dd2b1210f
commit e90bbb37d4
4 changed files with 17 additions and 11 deletions

View File

@ -1547,8 +1547,9 @@ millis_t shift_ms; // = 0
inline void Init_Shift_Name() {
const bool is_subdir = !card.flag.workDirIsRoot;
const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
if (WITHIN(filenum, 0, card.get_num_Files() - 1)) {
card.getfilename_sorted(filenum);
const uint16_t fileCnt = card.get_num_Files();
if (WITHIN(filenum, 0, fileCnt - 1)) {
card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
char * const name = card.longest_filename();
make_name_without_ext(shift_name, name, 100);
}
@ -1561,8 +1562,8 @@ inline void Init_SDItem_Shift() {
}
/**
* Display an SD item, adding a CDUP for subfolders.
*/
* Display an SD item, adding a CDUP for subfolders.
*/
inline void Draw_SDItem(const uint16_t item, int16_t row=-1) {
if (row < 0) row = item + 1 + MROWS - index_file;
const bool is_subdir = !card.flag.workDirIsRoot;
@ -1898,7 +1899,7 @@ void HMI_SelectFile(void) {
}
else {
const uint16_t filenum = select_file.now - 1 - hasUpDir;
card.getfilename_sorted(filenum);
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
// Enter that folder!
if (card.flag.filenameIsDir) {
@ -3415,10 +3416,11 @@ void EachMomentUpdate(void) {
DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
};
LOOP_L_N(i, card.get_num_Files()) {
const uint16_t fileCnt = card.get_num_Files();
for (uint16_t i = 0; i < fileCnt; i++) {
// TODO: Resume print via M1000 then update the UI
// with the active filename which can come from CardReader.
card.getfilename_sorted(i);
card.getfilename_sorted(SD_ORDER(i, fileCnt));
if (!strcmp(card.filename, &recovery.info.sd_filename[1])) { // Resume print before power failure while have the same file
recovery_flag = 1;
HMI_flag.select_flag = 1;

View File

@ -126,7 +126,7 @@ void menu_media() {
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
if (_menuLineNr == _thisItemNr) {
card.getfilename_sorted(i);
card.getfilename_sorted(SD_ORDER(i, fileCnt));
if (card.flag.filenameIsDir)
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
else

View File

@ -947,7 +947,7 @@ void CardReader::cdroot() {
// Init sort order.
for (uint16_t i = 0; i < fileCnt; i++) {
sort_order[i] = SD_ORDER(i, fileCnt);
sort_order[i] = i;
// If using RAM then read all filenames now.
#if ENABLED(SDSORT_USES_RAM)
selectFileByIndex(i);

View File

@ -31,7 +31,11 @@
#define SD_RESORT 1
#endif
#define SD_ORDER(N,C) (TERN(SDCARD_RATHERRECENTFIRST, C - 1 - (N), N))
#if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
#define SD_ORDER(N,C) ((C) - 1 - (N))
#else
#define SD_ORDER(N,C) N
#endif
#define MAX_DIR_DEPTH 10 // Maximum folder depth
#define MAXDIRNAMELENGTH 8 // DOS folder name size