From f7cb9455c86cc6410964fe8237f295e7eabab707 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 4 Sep 2020 19:57:07 -0500 Subject: [PATCH] No 'ls' if media isn't mounted --- Marlin/src/core/language.h | 1 + Marlin/src/gcode/sd/M20.cpp | 10 +++++++--- Marlin/src/sd/cardreader.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index f0ddbdd6d..1d81ee61f 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -120,6 +120,7 @@ #define STR_ERR_CHECKSUM_MISMATCH "checksum mismatch, Last Line: " #define STR_ERR_NO_CHECKSUM "No Checksum with line number, Last Line: " #define STR_FILE_PRINTED "Done printing file" +#define STR_NO_MEDIA "No media" #define STR_BEGIN_FILE_LIST "Begin file list" #define STR_END_FILE_LIST "End file list" #define STR_INVALID_EXTRUDER "Invalid extruder" diff --git a/Marlin/src/gcode/sd/M20.cpp b/Marlin/src/gcode/sd/M20.cpp index 6d4c55752..7ac4affda 100644 --- a/Marlin/src/gcode/sd/M20.cpp +++ b/Marlin/src/gcode/sd/M20.cpp @@ -31,9 +31,13 @@ * M20: List SD card to serial output */ void GcodeSuite::M20() { - SERIAL_ECHOLNPGM(STR_BEGIN_FILE_LIST); - card.ls(); - SERIAL_ECHOLNPGM(STR_END_FILE_LIST); + if (card.flag.mounted) { + SERIAL_ECHOLNPGM(STR_BEGIN_FILE_LIST); + card.ls(); + SERIAL_ECHOLNPGM(STR_END_FILE_LIST); + } + else + SERIAL_ECHO_MSG(STR_NO_MEDIA); } #endif // SDSUPPORT diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 59a5f1da8..3eacf8b69 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -276,8 +276,10 @@ void CardReader::printListing(SdFile parent, const char * const prepend/*=nullpt // List all files on the SD card // void CardReader::ls() { - root.rewind(); - printListing(root); + if (flag.mounted) { + root.rewind(); + printListing(root); + } } #if ENABLED(LONG_FILENAME_HOST_SUPPORT)