From f81ca65a16838923f76db11a2c1845cdd5d14f74 Mon Sep 17 00:00:00 2001 From: Hannes Date: Thu, 14 Aug 2025 09:23:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Provide=20'M20=20F'=20(list=20bi?= =?UTF-8?q?nary=20files)=20as=20needed=20(#27977)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/src/sd/cardreader.cpp | 14 +++++++------- Marlin/src/sd/cardreader.h | 12 ++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index b7d6f70f65..83d0caea4f 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -209,11 +209,11 @@ inline bool extIsBIN(char *ext) { // // Return 'true' if the item is a folder, G-code file or Binary file // -bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin/*=false*/)) { +bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool binFiles/*=false*/)) { //uint8_t pn0 = p.name[0]; #if DISABLED(CUSTOM_FIRMWARE_UPLOAD) - constexpr bool onlyBin = false; + constexpr bool binFiles = false; #endif if ( (p.attributes & DIR_ATT_HIDDEN) // Hidden by attribute @@ -228,9 +228,9 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, return ( flag.filenameIsDir // All Directories are ok - || fileIsBinary() // BIN files are accepted - || (!onlyBin && p.name[8] == 'G' - && p.name[9] != '~') // Non-backup *.G* files are accepted + || ( binFiles && fileIsBinary()) // BIN files are accepted + || (!binFiles && p.name[8] == 'G' + && p.name[9] != '~') // Non-backup *.G* files are accepted ); } @@ -292,7 +292,7 @@ void CardReader::printListing(MediaFile parent, const char * const prepend, cons const bool includeLong = TEST(lsflags, LS_LONG_FILENAME); #endif #if ENABLED(CUSTOM_FIRMWARE_UPLOAD) - const bool onlyBin = TEST(lsflags, LS_ONLY_BIN); + const bool binFiles = TEST(lsflags, LS_ONLY_BIN); #endif UNUSED(lsflags); dir_t p; @@ -328,7 +328,7 @@ void CardReader::printListing(MediaFile parent, const char * const prepend, cons return; } } - else if (is_visible_entity(p OPTARG(CUSTOM_FIRMWARE_UPLOAD, onlyBin))) { + else if (is_visible_entity(p OPTARG(CUSTOM_FIRMWARE_UPLOAD, binFiles))) { if (prepend) SERIAL_ECHO(prepend, C('/')); SERIAL_ECHO(createFilename(filename, p), C(' '), p.fileSize); if (includeTime) { diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 6c1f05b8af..19e08b5b4d 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -60,6 +60,10 @@ extern const char M23_STR[], M24_STR[]; #include "Sd2Card.h" #endif +#if ANY(DO_LIST_BIN_FILES, CUSTOM_FIRMWARE_UPLOAD) + #define MEDIA_SUPPORT_BIN_FILES 1 +#endif + typedef struct { bool saving:1, // Receiving a G-code file or logging commands during a print logging:1, // Log enqueued commands to the open file. See GCodeQueue::advance() @@ -69,7 +73,7 @@ typedef struct { filenameIsDir:1, // The working item is a directory workDirIsRoot:1, // The working directory is / so there's no parent abort_sd_printing:1 // Abort by calling abortSDPrinting() at the main loop() - #if DO_LIST_BIN_FILES + #if MEDIA_SUPPORT_BIN_FILES , filenameIsBin:1 // The working item is a BIN file #endif #if ENABLED(BINARY_FILE_TRANSFER) @@ -300,8 +304,8 @@ public: #endif // Binary flag for the current file - static bool fileIsBinary() { return TERN0(DO_LIST_BIN_FILES, flag.filenameIsBin); } - static void setBinFlag(const bool bin) { TERN(DO_LIST_BIN_FILES, flag.filenameIsBin = bin, UNUSED(bin)); } + static bool fileIsBinary() { return TERN0(MEDIA_SUPPORT_BIN_FILES, flag.filenameIsBin); } + static void setBinFlag(const bool bin) { TERN(MEDIA_SUPPORT_BIN_FILES, flag.filenameIsBin = bin, UNUSED(bin)); } // Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...) static char* getWorkDirName() { workDir.getDosName(filename); return filename; } @@ -412,7 +416,7 @@ private: // // 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 binFiles=false)); static int16_t countVisibleItems(MediaFile dir); static void selectByIndex(MediaFile dir, const int16_t index); static void selectByName(MediaFile dir, const char * const match);