From 15bea5043c13c5958aac691e6e86e2489ca8aba4 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 14 Sep 2019 13:42:28 +0200 Subject: [PATCH] Followup to SD menu optimization (#15252) --- Marlin/src/lcd/menu/menu_media.cpp | 5 ++++- Marlin/src/sd/SdBaseFile.cpp | 4 ++-- Marlin/src/sd/SdBaseFile.h | 2 +- Marlin/src/sd/cardreader.cpp | 4 ++-- Marlin/src/sd/cardreader.h | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_media.cpp b/Marlin/src/lcd/menu/menu_media.cpp index b6704d4f6c..7625e37c2d 100644 --- a/Marlin/src/lcd/menu/menu_media.cpp +++ b/Marlin/src/lcd/menu/menu_media.cpp @@ -127,18 +127,21 @@ void menu_media() { #if HAS_GRAPHICAL_LCD static uint16_t fileCnt; + static bool at_root; if (ui.first_page) { fileCnt = card.get_num_Files(); card.getWorkDirName(); + at_root = card.filename[0] == '/'; } #else const uint16_t fileCnt = card.get_num_Files(); card.getWorkDirName(); + const bool at_root = card.filename[0] == '/'; #endif START_MENU(); MENU_BACK(MSG_MAIN); - if (card.filename[0] == '/') { + if (at_root) { #if !PIN_EXISTS(SD_DETECT) MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh); #endif diff --git a/Marlin/src/sd/SdBaseFile.cpp b/Marlin/src/sd/SdBaseFile.cpp index 08eb864095..2969208838 100644 --- a/Marlin/src/sd/SdBaseFile.cpp +++ b/Marlin/src/sd/SdBaseFile.cpp @@ -273,7 +273,7 @@ int16_t SdBaseFile::fgets(char* str, int16_t num, char* delim) { * * \return true for success, false for failure. */ -bool SdBaseFile::getFilename(char * const name) { +bool SdBaseFile::getDosName(char * const name) { if (!isOpen()) return false; if (isRoot()) { @@ -957,7 +957,7 @@ void SdBaseFile::printFatTime(uint16_t fatTime) { */ bool SdBaseFile::printName() { char name[FILENAME_LENGTH]; - if (!getFilename(name)) return false; + if (!getDosName(name)) return false; SERIAL_ECHO(name); return true; } diff --git a/Marlin/src/sd/SdBaseFile.h b/Marlin/src/sd/SdBaseFile.h index 494b4f6bee..4d4062b1cd 100644 --- a/Marlin/src/sd/SdBaseFile.h +++ b/Marlin/src/sd/SdBaseFile.h @@ -286,7 +286,7 @@ class SdBaseFile { */ bool isRoot() const { return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32; } - bool getFilename(char * const name); + bool getDosName(char * const name); void ls(uint8_t flags = 0, uint8_t indent = 0); bool mkdir(SdBaseFile* dir, const char* path, bool pFlag = true); diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 76fe43d09b..e692f84b9a 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -313,7 +313,7 @@ void CardReader::ls() { void CardReader::printFilename() { if (file.isOpen()) { char dosFilename[FILENAME_LENGTH]; - file.getFilename(dosFilename); + file.getDosName(dosFilename); SERIAL_ECHO(dosFilename); #if ENABLED(LONG_FILENAME_HOST_SUPPORT) getfilename(0, dosFilename); @@ -404,7 +404,7 @@ void CardReader::openLogFile(char * const path) { } void appendAtom(SdFile &file, char *& dst, uint8_t &cnt) { - file.getFilename(dst); + file.getDosName(dst); while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; } if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; } } diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 8eedfc384e..c78df1949c 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -120,7 +120,7 @@ public: static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); } static inline uint32_t getIndex() { return sdpos; } static inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; } - static inline char* getWorkDirName() { workDir.getFilename(filename); return filename; } + static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; } static inline int16_t read(void* buf, uint16_t nbyte) { return file.isOpen() ? file.read(buf, nbyte) : -1; } static inline int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }