Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache file count in CardReader #25611

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions Marlin/src/feature/easythreed_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,31 +190,28 @@ void EasythreedUI::printButton() {
print_key_flag = PF_PAUSE; // The "Print" button now pauses the print
card.mount(); // Force SD card to mount - now!
if (!card.isMounted) { // Failed to mount?
blink_interval_ms = LED_OFF; // Turn off LED
print_key_flag = PF_START;
return; // Bail out
blink_interval_ms = LED_OFF; // Turn off LED
print_key_flag = PF_START;
return; // Bail out
}
card.ls(); // List all files to serial output
const uint16_t filecnt = card.countFilesInWorkDir(); // Count printable files in cwd
const int16_t filecnt = card.get_num_items(); // Count printable files in cwd
if (filecnt == 0) return; // None are printable?
card.selectFileByIndex(filecnt); // Select the last file according to current sort options
card.openAndPrintFile(card.filename); // Start printing it
break;
}
} break;
case PF_PAUSE: { // Pause printing (not currently firing)
if (!printingIsActive()) break;
blink_interval_ms = LED_ON; // Set indicator to steady ON
queue.inject(F("M25")); // Queue Pause
print_key_flag = PF_RESUME; // The "Print" button now resumes the print
break;
}
} break;
case PF_RESUME: { // Resume printing
if (printingIsActive()) break;
blink_interval_ms = LED_BLINK_2; // Blink the indicator LED at 1 second intervals
queue.inject(F("M24")); // Queue resume
print_key_flag = PF_PAUSE; // The "Print" button now pauses the print
break;
}
} break;
}
}
else { // Register a longer press
Expand Down
23 changes: 13 additions & 10 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3262,9 +3262,9 @@

// Number of VFAT entries used. Each entry has 13 UTF-16 characters
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
#define MAX_VFAT_ENTRIES (5)
#define MAX_VFAT_ENTRIES 5
#else
#define MAX_VFAT_ENTRIES (2)
#define MAX_VFAT_ENTRIES 2
#endif

// Nozzle park for Delta
Expand All @@ -3279,14 +3279,17 @@
#if defined(TARGET_LPC1768) && IS_RRD_FG_SC && (SD_SCK_PIN == LCD_PINS_D4)
#define SDCARD_SORT_ALPHA // Keep one directory level in RAM. Changing directory levels
// may still glitch the screen, but LCD updates clean it up.
#undef SDSORT_LIMIT
#undef SDSORT_USES_RAM
#undef SDSORT_USES_STACK
#undef SDSORT_CACHE_NAMES
#define SDSORT_LIMIT 64
#define SDSORT_USES_RAM true
#define SDSORT_USES_STACK false
#define SDSORT_CACHE_NAMES true
#if SDSORT_LIMIT > 64 || !SDSORT_USES_RAM || SDSORT_USES_STACK || !SDSORT_CACHE_NAMES
#undef SDSORT_LIMIT
#undef SDSORT_USES_RAM
#undef SDSORT_USES_STACK
#undef SDSORT_CACHE_NAMES
#define SDSORT_LIMIT 64
#define SDSORT_USES_RAM true
#define SDSORT_USES_STACK false
#define SDSORT_CACHE_NAMES true
#define SDSORT_CACHE_LPC1768_WARNING 1
#endif
#ifndef FOLDER_SORTING
#define FOLDER_SORTING -1
#endif
Expand Down
15 changes: 8 additions & 7 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,9 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
* SD File Sorting
*/
#if ENABLED(SDCARD_SORT_ALPHA)
#if SDSORT_LIMIT > 256
#if NONE(EXTENSIBLE_UI, HAS_MARLINUI_MENU, DWIN_CREALITY_LCD, DWIN_CREALITY_LCD_JYERSUI, DWIN_LCD_PROUI)
#error "SDCARD_SORT_ALPHA requires an LCD that supports it. (It doesn't apply to M20, etc.)"
#elif SDSORT_LIMIT > 256
#error "SDSORT_LIMIT must be 256 or smaller."
#elif SDSORT_LIMIT < 10
#error "SDSORT_LIMIT should be greater than 9 to be useful."
Expand All @@ -1049,7 +1051,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#elif SDSORT_CACHE_VFATS > MAX_VFAT_ENTRIES
#undef SDSORT_CACHE_VFATS
#define SDSORT_CACHE_VFATS MAX_VFAT_ENTRIES
#warning "SDSORT_CACHE_VFATS was reduced to MAX_VFAT_ENTRIES!"
#define SDSORT_CACHE_VFATS_WARNING 1
#endif
#endif
#endif
Expand Down Expand Up @@ -3117,14 +3119,13 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
/**
* Make sure features that need to write to the SD card can
*/
#if ENABLED(SDCARD_READONLY) && ANY(POWER_LOSS_RECOVERY, BINARY_FILE_TRANSFER, SDCARD_EEPROM_EMULATION)
#undef SDCARD_READONLY
#if ENABLED(SDCARD_READONLY)
#if ENABLED(POWER_LOSS_RECOVERY)
#warning "Either disable SDCARD_READONLY or disable POWER_LOSS_RECOVERY."
#error "Either disable SDCARD_READONLY or disable POWER_LOSS_RECOVERY."
#elif ENABLED(BINARY_FILE_TRANSFER)
#warning "Either disable SDCARD_READONLY or disable BINARY_FILE_TRANSFER."
#error "Either disable SDCARD_READONLY or disable BINARY_FILE_TRANSFER."
#elif ENABLED(SDCARD_EEPROM_EMULATION)
#warning "Either disable SDCARD_READONLY or disable SDCARD_EEPROM_EMULATION."
#error "Either disable SDCARD_READONLY or disable SDCARD_EEPROM_EMULATION."
#endif
#endif

Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/inc/Warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,10 @@
#if MULTISTEPPING_LIMIT_WARNING
#warning "MULTISTEPPING_LIMIT has been automatically set to 128. Use a lower value if the machine is slow to respond."
#endif

#if SDSORT_CACHE_VFATS_WARNING
#warning "SDSORT_CACHE_VFATS has been reduced to MAX_VFAT_ENTRIES."
#endif
#if SDSORT_CACHE_LPC1768_WARNING
#warning "SDCARD_SORT_ALPHA sub-options overridden for LPC1768 with DOGM LCD SCK overlap."
#endif
10 changes: 5 additions & 5 deletions Marlin/src/lcd/e3v2/creality/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void Scroll_Menu(const uint8_t dir) {
}

inline uint16_t nr_sd_menu_items() {
return card.get_num_Files() + !card.flag.workDirIsRoot;
return card.get_num_items() + !card.flag.workDirIsRoot;
}

void Erase_Menu_Text(const uint8_t line) {
Expand Down Expand Up @@ -1830,9 +1830,9 @@ void MarlinUI::refresh() { /* Nothing to see here */ }
void Init_Shift_Name() {
const bool is_subdir = !card.flag.workDirIsRoot;
const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
const uint16_t fileCnt = card.get_num_Files();
const int16_t fileCnt = card.get_num_items();
if (WITHIN(filenum, 0, fileCnt - 1)) {
card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
card.selectFileByIndexSorted(filenum);
char * const name = card.longest_filename();
make_name_without_ext(shift_name, name, 100);
}
Expand All @@ -1857,7 +1857,7 @@ void Draw_SDItem(const uint16_t item, int16_t row=-1) {
return;
}

card.getfilename_sorted(SD_ORDER(item - is_subdir, card.get_num_Files()));
card.selectFileByIndexSorted(item - is_subdir);
char * const name = card.longest_filename();

#if ENABLED(SCROLL_LONG_FILENAMES)
Expand Down Expand Up @@ -2223,7 +2223,7 @@ void HMI_SelectFile() {
}
else {
const uint16_t filenum = select_file.now - 1 - hasUpDir;
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
card.selectFileByIndexSorted(filenum);

// Enter that folder!
if (card.flag.filenameIsDir) {
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ void CrealityDWINClass::Draw_SD_Item(uint8_t item, uint8_t row) {
if (item == 0)
Draw_Menu_Item(0, ICON_Back, card.flag.workDirIsRoot ? F("Back") : F(".."));
else {
card.getfilename_sorted(SD_ORDER(item - 1, card.get_num_Files()));
card.selectFileByIndexSorted(item - 1);
char * const filename = card.longest_filename();
size_t max = MENU_CHAR_LIMIT;
size_t pos = strlen(filename), len = pos;
Expand All @@ -831,7 +831,7 @@ void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) {
scrollpos = 0;
process = File;
if (card.isMounted() && !removed) {
LOOP_L_N(i, _MIN(card.get_num_Files() + 1, TROWS))
LOOP_L_N(i, _MIN(card.get_num_items() + 1, TROWS))
Draw_SD_Item(i, i);
}
else {
Expand Down Expand Up @@ -4281,7 +4281,7 @@ void CrealityDWINClass::File_Control() {
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
if (encoder_diffState == ENCODER_DIFF_NO) {
if (selection > 0) {
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
card.selectFileByIndexSorted(selection - 1);
char * const filename = card.longest_filename();
size_t len = strlen(filename);
size_t pos = len;
Expand All @@ -4300,7 +4300,7 @@ void CrealityDWINClass::File_Control() {
}
return;
}
if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_Files()) {
if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_items()) {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
if (selection > 0) {
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
Expand Down Expand Up @@ -4340,7 +4340,7 @@ void CrealityDWINClass::File_Control() {
}
}
else {
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
card.selectFileByIndexSorted(selection - 1);
if (card.flag.filenameIsDir) {
card.cd(card.filename);
Draw_SD_List();
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ void SetMediaAutoMount() {
}

inline uint16_t nr_sd_menu_items() {
return _MIN(card.get_num_Files() + !card.flag.workDirIsRoot, MENU_MAX_ITEMS);
return _MIN(card.get_num_items() + !card.flag.workDirIsRoot, MENU_MAX_ITEMS);
}

void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT) {
Expand Down Expand Up @@ -891,7 +891,7 @@ void onClickSDItem() {
if (hasUpDir && CurrentMenu->selected == 1) return SDCard_Up();
else {
const uint16_t filenum = CurrentMenu->selected - 1 - hasUpDir;
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
card.selectFileByIndexSorted(filenum);

// Enter that folder!
if (card.flag.filenameIsDir) return SDCard_Folder(card.filename);
Expand Down Expand Up @@ -934,7 +934,7 @@ void onClickSDItem() {
last_itemselected = selected;
if (selected >= 1 + hasUpDir) {
const int8_t filenum = selected - 1 - hasUpDir; // Skip "Back" and ".."
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
card.selectFileByIndexSorted(filenum);
make_name_without_ext(shift_name, card.longest_filename(), LONG_FILENAME_LENGTH);
shift_len = strlen(shift_name);
shift_amt = 0;
Expand All @@ -959,7 +959,7 @@ void onDrawFileName(MenuItemClass* menuitem, int8_t line) {
}
else {
uint8_t icon;
card.getfilename_sorted(SD_ORDER(menuitem->pos - is_subdir - 1, card.get_num_Files()));
card.selectFileByIndexSorted(menuitem->pos - is_subdir - 1);
make_name_without_ext(shift_name, card.longest_filename());
icon = card.flag.filenameIsDir ? ICON_Folder : card.fileIsBinary() ? ICON_Binary : ICON_File;
Draw_Menu_Line(line, icon, shift_name);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/malyan/malyan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ void process_lcd_s_command(const char *command) {
// select a file for printing during a print, there's
// little reason not to do it this way.
char message_buffer[MAX_CURLY_COMMAND];
uint16_t file_count = card.get_num_Files();
for (uint16_t i = 0; i < file_count; i++) {
int16_t file_count = card.get_num_items();
for (int16_t i = 0; i < file_count; i++) {
card.selectFileByIndex(i);
sprintf_P(message_buffer, card.flag.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
write_to_lcd(message_buffer);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ uint8_t sel_id = 0;
else
card.cdroot();

const uint16_t fileCnt = card.get_num_Files();
const int16_t fileCnt = card.get_num_items();

for (uint16_t i = 0; i < fileCnt; i++) {
for (int16_t i = 0; i < fileCnt; i++) {
if (list_file.Sd_file_cnt == list_file.Sd_file_offset) {
card.getfilename_sorted(SD_ORDER(i, fileCnt));
card.selectFileByIndexSorted(i);

list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir;
strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/wifi_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,12 +823,12 @@ uint8_t Explore_Disk(const char * const path, const uint8_t recu_level, const bo

if (!path) return 0;

const uint8_t fileCnt = card.get_num_Files();
const int16_t fileCnt = card.get_num_items();

MediaFile file;
MediaFile *diveDir;
for (uint8_t i = 0; i < fileCnt; i++) {
card.getfilename_sorted(SD_ORDER(i, fileCnt));
for (int16_t i = 0; i < fileCnt; i++) {
card.selectFileByIndexSorted(i);

ZERO(Fstream);
strcpy(Fstream, card.filename);
Expand Down
18 changes: 5 additions & 13 deletions Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,12 +1136,12 @@ namespace ExtUI {

FileList::FileList() { refresh(); }

void FileList::refresh() { num_files = 0xFFFF; }
void FileList::refresh() { }

bool FileList::seek(const uint16_t pos, const bool skip_range_check) {
#if ENABLED(SDSUPPORT)
if (!skip_range_check && (pos + 1) > count()) return false;
card.getfilename_sorted(SD_ORDER(pos, count()));
card.selectFileByIndexSorted(pos);
return card.filename[0] != '\0';
#else
UNUSED(pos);
Expand All @@ -1167,27 +1167,19 @@ namespace ExtUI {
}

uint16_t FileList::count() {
return TERN0(SDSUPPORT, (num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)));
return TERN0(SDSUPPORT, card.get_num_items());
}

bool FileList::isAtRootDir() {
return TERN1(SDSUPPORT, card.flag.workDirIsRoot);
}

void FileList::upDir() {
#if ENABLED(SDSUPPORT)
card.cdup();
num_files = 0xFFFF;
#endif
TERN_(SDSUPPORT, card.cdup());
}

void FileList::changeDir(const char * const dirname) {
#if ENABLED(SDSUPPORT)
card.cd(dirname);
num_files = 0xFFFF;
#else
UNUSED(dirname);
#endif
TERN(SDSUPPORT, card.cd(dirname), UNUSED(dirname));
}

} // namespace ExtUI
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/lcd/extui/ui_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,6 @@ namespace ExtUI {
void resumePrint();

class FileList {
private:
uint16_t num_files;

public:
FileList();
void refresh();
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ void menu_media_filelist() {
ui.encoder_direction_menus();

#if HAS_MARLINUI_U8GLIB
static uint16_t fileCnt;
if (ui.first_page) fileCnt = card.get_num_Files();
static int16_t fileCnt;
if (ui.first_page) fileCnt = card.get_num_items();
#else
const uint16_t fileCnt = card.get_num_Files();
const int16_t fileCnt = card.get_num_items();
#endif

START_MENU();
Expand All @@ -129,9 +129,9 @@ void menu_media_filelist() {
else if (card.isMounted())
ACTION_ITEM_F(F(LCD_STR_FOLDER " .."), lcd_sd_updir);

if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
if (ui.should_draw()) for (int16_t i = 0; i < fileCnt; i++) {
if (_menuLineNr == _thisItemNr) {
card.getfilename_sorted(SD_ORDER(i, fileCnt));
card.selectFileByIndexSorted(i);
if (card.flag.filenameIsDir)
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
else
Expand Down
Loading