Save 16 bytes - pass ls_param by value to functions
... as ls_param is a 1-byte structure it is more conservative to pass it to functions by value than by a pointer
This commit is contained in:
parent
2129bcf315
commit
7011014abb
|
|
@ -5744,13 +5744,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
|
||||||
- `L` - Reports ling filenames instead of just short filenames. Requires host software parsing.
|
- `L` - Reports ling filenames instead of just short filenames. Requires host software parsing.
|
||||||
*/
|
*/
|
||||||
case 20:
|
case 20:
|
||||||
{
|
|
||||||
KEEPALIVE_STATE(NOT_BUSY); // do not send busy messages during listing. Inhibits the output of manage_heater()
|
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
|
SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST
|
||||||
struct CardReader::ls_param params = {.LFN = code_seen('L'), .timestamp = code_seen('T')};
|
card.ls(CardReader::ls_param(code_seen('L'), code_seen('T')));
|
||||||
card.ls(params);
|
|
||||||
SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST
|
SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
### M21 - Init SD card <a href="https://reprap.org/wiki/G-code#M21:_Initialize_SD_card">M21: Initialize SD card</a>
|
### M21 - Init SD card <a href="https://reprap.org/wiki/G-code#M21:_Initialize_SD_card">M21: Initialize SD card</a>
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
|
||||||
+* LS_SerialPrint - Print the full path and size of each file to serial output
|
+* LS_SerialPrint - Print the full path and size of each file to serial output
|
||||||
+*/
|
+*/
|
||||||
|
|
||||||
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/, LsAction lsAction, struct ls_param *lsParams) {
|
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/, LsAction lsAction, ls_param lsParams) {
|
||||||
static uint8_t recursionCnt = 0;
|
static uint8_t recursionCnt = 0;
|
||||||
// RAII incrementer for the recursionCnt
|
// RAII incrementer for the recursionCnt
|
||||||
class _incrementer
|
class _incrementer
|
||||||
|
|
@ -102,7 +102,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
// Get a new directory object using the full path
|
// Get a new directory object using the full path
|
||||||
// and dive recursively into it.
|
// and dive recursively into it.
|
||||||
|
|
||||||
if (lsParams->LFN)
|
if (lsParams.LFN)
|
||||||
printf_P(PSTR("DIR_ENTER: %s \"%s\"\n"), path, longFilename[0] ? longFilename : lfilename);
|
printf_P(PSTR("DIR_ENTER: %s \"%s\"\n"), path, longFilename[0] ? longFilename : lfilename);
|
||||||
|
|
||||||
SdFile dir;
|
SdFile dir;
|
||||||
|
|
@ -114,7 +114,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
lsDive(path, dir, NULL, lsAction, lsParams);
|
lsDive(path, dir, NULL, lsAction, lsParams);
|
||||||
// close() is done automatically by destructor of SdFile
|
// close() is done automatically by destructor of SdFile
|
||||||
|
|
||||||
if (lsParams->LFN)
|
if (lsParams.LFN)
|
||||||
puts_P(PSTR("DIR_EXIT"));
|
puts_P(PSTR("DIR_EXIT"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -133,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
MYSERIAL.write(' ');
|
MYSERIAL.write(' ');
|
||||||
SERIAL_PROTOCOL(p.fileSize);
|
SERIAL_PROTOCOL(p.fileSize);
|
||||||
|
|
||||||
if (lsParams->timestamp)
|
if (lsParams.timestamp)
|
||||||
{
|
{
|
||||||
crmodDate = p.lastWriteDate;
|
crmodDate = p.lastWriteDate;
|
||||||
crmodTime = p.lastWriteTime;
|
crmodTime = p.lastWriteTime;
|
||||||
|
|
@ -144,7 +144,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
printf_P(PSTR(" %#lx"), ((uint32_t)crmodDate << 16) | crmodTime);
|
printf_P(PSTR(" %#lx"), ((uint32_t)crmodDate << 16) | crmodTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lsParams->LFN)
|
if (lsParams.LFN)
|
||||||
printf_P(PSTR(" \"%s\""), LONGEST_FILENAME);
|
printf_P(PSTR(" \"%s\""), LONGEST_FILENAME);
|
||||||
|
|
||||||
SERIAL_PROTOCOLLN();
|
SERIAL_PROTOCOLLN();
|
||||||
|
|
@ -189,10 +189,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
} // while readDir
|
} // while readDir
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardReader::ls(struct ls_param params)
|
void CardReader::ls(ls_param params)
|
||||||
{
|
{
|
||||||
root.rewind();
|
root.rewind();
|
||||||
lsDive("",root, NULL, LS_SerialPrint, ¶ms);
|
lsDive("",root, NULL, LS_SerialPrint, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ public:
|
||||||
{
|
{
|
||||||
bool LFN : 1;
|
bool LFN : 1;
|
||||||
bool timestamp : 1;
|
bool timestamp : 1;
|
||||||
|
inline ls_param():LFN(0), timestamp(0) { }
|
||||||
|
inline ls_param(bool LFN, bool timestamp):LFN(LFN), timestamp(timestamp) { }
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
void initsd();
|
void initsd();
|
||||||
|
|
@ -54,7 +56,7 @@ public:
|
||||||
uint16_t getWorkDirDepth();
|
uint16_t getWorkDirDepth();
|
||||||
|
|
||||||
|
|
||||||
void ls(struct ls_param params);
|
void ls(ls_param params);
|
||||||
bool chdir(const char * relpath, bool doPresort);
|
bool chdir(const char * relpath, bool doPresort);
|
||||||
void updir();
|
void updir();
|
||||||
void setroot(bool doPresort);
|
void setroot(bool doPresort);
|
||||||
|
|
@ -137,7 +139,7 @@ private:
|
||||||
char* diveDirName;
|
char* diveDirName;
|
||||||
|
|
||||||
bool diveSubfolder (const char *&fileName);
|
bool diveSubfolder (const char *&fileName);
|
||||||
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL, LsAction lsAction = LS_GetFilename, struct ls_param *lsParams = NULL);
|
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL, LsAction lsAction = LS_GetFilename, ls_param lsParams = ls_param());
|
||||||
#ifdef SDCARD_SORT_ALPHA
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
void flush_presort();
|
void flush_presort();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue