I'm using the SdFat Library's sd.ls(LS_R)
function to give me a serial output stream of all files on an SD card. My issue is that I would like to have it use a different character than '\n' at the end of each line as I'm using it as a termchar for my overall comms protocol. How can I get it to print a :
or (another symbol that doesn't appear in file names) instead of a \ln
I am currently trying to have fun Modding my own sd.ls().
Worst way, modifying the library:
Go into FatFilePrint.cpp
(Suggestion: Create yourself a new 'flag' like LS_COMMA)
Find the line
void FatFile::ls(print_t* pr, uint8_t flags, uint8_t indent) { ...
add your flag
if (flag & !LS_COMMA) {
pr-->write(':');
} else {
//original library set of
// pr->write(stuff);
}
--> SuperClass version # (prefered )
this will override the original ls() method by creating a new Class inheriting from the original one.
rather then invoking it from "volume", sd.ls( your params);
invoke it from a directory file instead.
superFatFile rootDir;
rootDir.open("/");
rootDir.ls( __your_params__);
Place this superClass declaration in your .h don't hesitate to remove any of the "flags" related code if YOUR requirement never calls for them.
class superFatFile : public FatFile {
public:
void ls(print_t* pr, uint8_t flags /* = 0 */, uint8_t indent /* = 0 */){
superFile file;
rewind();
while (file.openNext(this, O_READ)) {
if (!file.isHidden() || (flags & LS_A)) {
// adds 'spaces' indent for dir level
for (uint8_t i = 0; i < indent; i++) {
pr->write(' ');
}
if (flags & LS_DATE) {
file.printModifyDateTime(pr);
pr->write(' ');
}
if (flags & LS_SIZE) {
file.printFileSize(pr);
pr->write(' ');
}
// prints filename
if (!file.isDir()) {
file.printName(pr);
pr->write('\r');
pr->write('\n'); // HERE IS YOUR SEPARATOR CARACTERS !!!
}
// execute recursivly if LS_R flag was set
if ((flags & LS_R) && file.isDir()) file.ls(pr, flags, indent + 2);
}
}
file.close();
} // end of new LS method
}; // end of superClass