Followup to SD menu optimization (#15252)

2.0.x
Tanguy Pruvot 5 years ago committed by Scott Lahteine
parent 61e3f119f4
commit 15bea5043c

@ -127,18 +127,21 @@ void menu_media() {
#if HAS_GRAPHICAL_LCD #if HAS_GRAPHICAL_LCD
static uint16_t fileCnt; static uint16_t fileCnt;
static bool at_root;
if (ui.first_page) { if (ui.first_page) {
fileCnt = card.get_num_Files(); fileCnt = card.get_num_Files();
card.getWorkDirName(); card.getWorkDirName();
at_root = card.filename[0] == '/';
} }
#else #else
const uint16_t fileCnt = card.get_num_Files(); const uint16_t fileCnt = card.get_num_Files();
card.getWorkDirName(); card.getWorkDirName();
const bool at_root = card.filename[0] == '/';
#endif #endif
START_MENU(); START_MENU();
MENU_BACK(MSG_MAIN); MENU_BACK(MSG_MAIN);
if (card.filename[0] == '/') { if (at_root) {
#if !PIN_EXISTS(SD_DETECT) #if !PIN_EXISTS(SD_DETECT)
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh); MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
#endif #endif

@ -273,7 +273,7 @@ int16_t SdBaseFile::fgets(char* str, int16_t num, char* delim) {
* *
* \return true for success, false for failure. * \return true for success, false for failure.
*/ */
bool SdBaseFile::getFilename(char * const name) { bool SdBaseFile::getDosName(char * const name) {
if (!isOpen()) return false; if (!isOpen()) return false;
if (isRoot()) { if (isRoot()) {
@ -957,7 +957,7 @@ void SdBaseFile::printFatTime(uint16_t fatTime) {
*/ */
bool SdBaseFile::printName() { bool SdBaseFile::printName() {
char name[FILENAME_LENGTH]; char name[FILENAME_LENGTH];
if (!getFilename(name)) return false; if (!getDosName(name)) return false;
SERIAL_ECHO(name); SERIAL_ECHO(name);
return true; return true;
} }

@ -286,7 +286,7 @@ class SdBaseFile {
*/ */
bool isRoot() const { return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32; } 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); void ls(uint8_t flags = 0, uint8_t indent = 0);
bool mkdir(SdBaseFile* dir, const char* path, bool pFlag = true); bool mkdir(SdBaseFile* dir, const char* path, bool pFlag = true);

@ -313,7 +313,7 @@ void CardReader::ls() {
void CardReader::printFilename() { void CardReader::printFilename() {
if (file.isOpen()) { if (file.isOpen()) {
char dosFilename[FILENAME_LENGTH]; char dosFilename[FILENAME_LENGTH];
file.getFilename(dosFilename); file.getDosName(dosFilename);
SERIAL_ECHO(dosFilename); SERIAL_ECHO(dosFilename);
#if ENABLED(LONG_FILENAME_HOST_SUPPORT) #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
getfilename(0, dosFilename); getfilename(0, dosFilename);
@ -404,7 +404,7 @@ void CardReader::openLogFile(char * const path) {
} }
void appendAtom(SdFile &file, char *& dst, uint8_t &cnt) { void appendAtom(SdFile &file, char *& dst, uint8_t &cnt) {
file.getFilename(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++; }
} }

@ -120,7 +120,7 @@ public:
static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); } static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
static inline uint32_t getIndex() { return sdpos; } static inline uint32_t getIndex() { return sdpos; }
static inline uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; } 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 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; } static inline int16_t write(void* buf, uint16_t nbyte) { return file.isOpen() ? file.write(buf, nbyte) : -1; }

Loading…
Cancel
Save