Skip to content

Commit 218ca05

Browse files
authored
πŸ§‘β€πŸ’» General 'MediaFile' type alias (MarlinFirmware#24424)
1 parent 08d9cbb commit 218ca05

19 files changed

+135
-55
lines changed

β€ŽMarlin/src/HAL/STM32/eeprom_sdcard.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
4848
bool PersistentStore::access_start() {
4949
if (!card.isMounted()) return false;
5050

51-
SdFile file, root = card.getroot();
51+
MediaFile file, root = card.getroot();
5252
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
5353
return true;
5454

@@ -63,7 +63,7 @@ bool PersistentStore::access_start() {
6363
bool PersistentStore::access_finish() {
6464
if (!card.isMounted()) return false;
6565

66-
SdFile file, root = card.getroot();
66+
MediaFile file, root = card.getroot();
6767
int bytes_written = 0;
6868
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
6969
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);

β€ŽMarlin/src/HAL/STM32F1/eeprom_sdcard.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
4747
bool PersistentStore::access_start() {
4848
if (!card.isMounted()) return false;
4949

50-
SdFile file, root = card.getroot();
50+
MediaFile file, root = card.getroot();
5151
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
5252
return true; // false aborts the save
5353

@@ -62,7 +62,7 @@ bool PersistentStore::access_start() {
6262
bool PersistentStore::access_finish() {
6363
if (!card.isMounted()) return false;
6464

65-
SdFile file, root = card.getroot();
65+
MediaFile file, root = card.getroot();
6666
int bytes_written = 0;
6767
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
6868
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
bool PrintJobRecovery::enabled; // Initialized by settings.load()
3535

36-
SdFile PrintJobRecovery::file;
36+
MediaFile PrintJobRecovery::file;
3737
job_recovery_info_t PrintJobRecovery::info;
3838
const char PrintJobRecovery::filename[5] = "/PLR";
3939
uint8_t PrintJobRecovery::queue_index_r;

β€ŽMarlin/src/feature/powerloss.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class PrintJobRecovery {
138138
public:
139139
static const char filename[5];
140140

141-
static SdFile file;
141+
static MediaFile file;
142142
static job_recovery_info_t info;
143143

144144
static uint8_t queue_index_r; //!< Queue index of the active command

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4663,7 +4663,7 @@ void CrealityDWINClass::Start_Print(bool sd) {
46634663
if (sd) {
46644664
#if ENABLED(POWER_LOSS_RECOVERY)
46654665
if (recovery.valid()) {
4666-
SdFile *diveDir = nullptr;
4666+
MediaFile *diveDir = nullptr;
46674667
const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename);
46684668
card.selectFileByName(fname);
46694669
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ void EachMomentUpdate() {
13471347
DWINUI::Draw_Button(BTN_Cancel, 26, 280);
13481348
DWINUI::Draw_Button(BTN_Continue, 146, 280);
13491349
}
1350-
SdFile *dir = nullptr;
1350+
MediaFile *dir = nullptr;
13511351
const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename);
13521352
card.selectFileByName(filename);
13531353
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 207, card.longest_filename());

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class MediaFileReader {
3333
private:
3434
#if ENABLED(SDSUPPORT)
35-
SdFile root, file;
35+
MediaFile root, file;
3636
#endif
3737

3838
public:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
9090
char *cur_name;
9191
cur_name = strrchr(list_file.file_name[sel_id], '/');
9292

93-
SdFile file, *curDir;
93+
MediaFile file, *curDir;
9494
card.abortFilePrintNow();
9595
const char * const fname = card.diveToFile(false, curDir, cur_name);
9696
if (!fname) return;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ char *creat_title_text() {
647647

648648
char *cur_name = strrchr(list_file.file_name[sel_id], '/');
649649

650-
SdFile file;
651-
SdFile *curDir;
650+
MediaFile file;
651+
MediaFile *curDir;
652652
const char * const fname = card.diveToFile(false, curDir, cur_name);
653653
if (!fname) return;
654654
if (file.open(curDir, fname, O_READ)) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ void disp_assets_update_progress(FSTR_P const fmsg) {
727727
uint8_t mks_test_flag = 0;
728728
const char *MKSTestPath = "MKS_TEST";
729729
void mks_test_get() {
730-
SdFile dir, root = card.getroot();
730+
MediaFile dir, root = card.getroot();
731731
if (dir.open(&root, MKSTestPath, O_RDONLY))
732732
mks_test_flag = 0x1E;
733733
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
403403
#define ASSET_TYPE_TITLE_LOGO 2
404404
#define ASSET_TYPE_G_PREVIEW 3
405405
#define ASSET_TYPE_FONT 4
406-
static void loadAsset(SdFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) {
407-
SdFile file;
406+
static void loadAsset(MediaFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) {
407+
MediaFile file;
408408
char dosFilename[FILENAME_LENGTH];
409409
createFilename(dosFilename, entry);
410410
if (!file.open(&dir, dosFilename, O_READ)) {
@@ -488,7 +488,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
488488

489489
void UpdateAssets() {
490490
if (!card.isMounted()) return;
491-
SdFile dir, root = card.getroot();
491+
MediaFile dir, root = card.getroot();
492492
if (dir.open(&root, assetsPath, O_RDONLY)) {
493493

494494
disp_assets_update();

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ int32_t lastFragment = 0;
736736

737737
char saveFilePath[50];
738738

739-
static SdFile upload_file, *upload_curDir;
739+
static MediaFile upload_file, *upload_curDir;
740740
static filepos_t pos;
741741

742742
int write_to_file(char *buf, int len) {
@@ -974,8 +974,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
974974
if (!gcode_preview_over) {
975975
char *cur_name = strrchr(list_file.file_name[sel_id], '/');
976976

977-
SdFile file;
978-
SdFile *curDir;
977+
MediaFile file;
978+
MediaFile *curDir;
979979
card.abortFilePrintNow();
980980
const char * const fname = card.diveToFile(false, curDir, cur_name);
981981
if (!fname) return;
@@ -1595,7 +1595,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
15951595
}
15961596
}
15971597
upload_file.close();
1598-
SdFile file, *curDir;
1598+
MediaFile file, *curDir;
15991599
const char * const fname = card.diveToFile(false, curDir, saveFilePath);
16001600
if (file.open(curDir, fname, O_RDWR)) {
16011601
gCfgItems.curFilesize = file.fileSize();
@@ -1969,7 +1969,7 @@ void mks_wifi_firmware_update() {
19691969

19701970
if (wifi_upload(0) >= 0) {
19711971
card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
1972-
SdFile file, *curDir;
1972+
MediaFile file, *curDir;
19731973
const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE);
19741974
if (file.open(curDir, fname, O_READ)) {
19751975
file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static const uint32_t defaultTimeout = 500;
8686
static const uint32_t eraseTimeout = 15000;
8787
static const uint32_t blockWriteTimeout = 200;
8888
static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short
89-
static SdFile update_file, *update_curDir;
89+
static MediaFile update_file, *update_curDir;
9090

9191
// Messages corresponding to result codes, should make sense when followed by " error"
9292
const char *resultMessages[] = {

β€ŽMarlin/src/sd/SdFile.h

+2
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ class SdFile : public SdBaseFile {
5353
void write_P(PGM_P str);
5454
void writeln_P(PGM_P str);
5555
};
56+
57+
using MediaFile = SdFile;

β€ŽMarlin/src/sd/SdVolume.h

+2
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ class SdVolume {
199199
bool readBlock(uint32_t block, uint8_t *dst) { return sdCard_->readBlock(block, dst); }
200200
bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); }
201201
};
202+
203+
using MarlinVolume = SdVolume;

β€ŽMarlin/src/sd/cardreader.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0
7979

8080
// private:
8181

82-
SdFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH];
82+
MediaFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH];
8383
uint8_t CardReader::workDirDepth;
8484

8585
#if ENABLED(SDCARD_SORT_ALPHA)
@@ -133,8 +133,8 @@ uint8_t CardReader::workDirDepth;
133133
#endif
134134

135135
DiskIODriver* CardReader::driver = nullptr;
136-
SdVolume CardReader::volume;
137-
SdFile CardReader::file;
136+
MarlinVolume CardReader::volume;
137+
MediaFile CardReader::file;
138138

139139
#if HAS_MEDIA_SUBCALLS
140140
uint8_t CardReader::file_subcall_ctr;
@@ -228,7 +228,7 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD,
228228
//
229229
// Get the number of (compliant) items in the folder
230230
//
231-
int CardReader::countItems(SdFile dir) {
231+
int CardReader::countItems(MediaFile dir) {
232232
dir_t p;
233233
int c = 0;
234234
while (dir.readDir(&p, longFilename) > 0)
@@ -244,7 +244,7 @@ int CardReader::countItems(SdFile dir) {
244244
//
245245
// Get file/folder info for an item by index
246246
//
247-
void CardReader::selectByIndex(SdFile dir, const uint8_t index) {
247+
void CardReader::selectByIndex(MediaFile dir, const uint8_t index) {
248248
dir_t p;
249249
for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0;) {
250250
if (is_visible_entity(p)) {
@@ -260,7 +260,7 @@ void CardReader::selectByIndex(SdFile dir, const uint8_t index) {
260260
//
261261
// Get file/folder info for an item by name
262262
//
263-
void CardReader::selectByName(SdFile dir, const char * const match) {
263+
void CardReader::selectByName(MediaFile dir, const char * const match) {
264264
dir_t p;
265265
for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0; cnt++) {
266266
if (is_visible_entity(p)) {
@@ -280,7 +280,7 @@ void CardReader::selectByName(SdFile dir, const char * const match) {
280280
* this can blow up the stack, so a 'depth' parameter would be a
281281
* good addition.
282282
*/
283-
void CardReader::printListing(SdFile parent, const char * const prepend, const uint8_t lsflags
283+
void CardReader::printListing(MediaFile parent, const char * const prepend, const uint8_t lsflags
284284
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/)
285285
) {
286286
const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP));
@@ -304,7 +304,7 @@ void CardReader::printListing(SdFile parent, const char * const prepend, const
304304

305305
// Get a new directory object using the full path
306306
// and dive recursively into it.
307-
SdFile child; // child.close() in destructor
307+
MediaFile child; // child.close() in destructor
308308
if (child.open(&parent, dosFilename, O_READ)) {
309309
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
310310
if (includeLong) {
@@ -375,7 +375,7 @@ void CardReader::ls(const uint8_t lsflags) {
375375
// Zero out slashes to make segments
376376
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
377377

378-
SdFile diveDir = root; // start from the root for segment 1
378+
MediaFile diveDir = root; // start from the root for segment 1
379379
for (i = 0; i < pathLen;) {
380380

381381
if (path[i] == '\0') i++; // move past a single nul
@@ -404,7 +404,7 @@ void CardReader::ls(const uint8_t lsflags) {
404404
// SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
405405

406406
// Open the sub-item as the new dive parent
407-
SdFile dir;
407+
MediaFile dir;
408408
if (!dir.open(&diveDir, segment, O_READ)) {
409409
SERIAL_EOL();
410410
SERIAL_ECHO_START();
@@ -604,7 +604,7 @@ void CardReader::getAbsFilenameInCWD(char *dst) {
604604
*dst++ = '/';
605605
uint8_t cnt = 1;
606606

607-
auto appendAtom = [&](SdFile &file) {
607+
auto appendAtom = [&](MediaFile &file) {
608608
file.getDosName(dst);
609609
while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; }
610610
if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; }
@@ -683,7 +683,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
683683

684684
abortFilePrintNow();
685685

686-
SdFile *diveDir;
686+
MediaFile *diveDir;
687687
const char * const fname = diveToFile(true, diveDir, path);
688688
if (!fname) return openFailed(path);
689689

@@ -719,7 +719,7 @@ void CardReader::openFileWrite(const char * const path) {
719719

720720
abortFilePrintNow();
721721

722-
SdFile *diveDir;
722+
MediaFile *diveDir;
723723
const char * const fname = diveToFile(false, diveDir, path);
724724
if (!fname) return openFailed(path);
725725

@@ -747,7 +747,7 @@ bool CardReader::fileExists(const char * const path) {
747747
DEBUG_ECHOLNPGM("fileExists: ", path);
748748

749749
// Dive to the file's directory and get the base name
750-
SdFile *diveDir = nullptr;
750+
MediaFile *diveDir = nullptr;
751751
const char * const fname = diveToFile(false, diveDir, path);
752752
if (!fname) return false;
753753

@@ -757,7 +757,7 @@ bool CardReader::fileExists(const char * const path) {
757757
//diveDir->close();
758758

759759
// Try to open the file and return the result
760-
SdFile tmpFile;
760+
MediaFile tmpFile;
761761
const bool success = tmpFile.open(diveDir, fname, O_READ);
762762
if (success) tmpFile.close();
763763
return success;
@@ -771,7 +771,7 @@ void CardReader::removeFile(const char * const name) {
771771

772772
//abortFilePrintNow();
773773

774-
SdFile *itsDirPtr;
774+
MediaFile *itsDirPtr;
775775
const char * const fname = diveToFile(false, itsDirPtr, name);
776776
if (!fname) return;
777777

@@ -919,23 +919,23 @@ uint16_t CardReader::countFilesInWorkDir() {
919919
* - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...)
920920
*
921921
* On exit:
922-
* - Your curDir pointer contains an SdFile reference to the file's directory.
922+
* - Your curDir pointer contains an MediaFile reference to the file's directory.
923923
* - If update_cwd was 'true' the workDir now points to the file's directory.
924924
*
925925
* Returns a pointer to the last segment (filename) of the given DOS 8.3 path.
926-
* On exit, inDirPtr contains an SdFile reference to the file's directory.
926+
* On exit, inDirPtr contains an MediaFile reference to the file's directory.
927927
*
928928
* A nullptr result indicates an unrecoverable error.
929929
*
930930
* NOTE: End the path with a slash to dive to a folder. In this case the
931931
* returned filename will be blank (points to the end of the path).
932932
*/
933-
const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, const char * const path, const bool echo/*=false*/) {
933+
const char* CardReader::diveToFile(const bool update_cwd, MediaFile* &inDirPtr, const char * const path, const bool echo/*=false*/) {
934934
DEBUG_SECTION(est, "diveToFile", true);
935935

936936
// Track both parent and subfolder
937-
static SdFile newDir1, newDir2;
938-
SdFile *sub = &newDir1, *startDirPtr;
937+
static MediaFile newDir1, newDir2;
938+
MediaFile *sub = &newDir1, *startDirPtr;
939939

940940
// Parsing the path string
941941
const char *atom_ptr = path;
@@ -1017,7 +1017,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, con
10171017
}
10181018

10191019
void CardReader::cd(const char * relpath) {
1020-
SdFile newDir, *parent = &getWorkDir();
1020+
MediaFile newDir, *parent = &getWorkDir();
10211021

10221022
if (newDir.open(parent, relpath, O_READ)) {
10231023
workDir = newDir;

0 commit comments

Comments
Β (0)