Multi-host support
This commit is contained in:
committed by
Scott Lahteine
parent
dabb75034c
commit
f7efac57b7
@ -339,38 +339,38 @@ int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) {
|
||||
&& DIR_IS_FILE_OR_SUBDIR(&dir)) break;
|
||||
}
|
||||
// indent for dir level
|
||||
for (uint8_t i = 0; i < indent; i++) MYSERIAL.write(' ');
|
||||
for (uint8_t i = 0; i < indent; i++) SERIAL_CHAR(' ');
|
||||
|
||||
// print name
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
if (dir.name[i] == ' ')continue;
|
||||
if (i == 8) {
|
||||
MYSERIAL.write('.');
|
||||
SERIAL_CHAR('.');
|
||||
w++;
|
||||
}
|
||||
MYSERIAL.write(dir.name[i]);
|
||||
SERIAL_CHAR(dir.name[i]);
|
||||
w++;
|
||||
}
|
||||
if (DIR_IS_SUBDIR(&dir)) {
|
||||
MYSERIAL.write('/');
|
||||
SERIAL_CHAR('/');
|
||||
w++;
|
||||
}
|
||||
if (flags & (LS_DATE | LS_SIZE)) {
|
||||
while (w++ < 14) MYSERIAL.write(' ');
|
||||
while (w++ < 14) SERIAL_CHAR(' ');
|
||||
}
|
||||
// print modify date/time if requested
|
||||
if (flags & LS_DATE) {
|
||||
MYSERIAL.write(' ');
|
||||
SERIAL_CHAR(' ');
|
||||
printFatDate(dir.lastWriteDate);
|
||||
MYSERIAL.write(' ');
|
||||
SERIAL_CHAR(' ');
|
||||
printFatTime(dir.lastWriteTime);
|
||||
}
|
||||
// print size if requested
|
||||
if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
|
||||
MYSERIAL.write(' ');
|
||||
MYSERIAL.print(dir.fileSize);
|
||||
SERIAL_CHAR(' ');
|
||||
SERIAL_ECHO(dir.fileSize);
|
||||
}
|
||||
MYSERIAL.println();
|
||||
SERIAL_EOL();
|
||||
return DIR_IS_FILE(&dir) ? 1 : 2;
|
||||
}
|
||||
|
||||
@ -902,11 +902,10 @@ int SdBaseFile::peek() {
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// print uint8_t with width 2
|
||||
static void print2u(uint8_t v) {
|
||||
if (v < 10) MYSERIAL.write('0');
|
||||
MYSERIAL.print(v, DEC);
|
||||
static void print2u(const uint8_t v) {
|
||||
if (v < 10) SERIAL_CHAR('0');
|
||||
SERIAL_ECHO_F(v, DEC);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -927,10 +926,10 @@ static void print2u(uint8_t v) {
|
||||
* \param[in] fatDate The date field from a directory entry.
|
||||
*/
|
||||
void SdBaseFile::printFatDate(uint16_t fatDate) {
|
||||
MYSERIAL.print(FAT_YEAR(fatDate));
|
||||
MYSERIAL.write('-');
|
||||
SERIAL_ECHO(FAT_YEAR(fatDate));
|
||||
SERIAL_CHAR('-');
|
||||
print2u(FAT_MONTH(fatDate));
|
||||
MYSERIAL.write('-');
|
||||
SERIAL_CHAR('-');
|
||||
print2u(FAT_DAY(fatDate));
|
||||
}
|
||||
|
||||
@ -945,9 +944,9 @@ void SdBaseFile::printFatDate(uint16_t fatDate) {
|
||||
*/
|
||||
void SdBaseFile::printFatTime(uint16_t fatTime) {
|
||||
print2u(FAT_HOUR(fatTime));
|
||||
MYSERIAL.write(':');
|
||||
SERIAL_CHAR(':');
|
||||
print2u(FAT_MINUTE(fatTime));
|
||||
MYSERIAL.write(':');
|
||||
SERIAL_CHAR(':');
|
||||
print2u(FAT_SECOND(fatTime));
|
||||
}
|
||||
|
||||
@ -959,7 +958,7 @@ void SdBaseFile::printFatTime(uint16_t fatTime) {
|
||||
bool SdBaseFile::printName() {
|
||||
char name[FILENAME_LENGTH];
|
||||
if (!getFilename(name)) return false;
|
||||
MYSERIAL.print(name);
|
||||
SERIAL_ECHO(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,54 +38,22 @@
|
||||
* \return The number of free bytes.
|
||||
*/
|
||||
#ifdef __arm__
|
||||
extern "C" char* sbrk(int incr);
|
||||
int SdFatUtil::FreeRam() {
|
||||
char top;
|
||||
return &top - reinterpret_cast<char*>(sbrk(0));
|
||||
}
|
||||
#else // __arm__
|
||||
extern char* __brkval;
|
||||
extern char __bss_end;
|
||||
/**
|
||||
* Amount of free RAM
|
||||
* \return The number of free bytes.
|
||||
*/
|
||||
int SdFatUtil::FreeRam() {
|
||||
char top;
|
||||
return __brkval ? &top - __brkval : &top - &__bss_end;
|
||||
}
|
||||
#endif // __arm
|
||||
|
||||
/**
|
||||
* %Print a string in flash memory.
|
||||
*
|
||||
* \param[in] pr Print object for output.
|
||||
* \param[in] str Pointer to string stored in flash memory.
|
||||
*/
|
||||
void SdFatUtil::print_P(PGM_P str) {
|
||||
for (uint8_t c; (c = pgm_read_byte(str)); str++) MYSERIAL.write(c);
|
||||
}
|
||||
extern "C" char* sbrk(int incr);
|
||||
int SdFatUtil::FreeRam() {
|
||||
char top;
|
||||
return &top - reinterpret_cast<char*>(sbrk(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* %Print a string in flash memory followed by a CR/LF.
|
||||
*
|
||||
* \param[in] pr Print object for output.
|
||||
* \param[in] str Pointer to string stored in flash memory.
|
||||
*/
|
||||
void SdFatUtil::println_P(PGM_P str) { print_P(str); MYSERIAL.println(); }
|
||||
#else
|
||||
|
||||
/**
|
||||
* %Print a string in flash memory to Serial.
|
||||
*
|
||||
* \param[in] str Pointer to string stored in flash memory.
|
||||
*/
|
||||
void SdFatUtil::SerialPrint_P(PGM_P str) { print_P(str); }
|
||||
extern char* __brkval;
|
||||
extern char __bss_end;
|
||||
int SdFatUtil::FreeRam() {
|
||||
char top;
|
||||
return __brkval ? &top - __brkval : &top - &__bss_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* %Print a string in flash memory to Serial followed by a CR/LF.
|
||||
*
|
||||
* \param[in] str Pointer to string stored in flash memory.
|
||||
*/
|
||||
void SdFatUtil::SerialPrintln_P(PGM_P str) { println_P(str); }
|
||||
#endif
|
||||
|
||||
#endif // SDSUPPORT
|
||||
|
@ -35,17 +35,9 @@
|
||||
* \file
|
||||
* \brief Useful utility functions.
|
||||
*/
|
||||
/** Store and print a string in flash memory.*/
|
||||
#define PgmPrint(x) SerialPrint_P(PSTR(x))
|
||||
/** Store and print a string in flash memory followed by a CR/LF.*/
|
||||
#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
|
||||
|
||||
namespace SdFatUtil {
|
||||
int FreeRam();
|
||||
void print_P(PGM_P str);
|
||||
void println_P(PGM_P str);
|
||||
void SerialPrint_P(PGM_P str);
|
||||
void SerialPrintln_P(PGM_P str);
|
||||
}
|
||||
|
||||
using namespace SdFatUtil; // NOLINT
|
||||
|
@ -85,7 +85,11 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
|
||||
|
||||
uint16_t nrFile_index;
|
||||
|
||||
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
||||
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/
|
||||
#if NUM_SERIAL > 1
|
||||
, const int8_t port/*= -1*/
|
||||
#endif
|
||||
) {
|
||||
dir_t p;
|
||||
uint8_t cnt = 0;
|
||||
|
||||
@ -118,12 +122,16 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||
SdFile dir;
|
||||
if (!dir.open(parent, lfilename, O_READ)) {
|
||||
if (lsAction == LS_SerialPrint) {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
|
||||
SERIAL_ECHOLN(lfilename);
|
||||
SERIAL_ECHO_START_P(port);
|
||||
SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
|
||||
SERIAL_ECHOLN_P(port, lfilename);
|
||||
}
|
||||
}
|
||||
lsDive(path, dir);
|
||||
lsDive(path, dir
|
||||
#if NUM_SERIAL > 1
|
||||
, NULL, port
|
||||
#endif
|
||||
);
|
||||
// close() is done automatically by destructor of SdFile
|
||||
}
|
||||
else {
|
||||
@ -145,10 +153,10 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||
|
||||
case LS_SerialPrint:
|
||||
createFilename(filename, p);
|
||||
SERIAL_PROTOCOL(prepend);
|
||||
SERIAL_PROTOCOL(filename);
|
||||
SERIAL_PROTOCOLCHAR(' ');
|
||||
SERIAL_PROTOCOLLN(p.fileSize);
|
||||
SERIAL_PROTOCOL_P(port, prepend);
|
||||
SERIAL_PROTOCOL_P(port, filename);
|
||||
SERIAL_PROTOCOLCHAR_P(port, ' ');
|
||||
SERIAL_PROTOCOLLN_P(port, p.fileSize);
|
||||
break;
|
||||
|
||||
case LS_GetFilename:
|
||||
@ -165,10 +173,18 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||
} // while readDir
|
||||
}
|
||||
|
||||
void CardReader::ls() {
|
||||
void CardReader::ls(
|
||||
#if NUM_SERIAL > 1
|
||||
const int8_t port
|
||||
#endif
|
||||
) {
|
||||
lsAction = LS_SerialPrint;
|
||||
root.rewind();
|
||||
lsDive("", root);
|
||||
lsDive("", root
|
||||
#if NUM_SERIAL > 1
|
||||
, NULL, port
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
||||
@ -176,12 +192,16 @@ void CardReader::ls() {
|
||||
/**
|
||||
* Get a long pretty path based on a DOS 8.3 path
|
||||
*/
|
||||
void CardReader::printLongPath(char *path) {
|
||||
void CardReader::printLongPath(char *path
|
||||
#if NUM_SERIAL > 1
|
||||
, const int8_t port/*= -1*/
|
||||
#endif
|
||||
) {
|
||||
lsAction = LS_GetFilename;
|
||||
|
||||
int i, pathLen = strlen(path);
|
||||
|
||||
// SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
|
||||
// SERIAL_ECHOPGM_P(port, "Full Path: "); SERIAL_ECHOLN_P(port, path);
|
||||
|
||||
// Zero out slashes to make segments
|
||||
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
|
||||
@ -199,28 +219,32 @@ void CardReader::ls() {
|
||||
// Go to the next segment
|
||||
while (path[++i]) { }
|
||||
|
||||
// SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
|
||||
// SERIAL_ECHOPGM_P(port, "Looking for segment: "); SERIAL_ECHOLN_P(port, segment);
|
||||
|
||||
// Find the item, setting the long filename
|
||||
diveDir.rewind();
|
||||
lsDive("", diveDir, segment);
|
||||
lsDive("", diveDir, segment
|
||||
#if NUM_SERIAL > 1
|
||||
, port
|
||||
#endif
|
||||
);
|
||||
|
||||
// Print /LongNamePart to serial output
|
||||
SERIAL_PROTOCOLCHAR('/');
|
||||
SERIAL_PROTOCOL(longFilename[0] ? longFilename : "???");
|
||||
SERIAL_PROTOCOLCHAR_P(port, '/');
|
||||
SERIAL_PROTOCOL_P(port, longFilename[0] ? longFilename : "???");
|
||||
|
||||
// If the filename was printed then that's it
|
||||
if (!filenameIsDir) break;
|
||||
|
||||
// SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
|
||||
// SERIAL_ECHOPGM_P(port, "Opening dir: "); SERIAL_ECHOLN_P(port, segment);
|
||||
|
||||
// Open the sub-item as the new dive parent
|
||||
SdFile dir;
|
||||
if (!dir.open(diveDir, segment, O_READ)) {
|
||||
SERIAL_EOL();
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
|
||||
SERIAL_ECHO(segment);
|
||||
SERIAL_EOL_P(port);
|
||||
SERIAL_ECHO_START_P(port);
|
||||
SERIAL_ECHOPGM_P(port, MSG_SD_CANT_OPEN_SUBDIR);
|
||||
SERIAL_ECHO_P(port, segment);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -229,7 +253,7 @@ void CardReader::ls() {
|
||||
|
||||
} // while i<pathLen
|
||||
|
||||
SERIAL_EOL();
|
||||
SERIAL_EOL_P(port);
|
||||
}
|
||||
|
||||
#endif // LONG_FILENAME_HOST_SUPPORT
|
||||
@ -500,15 +524,19 @@ void CardReader::removeFile(const char * const name) {
|
||||
}
|
||||
}
|
||||
|
||||
void CardReader::getStatus() {
|
||||
void CardReader::getStatus(
|
||||
#if NUM_SERIAL > 1
|
||||
const int8_t port/*= -1*/
|
||||
#endif
|
||||
) {
|
||||
if (cardOK) {
|
||||
SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
|
||||
SERIAL_PROTOCOL(sdpos);
|
||||
SERIAL_PROTOCOLCHAR('/');
|
||||
SERIAL_PROTOCOLLN(filesize);
|
||||
SERIAL_PROTOCOLPGM_P(port, MSG_SD_PRINTING_BYTE);
|
||||
SERIAL_PROTOCOL_P(port, sdpos);
|
||||
SERIAL_PROTOCOLCHAR_P(port, '/');
|
||||
SERIAL_PROTOCOLLN_P(port, filesize);
|
||||
}
|
||||
else
|
||||
SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
|
||||
SERIAL_PROTOCOLLNPGM_P(port, MSG_SD_NOT_PRINTING);
|
||||
}
|
||||
|
||||
void CardReader::write_command(char *buf) {
|
||||
|
@ -49,11 +49,19 @@ public:
|
||||
void openAndPrintFile(const char *name);
|
||||
void startFileprint();
|
||||
void stopSDPrint();
|
||||
void getStatus();
|
||||
void getStatus(
|
||||
#if NUM_SERIAL > 1
|
||||
const int8_t port = -1
|
||||
#endif
|
||||
);
|
||||
void printingHasFinished();
|
||||
|
||||
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
|
||||
void printLongPath(char *path);
|
||||
void printLongPath(char *path
|
||||
#if NUM_SERIAL > 1
|
||||
, const int8_t port = -1
|
||||
#endif
|
||||
);
|
||||
#endif
|
||||
|
||||
void getfilename(uint16_t nr, const char* const match=NULL);
|
||||
@ -61,7 +69,11 @@ public:
|
||||
|
||||
void getAbsFilename(char *t);
|
||||
|
||||
void ls();
|
||||
void ls(
|
||||
#if NUM_SERIAL > 1
|
||||
const int8_t port = -1
|
||||
#endif
|
||||
);
|
||||
void chdir(const char *relpath);
|
||||
int8_t updir();
|
||||
void setroot();
|
||||
@ -162,7 +174,11 @@ private:
|
||||
LsAction lsAction; //stored for recursion.
|
||||
uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
|
||||
char* diveDirName;
|
||||
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
|
||||
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL
|
||||
#if NUM_SERIAL > 1
|
||||
, const int8_t port = -1
|
||||
#endif
|
||||
);
|
||||
|
||||
#if ENABLED(SDCARD_SORT_ALPHA)
|
||||
void flush_presort();
|
||||
|
Reference in New Issue
Block a user