Merge pull request #2987 from leptun/PFW-1144-LongPathName

"M20 L" support. Print long filenames
This commit is contained in:
DRracer 2021-01-26 08:40:26 +01:00 committed by GitHub
commit c465417f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View File

@ -5730,10 +5730,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
/*!
### M20 - SD Card file list <a href="https://reprap.org/wiki/G-code#M20:_List_SD_card">M20: List SD card</a>
#### Usage
M20 [ L ]
#### Parameters
- `L` - Reports ling filenames instead of just short filenames. Requires host software parsing.
*/
case 20:
KEEPALIVE_STATE(NOT_BUSY); // do not send busy messages during listing. Inhibits the output of manage_heater()
SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST
card.ls();
card.ls(code_seen('L'));
SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST
break;

View File

@ -62,9 +62,10 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
/**
+* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
+* LS_Count - Add +1 to nrFiles for every file within the parent
+* LS_GetFilename - Get the filename of the file indexed by nrFiles
+* LS_SerialPrint - Print the full path and size of each file to serial output
+* LS_Count - Add +1 to nrFiles for every file within the parent
+* LS_GetFilename - Get the filename of the file indexed by nrFiles
+* LS_SerialPrint - Print the full path and size of each file to serial output
+* LS_SerialPrint_LFN - Print the full path, long filename and size of each file to serial output
+*/
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
@ -90,9 +91,13 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
// Serial.print(path);
// Get a new directory object using the full path
// and dive recursively into it.
if (lsAction == LS_SerialPrint_LFN)
printf_P(PSTR("DIR_ENTER: %s \"%s\"\n"), path, longFilename[0] ? longFilename : lfilename);
SdFile dir;
if (!dir.open(parent, lfilename, O_READ)) {
if (lsAction == LS_SerialPrint) {
if (lsAction == LS_SerialPrint || lsAction == LS_SerialPrint_LFN) {
//SERIAL_ECHO_START();
//SERIAL_ECHOPGM(_i("Cannot open subdir"));////MSG_SD_CANT_OPEN_SUBDIR
//SERIAL_ECHOLN(lfilename);
@ -100,6 +105,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
}
lsDive(path, dir);
// close() is done automatically by destructor of SdFile
if (lsAction == LS_SerialPrint_LFN)
puts_P(PSTR("DIR_EXIT"));
}
else {
uint8_t pn0 = p.name[0];
@ -114,12 +122,18 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
nrFiles++;
break;
case LS_SerialPrint_LFN:
case LS_SerialPrint:
createFilename(filename, p);
SERIAL_PROTOCOL(prepend);
SERIAL_PROTOCOL(filename);
MYSERIAL.write(' ');
if (lsAction == LS_SerialPrint_LFN)
printf_P(PSTR("\"%s\" "), LONGEST_FILENAME);
SERIAL_PROTOCOLLN(p.fileSize);
manage_heater();
break;
case LS_GetFilename:
@ -160,9 +174,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
} // while readDir
}
void CardReader::ls()
void CardReader::ls(bool printLFN)
{
lsAction=LS_SerialPrint;
lsAction = printLFN ? LS_SerialPrint_LFN : LS_SerialPrint;
//if(lsAction==LS_Count)
//nrFiles=0;

View File

@ -6,7 +6,7 @@
#define MAX_DIR_DEPTH 10
#include "SdFile.h"
enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
enum LsAction {LS_SerialPrint,LS_SerialPrint_LFN,LS_Count,LS_GetFilename};
class CardReader
{
public:
@ -38,7 +38,7 @@ public:
uint16_t getWorkDirDepth();
void ls();
void ls(bool printLFN);
void chdir(const char * relpath);
void updir();
void setroot();