0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-01-19 16:16:13 +00:00

🧑‍💻 General 'MediaFile' type alias (#24424)

This commit is contained in:
Victor Oliveira 2023-02-04 05:10:26 -03:00 committed by GitHub
parent 08d9cbb930
commit 218ca05304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 135 additions and 55 deletions

View file

@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
if (!card.isMounted()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); MediaFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
return true; return true;
@ -63,7 +63,7 @@ bool PersistentStore::access_start() {
bool PersistentStore::access_finish() { bool PersistentStore::access_finish() {
if (!card.isMounted()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); MediaFile file, root = card.getroot();
int bytes_written = 0; int bytes_written = 0;
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);

View file

@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
if (!card.isMounted()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); MediaFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
return true; // false aborts the save return true; // false aborts the save
@ -62,7 +62,7 @@ bool PersistentStore::access_start() {
bool PersistentStore::access_finish() { bool PersistentStore::access_finish() {
if (!card.isMounted()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); MediaFile file, root = card.getroot();
int bytes_written = 0; int bytes_written = 0;
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);

View file

@ -33,7 +33,7 @@
bool PrintJobRecovery::enabled; // Initialized by settings.load() bool PrintJobRecovery::enabled; // Initialized by settings.load()
SdFile PrintJobRecovery::file; MediaFile PrintJobRecovery::file;
job_recovery_info_t PrintJobRecovery::info; job_recovery_info_t PrintJobRecovery::info;
const char PrintJobRecovery::filename[5] = "/PLR"; const char PrintJobRecovery::filename[5] = "/PLR";
uint8_t PrintJobRecovery::queue_index_r; uint8_t PrintJobRecovery::queue_index_r;

View file

@ -138,7 +138,7 @@ class PrintJobRecovery {
public: public:
static const char filename[5]; static const char filename[5];
static SdFile file; static MediaFile file;
static job_recovery_info_t info; static job_recovery_info_t info;
static uint8_t queue_index_r; //!< Queue index of the active command static uint8_t queue_index_r; //!< Queue index of the active command

View file

@ -4663,7 +4663,7 @@ void CrealityDWINClass::Start_Print(bool sd) {
if (sd) { if (sd) {
#if ENABLED(POWER_LOSS_RECOVERY) #if ENABLED(POWER_LOSS_RECOVERY)
if (recovery.valid()) { if (recovery.valid()) {
SdFile *diveDir = nullptr; MediaFile *diveDir = nullptr;
const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename); const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename);
card.selectFileByName(fname); card.selectFileByName(fname);
} }

View file

@ -1347,7 +1347,7 @@ void EachMomentUpdate() {
DWINUI::Draw_Button(BTN_Cancel, 26, 280); DWINUI::Draw_Button(BTN_Cancel, 26, 280);
DWINUI::Draw_Button(BTN_Continue, 146, 280); DWINUI::Draw_Button(BTN_Continue, 146, 280);
} }
SdFile *dir = nullptr; MediaFile *dir = nullptr;
const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename); const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename);
card.selectFileByName(filename); card.selectFileByName(filename);
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 207, card.longest_filename()); DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 207, card.longest_filename());

View file

@ -32,7 +32,7 @@
class MediaFileReader { class MediaFileReader {
private: private:
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
SdFile root, file; MediaFile root, file;
#endif #endif
public: public:

View file

@ -90,7 +90,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
char *cur_name; char *cur_name;
cur_name = strrchr(list_file.file_name[sel_id], '/'); cur_name = strrchr(list_file.file_name[sel_id], '/');
SdFile file, *curDir; MediaFile file, *curDir;
card.abortFilePrintNow(); card.abortFilePrintNow();
const char * const fname = card.diveToFile(false, curDir, cur_name); const char * const fname = card.diveToFile(false, curDir, cur_name);
if (!fname) return; if (!fname) return;

View file

@ -647,8 +647,8 @@ char *creat_title_text() {
char *cur_name = strrchr(list_file.file_name[sel_id], '/'); char *cur_name = strrchr(list_file.file_name[sel_id], '/');
SdFile file; MediaFile file;
SdFile *curDir; MediaFile *curDir;
const char * const fname = card.diveToFile(false, curDir, cur_name); const char * const fname = card.diveToFile(false, curDir, cur_name);
if (!fname) return; if (!fname) return;
if (file.open(curDir, fname, O_READ)) { if (file.open(curDir, fname, O_READ)) {

View file

@ -727,7 +727,7 @@ void disp_assets_update_progress(FSTR_P const fmsg) {
uint8_t mks_test_flag = 0; uint8_t mks_test_flag = 0;
const char *MKSTestPath = "MKS_TEST"; const char *MKSTestPath = "MKS_TEST";
void mks_test_get() { void mks_test_get() {
SdFile dir, root = card.getroot(); MediaFile dir, root = card.getroot();
if (dir.open(&root, MKSTestPath, O_RDONLY)) if (dir.open(&root, MKSTestPath, O_RDONLY))
mks_test_flag = 0x1E; mks_test_flag = 0x1E;
} }

View file

@ -403,8 +403,8 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
#define ASSET_TYPE_TITLE_LOGO 2 #define ASSET_TYPE_TITLE_LOGO 2
#define ASSET_TYPE_G_PREVIEW 3 #define ASSET_TYPE_G_PREVIEW 3
#define ASSET_TYPE_FONT 4 #define ASSET_TYPE_FONT 4
static void loadAsset(SdFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) { static void loadAsset(MediaFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) {
SdFile file; MediaFile file;
char dosFilename[FILENAME_LENGTH]; char dosFilename[FILENAME_LENGTH];
createFilename(dosFilename, entry); createFilename(dosFilename, entry);
if (!file.open(&dir, dosFilename, O_READ)) { if (!file.open(&dir, dosFilename, O_READ)) {
@ -488,7 +488,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
void UpdateAssets() { void UpdateAssets() {
if (!card.isMounted()) return; if (!card.isMounted()) return;
SdFile dir, root = card.getroot(); MediaFile dir, root = card.getroot();
if (dir.open(&root, assetsPath, O_RDONLY)) { if (dir.open(&root, assetsPath, O_RDONLY)) {
disp_assets_update(); disp_assets_update();

View file

@ -736,7 +736,7 @@ int32_t lastFragment = 0;
char saveFilePath[50]; char saveFilePath[50];
static SdFile upload_file, *upload_curDir; static MediaFile upload_file, *upload_curDir;
static filepos_t pos; static filepos_t pos;
int write_to_file(char *buf, int len) { int write_to_file(char *buf, int len) {
@ -974,8 +974,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
if (!gcode_preview_over) { if (!gcode_preview_over) {
char *cur_name = strrchr(list_file.file_name[sel_id], '/'); char *cur_name = strrchr(list_file.file_name[sel_id], '/');
SdFile file; MediaFile file;
SdFile *curDir; MediaFile *curDir;
card.abortFilePrintNow(); card.abortFilePrintNow();
const char * const fname = card.diveToFile(false, curDir, cur_name); const char * const fname = card.diveToFile(false, curDir, cur_name);
if (!fname) return; if (!fname) return;
@ -1595,7 +1595,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
} }
} }
upload_file.close(); upload_file.close();
SdFile file, *curDir; MediaFile file, *curDir;
const char * const fname = card.diveToFile(false, curDir, saveFilePath); const char * const fname = card.diveToFile(false, curDir, saveFilePath);
if (file.open(curDir, fname, O_RDWR)) { if (file.open(curDir, fname, O_RDWR)) {
gCfgItems.curFilesize = file.fileSize(); gCfgItems.curFilesize = file.fileSize();
@ -1969,7 +1969,7 @@ void mks_wifi_firmware_update() {
if (wifi_upload(0) >= 0) { if (wifi_upload(0) >= 0) {
card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME); card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
SdFile file, *curDir; MediaFile file, *curDir;
const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE); const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE);
if (file.open(curDir, fname, O_READ)) { if (file.open(curDir, fname, O_READ)) {
file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME); file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME);

View file

@ -86,7 +86,7 @@ static const uint32_t defaultTimeout = 500;
static const uint32_t eraseTimeout = 15000; static const uint32_t eraseTimeout = 15000;
static const uint32_t blockWriteTimeout = 200; static const uint32_t blockWriteTimeout = 200;
static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short
static SdFile update_file, *update_curDir; static MediaFile update_file, *update_curDir;
// Messages corresponding to result codes, should make sense when followed by " error" // Messages corresponding to result codes, should make sense when followed by " error"
const char *resultMessages[] = { const char *resultMessages[] = {

View file

@ -53,3 +53,5 @@ class SdFile : public SdBaseFile {
void write_P(PGM_P str); void write_P(PGM_P str);
void writeln_P(PGM_P str); void writeln_P(PGM_P str);
}; };
using MediaFile = SdFile;

View file

@ -199,3 +199,5 @@ class SdVolume {
bool readBlock(uint32_t block, uint8_t *dst) { return sdCard_->readBlock(block, dst); } bool readBlock(uint32_t block, uint8_t *dst) { return sdCard_->readBlock(block, dst); }
bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); } bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); }
}; };
using MarlinVolume = SdVolume;

View file

@ -79,7 +79,7 @@ IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0
// private: // private:
SdFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH]; MediaFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH];
uint8_t CardReader::workDirDepth; uint8_t CardReader::workDirDepth;
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
@ -133,8 +133,8 @@ uint8_t CardReader::workDirDepth;
#endif #endif
DiskIODriver* CardReader::driver = nullptr; DiskIODriver* CardReader::driver = nullptr;
SdVolume CardReader::volume; MarlinVolume CardReader::volume;
SdFile CardReader::file; MediaFile CardReader::file;
#if HAS_MEDIA_SUBCALLS #if HAS_MEDIA_SUBCALLS
uint8_t CardReader::file_subcall_ctr; uint8_t CardReader::file_subcall_ctr;
@ -228,7 +228,7 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD,
// //
// Get the number of (compliant) items in the folder // Get the number of (compliant) items in the folder
// //
int CardReader::countItems(SdFile dir) { int CardReader::countItems(MediaFile dir) {
dir_t p; dir_t p;
int c = 0; int c = 0;
while (dir.readDir(&p, longFilename) > 0) while (dir.readDir(&p, longFilename) > 0)
@ -244,7 +244,7 @@ int CardReader::countItems(SdFile dir) {
// //
// Get file/folder info for an item by index // Get file/folder info for an item by index
// //
void CardReader::selectByIndex(SdFile dir, const uint8_t index) { void CardReader::selectByIndex(MediaFile dir, const uint8_t index) {
dir_t p; dir_t p;
for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0;) { for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0;) {
if (is_visible_entity(p)) { if (is_visible_entity(p)) {
@ -260,7 +260,7 @@ void CardReader::selectByIndex(SdFile dir, const uint8_t index) {
// //
// Get file/folder info for an item by name // Get file/folder info for an item by name
// //
void CardReader::selectByName(SdFile dir, const char * const match) { void CardReader::selectByName(MediaFile dir, const char * const match) {
dir_t p; dir_t p;
for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0; cnt++) { for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0; cnt++) {
if (is_visible_entity(p)) { if (is_visible_entity(p)) {
@ -280,7 +280,7 @@ void CardReader::selectByName(SdFile dir, const char * const match) {
* this can blow up the stack, so a 'depth' parameter would be a * this can blow up the stack, so a 'depth' parameter would be a
* good addition. * good addition.
*/ */
void CardReader::printListing(SdFile parent, const char * const prepend, const uint8_t lsflags void CardReader::printListing(MediaFile parent, const char * const prepend, const uint8_t lsflags
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/)
) { ) {
const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP)); 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
// Get a new directory object using the full path // Get a new directory object using the full path
// and dive recursively into it. // and dive recursively into it.
SdFile child; // child.close() in destructor MediaFile child; // child.close() in destructor
if (child.open(&parent, dosFilename, O_READ)) { if (child.open(&parent, dosFilename, O_READ)) {
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
if (includeLong) { if (includeLong) {
@ -375,7 +375,7 @@ void CardReader::ls(const uint8_t lsflags) {
// Zero out slashes to make segments // Zero out slashes to make segments
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
SdFile diveDir = root; // start from the root for segment 1 MediaFile diveDir = root; // start from the root for segment 1
for (i = 0; i < pathLen;) { for (i = 0; i < pathLen;) {
if (path[i] == '\0') i++; // move past a single nul if (path[i] == '\0') i++; // move past a single nul
@ -404,7 +404,7 @@ void CardReader::ls(const uint8_t lsflags) {
// SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment); // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
// Open the sub-item as the new dive parent // Open the sub-item as the new dive parent
SdFile dir; MediaFile dir;
if (!dir.open(&diveDir, segment, O_READ)) { if (!dir.open(&diveDir, segment, O_READ)) {
SERIAL_EOL(); SERIAL_EOL();
SERIAL_ECHO_START(); SERIAL_ECHO_START();
@ -604,7 +604,7 @@ void CardReader::getAbsFilenameInCWD(char *dst) {
*dst++ = '/'; *dst++ = '/';
uint8_t cnt = 1; uint8_t cnt = 1;
auto appendAtom = [&](SdFile &file) { auto appendAtom = [&](MediaFile &file) {
file.getDosName(dst); file.getDosName(dst);
while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; } while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; }
if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; } if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; }
@ -683,7 +683,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ
abortFilePrintNow(); abortFilePrintNow();
SdFile *diveDir; MediaFile *diveDir;
const char * const fname = diveToFile(true, diveDir, path); const char * const fname = diveToFile(true, diveDir, path);
if (!fname) return openFailed(path); if (!fname) return openFailed(path);
@ -719,7 +719,7 @@ void CardReader::openFileWrite(const char * const path) {
abortFilePrintNow(); abortFilePrintNow();
SdFile *diveDir; MediaFile *diveDir;
const char * const fname = diveToFile(false, diveDir, path); const char * const fname = diveToFile(false, diveDir, path);
if (!fname) return openFailed(path); if (!fname) return openFailed(path);
@ -747,7 +747,7 @@ bool CardReader::fileExists(const char * const path) {
DEBUG_ECHOLNPGM("fileExists: ", path); DEBUG_ECHOLNPGM("fileExists: ", path);
// Dive to the file's directory and get the base name // Dive to the file's directory and get the base name
SdFile *diveDir = nullptr; MediaFile *diveDir = nullptr;
const char * const fname = diveToFile(false, diveDir, path); const char * const fname = diveToFile(false, diveDir, path);
if (!fname) return false; if (!fname) return false;
@ -757,7 +757,7 @@ bool CardReader::fileExists(const char * const path) {
//diveDir->close(); //diveDir->close();
// Try to open the file and return the result // Try to open the file and return the result
SdFile tmpFile; MediaFile tmpFile;
const bool success = tmpFile.open(diveDir, fname, O_READ); const bool success = tmpFile.open(diveDir, fname, O_READ);
if (success) tmpFile.close(); if (success) tmpFile.close();
return success; return success;
@ -771,7 +771,7 @@ void CardReader::removeFile(const char * const name) {
//abortFilePrintNow(); //abortFilePrintNow();
SdFile *itsDirPtr; MediaFile *itsDirPtr;
const char * const fname = diveToFile(false, itsDirPtr, name); const char * const fname = diveToFile(false, itsDirPtr, name);
if (!fname) return; if (!fname) return;
@ -919,23 +919,23 @@ uint16_t CardReader::countFilesInWorkDir() {
* - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...) * - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...)
* *
* On exit: * On exit:
* - Your curDir pointer contains an SdFile reference to the file's directory. * - Your curDir pointer contains an MediaFile reference to the file's directory.
* - If update_cwd was 'true' the workDir now points to the file's directory. * - If update_cwd was 'true' the workDir now points to the file's directory.
* *
* Returns a pointer to the last segment (filename) of the given DOS 8.3 path. * Returns a pointer to the last segment (filename) of the given DOS 8.3 path.
* On exit, inDirPtr contains an SdFile reference to the file's directory. * On exit, inDirPtr contains an MediaFile reference to the file's directory.
* *
* A nullptr result indicates an unrecoverable error. * A nullptr result indicates an unrecoverable error.
* *
* NOTE: End the path with a slash to dive to a folder. In this case the * NOTE: End the path with a slash to dive to a folder. In this case the
* returned filename will be blank (points to the end of the path). * returned filename will be blank (points to the end of the path).
*/ */
const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, const char * const path, const bool echo/*=false*/) { const char* CardReader::diveToFile(const bool update_cwd, MediaFile* &inDirPtr, const char * const path, const bool echo/*=false*/) {
DEBUG_SECTION(est, "diveToFile", true); DEBUG_SECTION(est, "diveToFile", true);
// Track both parent and subfolder // Track both parent and subfolder
static SdFile newDir1, newDir2; static MediaFile newDir1, newDir2;
SdFile *sub = &newDir1, *startDirPtr; MediaFile *sub = &newDir1, *startDirPtr;
// Parsing the path string // Parsing the path string
const char *atom_ptr = path; const char *atom_ptr = path;
@ -1017,7 +1017,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, con
} }
void CardReader::cd(const char * relpath) { void CardReader::cd(const char * relpath) {
SdFile newDir, *parent = &getWorkDir(); MediaFile newDir, *parent = &getWorkDir();
if (newDir.open(parent, relpath, O_READ)) { if (newDir.open(parent, relpath, O_READ)) {
workDir = newDir; workDir = newDir;

View file

@ -116,7 +116,7 @@ public:
static void changeMedia(DiskIODriver *_driver) { driver = _driver; } static void changeMedia(DiskIODriver *_driver) { driver = _driver; }
static SdFile getroot() { return root; } static MediaFile getroot() { return root; }
static void mount(); static void mount();
static void release(); static void release();
@ -190,12 +190,12 @@ public:
* Relative paths apply to the workDir. * Relative paths apply to the workDir.
* *
* update_cwd: Pass 'true' to update the workDir on success. * update_cwd: Pass 'true' to update the workDir on success.
* inDirPtr: On exit your pointer points to the target SdFile. * inDirPtr: On exit your pointer points to the target MediaFile.
* A nullptr indicates failure. * A nullptr indicates failure.
* path: Start with '/' for abs path. End with '/' to get a folder ref. * path: Start with '/' for abs path. End with '/' to get a folder ref.
* echo: Set 'true' to print the path throughout the loop. * echo: Set 'true' to print the path throughout the loop.
*/ */
static const char* diveToFile(const bool update_cwd, SdFile* &inDirPtr, const char * const path, const bool echo=false); static const char* diveToFile(const bool update_cwd, MediaFile* &inDirPtr, const char * const path, const bool echo=false);
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
static void presort(); static void presort();
@ -223,7 +223,7 @@ public:
// Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...) // Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...)
static char* getWorkDirName() { workDir.getDosName(filename); return filename; } static char* getWorkDirName() { workDir.getDosName(filename); return filename; }
static SdFile& getWorkDir() { return workDir.isOpen() ? workDir : root; } static MediaFile& getWorkDir() { return workDir.isOpen() ? workDir : root; }
// Print File stats // Print File stats
static uint32_t getFileSize() { return filesize; } static uint32_t getFileSize() { return filesize; }
@ -262,7 +262,7 @@ private:
// //
// Working directory and parents // Working directory and parents
// //
static SdFile root, workDir, workDirParents[MAX_DIR_DEPTH]; static MediaFile root, workDir, workDirParents[MAX_DIR_DEPTH];
static uint8_t workDirDepth; static uint8_t workDirDepth;
// //
@ -322,8 +322,8 @@ private:
#endif // SDCARD_SORT_ALPHA #endif // SDCARD_SORT_ALPHA
static DiskIODriver *driver; static DiskIODriver *driver;
static SdVolume volume; static MarlinVolume volume;
static SdFile file; static MediaFile file;
static uint32_t filesize, // Total size of the current file, in bytes static uint32_t filesize, // Total size of the current file, in bytes
sdpos; // Index most recently read (one behind file.getPos) sdpos; // Index most recently read (one behind file.getPos)
@ -341,10 +341,11 @@ private:
// Directory items // Directory items
// //
static bool is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false)); static bool is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false));
static int countItems(SdFile dir); static int countItems(MediaFile dir);
static void selectByIndex(SdFile dir, const uint8_t index); static void selectByIndex(MediaFile dir, const uint8_t index);
static void selectByName(SdFile dir, const char * const match); static void selectByName(MediaFile dir, const char * const match);
static void printListing(SdFile parent, const char * const prepend, const uint8_t lsflags static void printListing(
MediaFile parent, const char * const prepend, const uint8_t lsflags
OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr)
); );

View file

@ -22,6 +22,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "SdInfo.h"
/** /**
* DiskIO Interface * DiskIO Interface

74
Marlin/src/sd/storage.h Normal file
View file

@ -0,0 +1,74 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
* Marlin Storage Architecture:
*
* DiskIODriver:
* Do all low level IO with the underline hardware or block device: SPI, SDIO, OTG
*
* FilesystemDriver:
* Handle the filesystem format / implementation. Uses the io driver to read and write data.
* Sd2Card is the very first and current filesystem implementation on Marlin, supporting FAT.
* FatFS - Work in progress.
*
*
* Marlin Abstractions:
*
* Using this names allow us to isolate filesystem driver code, keeping all Marlin code agnostic.
*
* MediaFilesystem:
* Abstraction of systemwide filesystem operation.
*
* MarlinVolume:
* Abstraction of a filesystem volume.
*
* MediaFile:
* Abstraction of a generic file. Using this name allow us to isolate filesystem driver code,
* keeping all Marlin code agnostic.
*
* PrintFromStorage:
* Class to handle printing from any attached storage.
*
*/
/*
Interface definition. Doesn't need to be compiled, as we use duck typing,
allowing drivers to just use type alias.
Class MarlinVolume {
public:
};
Class MediaFile {
public:
};
Class MediaFilesystem {
public:
static void init();
static MarlinVolume* openVolume(const char *);
};
*/