Merge branch 'MK3' into thumbnails2
This commit is contained in:
commit
7aa4595211
49 changed files with 918 additions and 406 deletions
Firmware
|
@ -32,6 +32,7 @@ CardReader::CardReader()
|
|||
workDirDepth = 0;
|
||||
file_subcall_ctr=0;
|
||||
memset(workDirParents, 0, sizeof(workDirParents));
|
||||
presort_flag = false;
|
||||
|
||||
autostart_stilltocheck=true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
|
||||
lastnr=0;
|
||||
|
@ -69,12 +70,23 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
|
|||
+*/
|
||||
|
||||
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
||||
static uint8_t recursionCnt = 0;
|
||||
// RAII incrementer for the recursionCnt
|
||||
class _incrementer
|
||||
{
|
||||
public:
|
||||
_incrementer() {recursionCnt++;}
|
||||
~_incrementer() {recursionCnt--;}
|
||||
} recursionCntIncrementer;
|
||||
|
||||
dir_t p;
|
||||
uint8_t cnt = 0;
|
||||
// Read the next entry from a directory
|
||||
while (parent.readDir(p, longFilename) > 0) {
|
||||
// If the entry is a directory and the action is LS_SerialPrint
|
||||
if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
|
||||
if (recursionCnt > MAX_DIR_DEPTH)
|
||||
return;
|
||||
else if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) { // If the entry is a directory and the action is LS_SerialPrint
|
||||
|
||||
// Get the short name for the item, which we know is a folder
|
||||
char lfilename[FILENAME_LENGTH];
|
||||
createFilename(lfilename, p);
|
||||
|
@ -241,18 +253,18 @@ void CardReader::initsd()
|
|||
|
||||
}
|
||||
|
||||
void CardReader::setroot()
|
||||
void CardReader::setroot(bool doPresort)
|
||||
{
|
||||
/*if(!workDir.openRoot(&volume))
|
||||
{
|
||||
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
|
||||
}*/
|
||||
workDir=root;
|
||||
workDirDepth = 0;
|
||||
|
||||
curDir=&workDir;
|
||||
#ifdef SDCARD_SORT_ALPHA
|
||||
presort();
|
||||
#endif
|
||||
#ifdef SDCARD_SORT_ALPHA
|
||||
if (doPresort)
|
||||
presort();
|
||||
else
|
||||
presort_flag = true;
|
||||
#endif
|
||||
}
|
||||
void CardReader::release()
|
||||
{
|
||||
|
@ -304,6 +316,18 @@ void CardReader::getAbsFilename(char *t)
|
|||
else
|
||||
t[0]=0;
|
||||
}
|
||||
|
||||
void CardReader::printAbsFilenameFast()
|
||||
{
|
||||
SERIAL_PROTOCOL('/');
|
||||
for (uint8_t i = 0; i < getWorkDirDepth(); i++)
|
||||
{
|
||||
SERIAL_PROTOCOL(dir_names[i]);
|
||||
SERIAL_PROTOCOL('/');
|
||||
}
|
||||
SERIAL_PROTOCOL(LONGEST_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dive into subfolder
|
||||
*
|
||||
|
@ -317,19 +341,17 @@ void CardReader::getAbsFilename(char *t)
|
|||
* @param[in,out] fileName
|
||||
* expects file name including path
|
||||
* in case of absolute path, file name without path is returned
|
||||
* @param[in,out] dir SdFile object to operate with,
|
||||
* in case of absolute path, curDir is modified to point to dir,
|
||||
* so it is not possible to create on stack inside this function,
|
||||
* as curDir would point to destroyed object.
|
||||
*/
|
||||
void CardReader::diveSubfolder (const char *fileName, SdFile& dir)
|
||||
bool CardReader::diveSubfolder (const char *&fileName)
|
||||
{
|
||||
curDir=&root;
|
||||
if (!fileName) return;
|
||||
if (!fileName)
|
||||
return 1;
|
||||
|
||||
const char *dirname_start, *dirname_end;
|
||||
if (fileName[0] == '/') // absolute path
|
||||
{
|
||||
setroot(false);
|
||||
dirname_start = fileName + 1;
|
||||
while (*dirname_start)
|
||||
{
|
||||
|
@ -340,23 +362,13 @@ void CardReader::diveSubfolder (const char *fileName, SdFile& dir)
|
|||
{
|
||||
const size_t maxLen = 12;
|
||||
char subdirname[maxLen+1];
|
||||
subdirname[maxLen] = 0;
|
||||
const size_t len = ((static_cast<size_t>(dirname_end-dirname_start))>maxLen) ? maxLen : (dirname_end-dirname_start);
|
||||
strncpy(subdirname, dirname_start, len);
|
||||
SERIAL_ECHOLN(subdirname);
|
||||
if (!dir.open(curDir, subdirname, O_READ))
|
||||
{
|
||||
SERIAL_PROTOCOLRPGM(MSG_SD_OPEN_FILE_FAIL);
|
||||
SERIAL_PROTOCOL(subdirname);
|
||||
SERIAL_PROTOCOLLN('.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//SERIAL_ECHOLN("dive ok");
|
||||
}
|
||||
subdirname[len] = 0;
|
||||
if (!chdir(subdirname, false))
|
||||
return 0;
|
||||
|
||||
curDir = &dir;
|
||||
curDir = &workDir;
|
||||
dirname_start = dirname_end + 1;
|
||||
}
|
||||
else // the reminder after all /fsa/fdsa/ is the filename
|
||||
|
@ -373,6 +385,7 @@ void CardReader::diveSubfolder (const char *fileName, SdFile& dir)
|
|||
{
|
||||
curDir = &workDir;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char ofKill[] PROGMEM = "trying to call sub-gcode files with too many levels.";
|
||||
|
@ -428,9 +441,9 @@ void CardReader::openFileReadFilteredGcode(const char* name, bool replace_curren
|
|||
}
|
||||
sdprinting = false;
|
||||
|
||||
SdFile myDir;
|
||||
const char *fname=name;
|
||||
diveSubfolder(fname,myDir);
|
||||
if (!diveSubfolder(fname))
|
||||
return;
|
||||
|
||||
if (file.openFilteredGcode(curDir, fname)) {
|
||||
filesize = file.fileSize();
|
||||
|
@ -516,9 +529,9 @@ void CardReader::removeFile(const char* name)
|
|||
file.close();
|
||||
sdprinting = false;
|
||||
|
||||
SdFile myDir;
|
||||
const char *fname=name;
|
||||
diveSubfolder(fname,myDir);
|
||||
if (!diveSubfolder(fname))
|
||||
return;
|
||||
|
||||
if (file.remove(curDir, fname))
|
||||
{
|
||||
|
@ -543,31 +556,36 @@ uint32_t CardReader::getFileSize()
|
|||
return filesize;
|
||||
}
|
||||
|
||||
void CardReader::getStatus()
|
||||
void CardReader::getStatus(bool arg_P)
|
||||
{
|
||||
if(sdprinting)
|
||||
{
|
||||
if (isPrintPaused) {
|
||||
SERIAL_PROTOCOLLNPGM("SD print paused");
|
||||
}
|
||||
else if (saved_printing) {
|
||||
SERIAL_PROTOCOLLNPGM("Print saved");
|
||||
}
|
||||
else {
|
||||
SERIAL_PROTOCOLLN(LONGEST_FILENAME);
|
||||
SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE
|
||||
SERIAL_PROTOCOL(sdpos);
|
||||
SERIAL_PROTOCOL('/');
|
||||
SERIAL_PROTOCOLLN(filesize);
|
||||
uint16_t time = ( _millis() - starttime ) / 60000U;
|
||||
SERIAL_PROTOCOL(itostr2(time/60));
|
||||
SERIAL_PROTOCOL(':');
|
||||
SERIAL_PROTOCOLLN(itostr2(time%60));
|
||||
}
|
||||
}
|
||||
else {
|
||||
SERIAL_PROTOCOLLNPGM("Not SD printing");
|
||||
}
|
||||
if (isPrintPaused)
|
||||
{
|
||||
if (saved_printing && (saved_printing_type == PRINTING_TYPE_SD))
|
||||
SERIAL_PROTOCOLLNPGM("SD print paused");
|
||||
else
|
||||
SERIAL_PROTOCOLLNPGM("Print saved");
|
||||
}
|
||||
else if (sdprinting)
|
||||
{
|
||||
if (arg_P)
|
||||
{
|
||||
printAbsFilenameFast();
|
||||
SERIAL_PROTOCOLLN();
|
||||
}
|
||||
else
|
||||
SERIAL_PROTOCOLLN(LONGEST_FILENAME);
|
||||
|
||||
SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE
|
||||
SERIAL_PROTOCOL(sdpos);
|
||||
SERIAL_PROTOCOL('/');
|
||||
SERIAL_PROTOCOLLN(filesize);
|
||||
uint16_t time = ( _millis() - starttime ) / 60000U;
|
||||
SERIAL_PROTOCOL(itostr2(time/60));
|
||||
SERIAL_PROTOCOL(':');
|
||||
SERIAL_PROTOCOLLN(itostr2(time%60));
|
||||
}
|
||||
else
|
||||
SERIAL_PROTOCOLLNPGM("Not SD printing");
|
||||
}
|
||||
void CardReader::write_command(char *buf)
|
||||
{
|
||||
|
@ -704,7 +722,7 @@ uint16_t CardReader::getnrfilenames()
|
|||
return nrFiles;
|
||||
}
|
||||
|
||||
void CardReader::chdir(const char * relpath)
|
||||
bool CardReader::chdir(const char * relpath, bool doPresort)
|
||||
{
|
||||
SdFile newfile;
|
||||
SdFile *parent=&root;
|
||||
|
@ -712,23 +730,32 @@ void CardReader::chdir(const char * relpath)
|
|||
if(workDir.isOpen())
|
||||
parent=&workDir;
|
||||
|
||||
if(!newfile.open(*parent,relpath, O_READ))
|
||||
if(!newfile.open(*parent,relpath, O_READ) || ((workDirDepth + 1) >= MAX_DIR_DEPTH))
|
||||
{
|
||||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHORPGM(_n("Cannot enter subdir: "));////MSG_SD_CANT_ENTER_SUBDIR
|
||||
SERIAL_ECHOLN(relpath);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(dir_names[workDirDepth], relpath);
|
||||
puts(relpath);
|
||||
|
||||
if (workDirDepth < MAX_DIR_DEPTH) {
|
||||
for (int d = ++workDirDepth; d--;)
|
||||
workDirParents[d+1] = workDirParents[d];
|
||||
workDirParents[0]=*parent;
|
||||
}
|
||||
workDir=newfile;
|
||||
#ifdef SDCARD_SORT_ALPHA
|
||||
|
||||
#ifdef SDCARD_SORT_ALPHA
|
||||
if (doPresort)
|
||||
presort();
|
||||
#endif
|
||||
else
|
||||
presort_flag = true;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue