Skip to content

Commit

Permalink
Followup to SD menu optimization (MarlinFirmware#15252)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot authored and thinkyhead committed Sep 14, 2019
1 parent 61e3f11 commit 15bea50
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/sd/SdBaseFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/sd/SdBaseFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++; }
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CardReader {
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; }

Expand Down

0 comments on commit 15bea50

Please sign in to comment.