Skip to content

Commit 6b65665

Browse files
committed
πŸ§‘β€πŸ’» SD card
1 parent 8753015 commit 6b65665

File tree

16 files changed

+273
-209
lines changed

16 files changed

+273
-209
lines changed

β€ŽMarlin/src/feature/easythreed_ui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ void EasythreedUI::printButton() {
195195
return; // Bail out
196196
}
197197
card.ls(); // List all files to serial output
198-
const uint16_t filecnt = card.countFilesInWorkDir(); // Count printable files in cwd
198+
const int16_t filecnt = card.get_num_items(); // Count printable files in cwd
199199
if (filecnt == 0) return; // None are printable?
200-
card.selectFileByIndex(filecnt); // Select the last file according to current sort options
200+
card.selectFileByIndex(filecnt); // Select the last file (without sort)
201201
card.openAndPrintFile(card.filename); // Start printing it
202202
} break;
203203
case PF_PAUSE: { // Pause printing (not currently firing)

β€ŽMarlin/src/lcd/e3v2/creality/dwin.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void Scroll_Menu(const uint8_t dir) {
411411
}
412412

413413
inline uint16_t nr_sd_menu_items() {
414-
return card.get_num_Files() + !card.flag.workDirIsRoot;
414+
return card.get_num_items() + !card.flag.workDirIsRoot;
415415
}
416416

417417
void Erase_Menu_Text(const uint8_t line) {
@@ -1830,9 +1830,9 @@ void MarlinUI::refresh() { /* Nothing to see here */ }
18301830
void Init_Shift_Name() {
18311831
const bool is_subdir = !card.flag.workDirIsRoot;
18321832
const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
1833-
const uint16_t fileCnt = card.get_num_Files();
1833+
const int16_t fileCnt = card.get_num_items();
18341834
if (WITHIN(filenum, 0, fileCnt - 1)) {
1835-
card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
1835+
card.selectFileByIndexSorted(filenum);
18361836
char * const name = card.longest_filename();
18371837
make_name_without_ext(shift_name, name, 100);
18381838
}
@@ -1857,7 +1857,7 @@ void Draw_SDItem(const uint16_t item, int16_t row=-1) {
18571857
return;
18581858
}
18591859

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

18631863
#if ENABLED(SCROLL_LONG_FILENAMES)
@@ -2223,7 +2223,7 @@ void HMI_SelectFile() {
22232223
}
22242224
else {
22252225
const uint16_t filenum = select_file.now - 1 - hasUpDir;
2226-
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
2226+
card.selectFileByIndexSorted(filenum);
22272227

22282228
// Enter that folder!
22292229
if (card.flag.filenameIsDir) {

β€ŽMarlin/src/lcd/e3v2/jyersui/dwin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ void CrealityDWINClass::Draw_SD_Item(const uint8_t item, const uint8_t row) {
808808
if (item == 0)
809809
Draw_Menu_Item(0, ICON_Back, card.flag.workDirIsRoot ? F("Back") : F(".."));
810810
else {
811-
card.getfilename_sorted(SD_ORDER(item - 1, card.get_num_Files()));
811+
card.selectFileByIndexSorted(item - 1);
812812
char * const filename = card.longest_filename();
813813
size_t max = MENU_CHAR_LIMIT;
814814
size_t pos = strlen(filename), len = pos;
@@ -4283,7 +4283,7 @@ void CrealityDWINClass::File_Control() {
42834283
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
42844284
if (encoder_diffState == ENCODER_DIFF_NO) {
42854285
if (selection > 0) {
4286-
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
4286+
card.selectFileByIndexSorted(selection - 1);
42874287
char * const filename = card.longest_filename();
42884288
size_t len = strlen(filename);
42894289
size_t pos = len;
@@ -4302,7 +4302,7 @@ void CrealityDWINClass::File_Control() {
43024302
}
43034303
return;
43044304
}
4305-
if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_Files()) {
4305+
if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_items()) {
43064306
DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
43074307
if (selection > 0) {
43084308
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
@@ -4342,7 +4342,7 @@ void CrealityDWINClass::File_Control() {
43424342
}
43434343
}
43444344
else {
4345-
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
4345+
card.selectFileByIndexSorted(selection - 1);
43464346
if (card.flag.filenameIsDir) {
43474347
card.cd(card.filename);
43484348
Draw_SD_List();

β€ŽMarlin/src/lcd/e3v2/proui/dwin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ void SetMediaAutoMount() {
873873
}
874874

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

879879
void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT) {
@@ -920,7 +920,7 @@ void onClickSDItem() {
920920
if (hasUpDir && CurrentMenu->selected == 1) return SDCard_Up();
921921
else {
922922
const uint16_t filenum = CurrentMenu->selected - 1 - hasUpDir;
923-
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
923+
card.selectFileByIndexSorted(filenum);
924924

925925
// Enter that folder!
926926
if (card.flag.filenameIsDir) return SDCard_Folder(card.filename);
@@ -963,7 +963,7 @@ void onClickSDItem() {
963963
last_itemselected = selected;
964964
if (selected >= 1 + hasUpDir) {
965965
const int8_t filenum = selected - 1 - hasUpDir; // Skip "Back" and ".."
966-
card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
966+
card.selectFileByIndexSorted(filenum);
967967
make_name_without_ext(shift_name, card.longest_filename(), LONG_FILENAME_LENGTH);
968968
shift_len = strlen(shift_name);
969969
shift_amt = 0;
@@ -991,7 +991,7 @@ void onDrawFileName(MenuItemClass* menuitem, int8_t line) {
991991
}
992992
else {
993993
uint8_t icon;
994-
card.getfilename_sorted(SD_ORDER(menuitem->pos - is_subdir - 1, card.get_num_Files()));
994+
card.selectFileByIndexSorted(menuitem->pos - is_subdir - 1);
995995
make_name_without_ext(shift_name, card.longest_filename());
996996
icon = card.flag.filenameIsDir ? ICON_Folder : card.fileIsBinary() ? ICON_Binary : ICON_File;
997997
Draw_Menu_Line(line, icon, shift_name);

β€ŽMarlin/src/lcd/extui/malyan/malyan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ void process_lcd_s_command(const char *command) {
325325
// select a file for printing during a print, there's
326326
// little reason not to do it this way.
327327
char message_buffer[MAX_CURLY_COMMAND];
328-
uint16_t file_count = card.get_num_Files();
329-
for (uint16_t i = 0; i < file_count; i++) {
328+
int16_t file_count = card.get_num_items();
329+
for (int16_t i = 0; i < file_count; i++) {
330330
card.selectFileByIndex(i);
331331
sprintf_P(message_buffer, card.flag.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.longest_filename());
332332
write_to_lcd(message_buffer);

β€ŽMarlin/src/lcd/extui/mks_ui/draw_print_file.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ uint8_t sel_id = 0;
7272
else
7373
card.cdroot();
7474

75-
const uint16_t fileCnt = card.get_num_Files();
75+
const int16_t fileCnt = card.get_num_items();
7676

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

8181
list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir;
8282
strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath);

β€ŽMarlin/src/lcd/extui/mks_ui/wifi_module.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,19 +817,26 @@ uint8_t Explore_Disk(char *path , uint8_t recu_level) {
817817

818818
if (!path) return 0;
819819

820-
const uint8_t fileCnt = card.get_num_Files();
820+
const int16_t fileCnt = card.get_num_items();
821821

822-
for (uint8_t i = 0; i < fileCnt; i++) {
823-
card.getfilename_sorted(SD_ORDER(i, fileCnt));
824-
ZERO(tmp);
825-
strcpy(tmp, card.filename);
822+
MediaFile file;
823+
MediaFile *diveDir;
824+
for (int16_t i = 0; i < fileCnt; i++) {
825+
card.selectFileByIndexSorted(i);
826826

827827
ZERO(Fstream);
828-
strcpy(Fstream, tmp);
828+
strcpy(Fstream, card.filename);
829829

830830
if (card.flag.filenameIsDir && recu_level <= 10)
831831
strcat_P(Fstream, PSTR(".DIR"));
832832

833+
strcat_P(Fstream, PSTR(" 0")); // report 0 file size
834+
835+
if (with_longnames) {
836+
strcat_P(Fstream, PSTR(" "));
837+
strcat_P(Fstream, card.longest_filename());
838+
}
839+
833840
strcat_P(Fstream, PSTR("\r\n"));
834841
send_to_wifi((uint8_t*)Fstream, strlen(Fstream));
835842
}

β€ŽMarlin/src/lcd/extui/ui_api.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,12 +1166,12 @@ namespace ExtUI {
11661166

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

1169-
void FileList::refresh() { num_files = 0xFFFF; }
1169+
void FileList::refresh() { }
11701170

11711171
bool FileList::seek(const uint16_t pos, const bool skip_range_check) {
11721172
#if HAS_MEDIA
11731173
if (!skip_range_check && (pos + 1) > count()) return false;
1174-
card.getfilename_sorted(SD_ORDER(pos, count()));
1174+
card.selectFileByIndexSorted(pos);
11751175
return card.filename[0] != '\0';
11761176
#else
11771177
UNUSED(pos);
@@ -1197,27 +1197,19 @@ namespace ExtUI {
11971197
}
11981198

11991199
uint16_t FileList::count() {
1200-
return TERN0(HAS_MEDIA, (num_files = (num_files == 0xFFFF ? card.get_num_Files() : num_files)));
1200+
return TERN0(HAS_MEDIA, card.get_num_items());
12011201
}
12021202

12031203
bool FileList::isAtRootDir() {
12041204
return TERN1(HAS_MEDIA, card.flag.workDirIsRoot);
12051205
}
12061206

12071207
void FileList::upDir() {
1208-
#if HAS_MEDIA
1209-
card.cdup();
1210-
num_files = 0xFFFF;
1211-
#endif
1208+
TERN_(HAS_MEDIA, card.cdup());
12121209
}
12131210

12141211
void FileList::changeDir(const char * const dirname) {
1215-
#if HAS_MEDIA
1216-
card.cd(dirname);
1217-
num_files = 0xFFFF;
1218-
#else
1219-
UNUSED(dirname);
1220-
#endif
1212+
TERN(HAS_MEDIA, card.cd(dirname), UNUSED(dirname));
12211213
}
12221214

12231215
} // namespace ExtUI

β€ŽMarlin/src/lcd/extui/ui_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,6 @@ namespace ExtUI {
434434
void resumePrint();
435435

436436
class FileList {
437-
private:
438-
uint16_t num_files;
439-
440437
public:
441438
FileList();
442439
void refresh();

β€ŽMarlin/src/lcd/menu/menu_media.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ void menu_media_filelist() {
109109
ui.encoder_direction_menus();
110110

111111
#if HAS_MARLINUI_U8GLIB
112-
static uint16_t fileCnt;
113-
if (ui.first_page) fileCnt = card.get_num_Files();
112+
static int16_t fileCnt;
113+
if (ui.first_page) fileCnt = card.get_num_items();
114114
#else
115-
const uint16_t fileCnt = card.get_num_Files();
115+
const int16_t fileCnt = card.get_num_items();
116116
#endif
117117

118118
START_MENU();
@@ -129,16 +129,18 @@ void menu_media_filelist() {
129129
else if (card.isMounted())
130130
ACTION_ITEM_F(F(LCD_STR_FOLDER " .."), lcd_sd_updir);
131131

132-
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {
133-
if (_menuLineNr == _thisItemNr) {
134-
card.getfilename_sorted(SD_ORDER(i, fileCnt));
135-
if (card.flag.filenameIsDir)
136-
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
137-
else
138-
MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
132+
if (ui.should_draw()) {
133+
for (int16_t i = 0; i < fileCnt; i++) {
134+
if (_menuLineNr != _thisItemNr)
135+
SKIP_ITEM();
136+
else {
137+
card.selectFileByIndexSorted(i);
138+
if (card.flag.filenameIsDir)
139+
MENU_ITEM(sdfolder, MSG_MEDIA_MENU, card);
140+
else
141+
MENU_ITEM(sdfile, MSG_MEDIA_MENU, card);
142+
}
139143
}
140-
else
141-
SKIP_ITEM();
142144
}
143145
END_MENU();
144146
}

0 commit comments

Comments
Β (0)