More fixes that were extracted from #2405
This commit is contained in:
parent
f343e6432a
commit
52f7a71dce
|
|
@ -350,10 +350,6 @@ extern unsigned long t_fan_rising_edge;
|
||||||
extern bool mesh_bed_leveling_flag;
|
extern bool mesh_bed_leveling_flag;
|
||||||
extern bool mesh_bed_run_from_menu;
|
extern bool mesh_bed_run_from_menu;
|
||||||
|
|
||||||
extern bool sortAlpha;
|
|
||||||
|
|
||||||
extern char dir_names[][9];
|
|
||||||
|
|
||||||
extern int8_t lcd_change_fil_state;
|
extern int8_t lcd_change_fil_state;
|
||||||
// save/restore printing
|
// save/restore printing
|
||||||
extern bool saved_printing;
|
extern bool saved_printing;
|
||||||
|
|
|
||||||
|
|
@ -228,10 +228,6 @@ bool fan_state[2];
|
||||||
int fan_edge_counter[2];
|
int fan_edge_counter[2];
|
||||||
int fan_speed[2];
|
int fan_speed[2];
|
||||||
|
|
||||||
char dir_names[MAX_DIR_DEPTH][9];
|
|
||||||
|
|
||||||
bool sortAlpha = false;
|
|
||||||
|
|
||||||
|
|
||||||
float extruder_multiplier[EXTRUDERS] = {1.0
|
float extruder_multiplier[EXTRUDERS] = {1.0
|
||||||
#if EXTRUDERS > 1
|
#if EXTRUDERS > 1
|
||||||
|
|
@ -11281,8 +11277,8 @@ void restore_print_from_eeprom(bool mbl_was_active) {
|
||||||
}
|
}
|
||||||
dir_name[8] = '\0';
|
dir_name[8] = '\0';
|
||||||
MYSERIAL.println(dir_name);
|
MYSERIAL.println(dir_name);
|
||||||
strcpy(dir_names[i], dir_name);
|
// strcpy(dir_names[i], dir_name);
|
||||||
card.chdir(dir_name);
|
card.chdir(dir_name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ CardReader::CardReader()
|
||||||
workDirDepth = 0;
|
workDirDepth = 0;
|
||||||
file_subcall_ctr=0;
|
file_subcall_ctr=0;
|
||||||
memset(workDirParents, 0, sizeof(workDirParents));
|
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.
|
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;
|
lastnr=0;
|
||||||
|
|
@ -69,12 +70,15 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
|
||||||
+*/
|
+*/
|
||||||
|
|
||||||
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*/) {
|
||||||
|
static uint8_t recursionCnt = 0;
|
||||||
dir_t p;
|
dir_t p;
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
// Read the next entry from a directory
|
// Read the next entry from a directory
|
||||||
while (parent.readDir(p, longFilename) > 0) {
|
while (parent.readDir(p, longFilename) > 0) {
|
||||||
// If the entry is a directory and the action is LS_SerialPrint
|
if (recursionCnt >= MAX_DIR_DEPTH)
|
||||||
if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
|
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
|
||||||
|
recursionCnt++;
|
||||||
// Get the short name for the item, which we know is a folder
|
// Get the short name for the item, which we know is a folder
|
||||||
char lfilename[FILENAME_LENGTH];
|
char lfilename[FILENAME_LENGTH];
|
||||||
createFilename(lfilename, p);
|
createFilename(lfilename, p);
|
||||||
|
|
@ -108,6 +112,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
||||||
|
|
||||||
if (lsAction == LS_SerialPrint_LFN)
|
if (lsAction == LS_SerialPrint_LFN)
|
||||||
puts_P(PSTR("DIR_EXIT"));
|
puts_P(PSTR("DIR_EXIT"));
|
||||||
|
recursionCnt--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint8_t pn0 = p.name[0];
|
uint8_t pn0 = p.name[0];
|
||||||
|
|
@ -241,18 +246,18 @@ void CardReader::initsd()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardReader::setroot()
|
void CardReader::setroot(bool doPresort)
|
||||||
{
|
{
|
||||||
/*if(!workDir.openRoot(&volume))
|
|
||||||
{
|
|
||||||
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
|
|
||||||
}*/
|
|
||||||
workDir=root;
|
workDir=root;
|
||||||
|
workDirDepth = 0;
|
||||||
|
|
||||||
curDir=&workDir;
|
curDir=&workDir;
|
||||||
#ifdef SDCARD_SORT_ALPHA
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
presort();
|
if (doPresort)
|
||||||
#endif
|
presort();
|
||||||
|
else
|
||||||
|
presort_flag = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void CardReader::release()
|
void CardReader::release()
|
||||||
{
|
{
|
||||||
|
|
@ -317,19 +322,17 @@ void CardReader::getAbsFilename(char *t)
|
||||||
* @param[in,out] fileName
|
* @param[in,out] fileName
|
||||||
* expects file name including path
|
* expects file name including path
|
||||||
* in case of absolute path, file name without path is returned
|
* 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;
|
curDir=&root;
|
||||||
if (!fileName) return;
|
if (!fileName)
|
||||||
|
return 1;
|
||||||
|
|
||||||
const char *dirname_start, *dirname_end;
|
const char *dirname_start, *dirname_end;
|
||||||
if (fileName[0] == '/') // absolute path
|
if (fileName[0] == '/') // absolute path
|
||||||
{
|
{
|
||||||
|
setroot(false);
|
||||||
dirname_start = fileName + 1;
|
dirname_start = fileName + 1;
|
||||||
while (*dirname_start)
|
while (*dirname_start)
|
||||||
{
|
{
|
||||||
|
|
@ -344,19 +347,10 @@ void CardReader::diveSubfolder (const char *fileName, SdFile& dir)
|
||||||
strncpy(subdirname, dirname_start, len);
|
strncpy(subdirname, dirname_start, len);
|
||||||
subdirname[len] = 0;
|
subdirname[len] = 0;
|
||||||
SERIAL_ECHOLN(subdirname);
|
SERIAL_ECHOLN(subdirname);
|
||||||
if (!dir.open(curDir, subdirname, O_READ))
|
if (!chdir(subdirname, false))
|
||||||
{
|
return 0;
|
||||||
SERIAL_PROTOCOLRPGM(MSG_SD_OPEN_FILE_FAIL);
|
|
||||||
SERIAL_PROTOCOL(subdirname);
|
|
||||||
SERIAL_PROTOCOLLN('.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//SERIAL_ECHOLN("dive ok");
|
|
||||||
}
|
|
||||||
|
|
||||||
curDir = &dir;
|
curDir = &workDir;
|
||||||
dirname_start = dirname_end + 1;
|
dirname_start = dirname_end + 1;
|
||||||
}
|
}
|
||||||
else // the reminder after all /fsa/fdsa/ is the filename
|
else // the reminder after all /fsa/fdsa/ is the filename
|
||||||
|
|
@ -373,6 +367,7 @@ void CardReader::diveSubfolder (const char *fileName, SdFile& dir)
|
||||||
{
|
{
|
||||||
curDir = &workDir;
|
curDir = &workDir;
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardReader::openFile(const char* name,bool read, bool replace_current/*=true*/)
|
void CardReader::openFile(const char* name,bool read, bool replace_current/*=true*/)
|
||||||
|
|
@ -423,9 +418,9 @@ void CardReader::openFile(const char* name,bool read, bool replace_current/*=tru
|
||||||
}
|
}
|
||||||
sdprinting = false;
|
sdprinting = false;
|
||||||
|
|
||||||
SdFile myDir;
|
|
||||||
const char *fname=name;
|
const char *fname=name;
|
||||||
diveSubfolder(fname,myDir);
|
if (!diveSubfolder(fname))
|
||||||
|
return;
|
||||||
|
|
||||||
if(read)
|
if(read)
|
||||||
{
|
{
|
||||||
|
|
@ -438,10 +433,9 @@ void CardReader::openFile(const char* name,bool read, bool replace_current/*=tru
|
||||||
SERIAL_PROTOCOLLN(filesize);
|
SERIAL_PROTOCOLLN(filesize);
|
||||||
sdpos = 0;
|
sdpos = 0;
|
||||||
|
|
||||||
SERIAL_PROTOCOLLNRPGM(_N("File selected"));////MSG_SD_FILE_SELECTED
|
SERIAL_PROTOCOLLNRPGM(MSG_FILE_SELECTED);
|
||||||
|
lcd_setstatuspgm(MSG_FILE_SELECTED);
|
||||||
getfilename(0, fname);
|
getfilename(0, fname);
|
||||||
lcd_setstatus(longFilename[0] ? longFilename : fname);
|
|
||||||
lcd_setstatuspgm(PSTR("SD-PRINTING"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -475,9 +469,9 @@ void CardReader::removeFile(const char* name)
|
||||||
file.close();
|
file.close();
|
||||||
sdprinting = false;
|
sdprinting = false;
|
||||||
|
|
||||||
SdFile myDir;
|
|
||||||
const char *fname=name;
|
const char *fname=name;
|
||||||
diveSubfolder(fname,myDir);
|
if (!diveSubfolder(fname))
|
||||||
|
return;
|
||||||
|
|
||||||
if (file.remove(curDir, fname))
|
if (file.remove(curDir, fname))
|
||||||
{
|
{
|
||||||
|
|
@ -670,7 +664,7 @@ uint16_t CardReader::getnrfilenames()
|
||||||
return nrFiles;
|
return nrFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardReader::chdir(const char * relpath)
|
bool CardReader::chdir(const char * relpath, bool doPresort)
|
||||||
{
|
{
|
||||||
SdFile newfile;
|
SdFile newfile;
|
||||||
SdFile *parent=&root;
|
SdFile *parent=&root;
|
||||||
|
|
@ -678,23 +672,32 @@ void CardReader::chdir(const char * relpath)
|
||||||
if(workDir.isOpen())
|
if(workDir.isOpen())
|
||||||
parent=&workDir;
|
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_ECHO_START;
|
||||||
SERIAL_ECHORPGM(_n("Cannot enter subdir: "));////MSG_SD_CANT_ENTER_SUBDIR
|
SERIAL_ECHORPGM(_n("Cannot enter subdir: "));////MSG_SD_CANT_ENTER_SUBDIR
|
||||||
SERIAL_ECHOLN(relpath);
|
SERIAL_ECHOLN(relpath);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
strcpy(dir_names[workDirDepth], relpath);
|
||||||
|
puts(relpath);
|
||||||
|
|
||||||
if (workDirDepth < MAX_DIR_DEPTH) {
|
if (workDirDepth < MAX_DIR_DEPTH) {
|
||||||
for (int d = ++workDirDepth; d--;)
|
for (int d = ++workDirDepth; d--;)
|
||||||
workDirParents[d+1] = workDirParents[d];
|
workDirParents[d+1] = workDirParents[d];
|
||||||
workDirParents[0]=*parent;
|
workDirParents[0]=*parent;
|
||||||
}
|
}
|
||||||
workDir=newfile;
|
workDir=newfile;
|
||||||
#ifdef SDCARD_SORT_ALPHA
|
|
||||||
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
|
if (doPresort)
|
||||||
presort();
|
presort();
|
||||||
#endif
|
else
|
||||||
|
presort_flag = true;
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
void ls(bool printLFN);
|
void ls(bool printLFN);
|
||||||
void chdir(const char * relpath);
|
bool chdir(const char * relpath, bool doPresort);
|
||||||
void updir();
|
void updir();
|
||||||
void setroot();
|
void setroot(bool doPresort);
|
||||||
|
|
||||||
#ifdef SDCARD_SORT_ALPHA
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
void presort();
|
void presort();
|
||||||
|
|
@ -82,6 +82,10 @@ public:
|
||||||
char longFilename[LONG_FILENAME_LENGTH];
|
char longFilename[LONG_FILENAME_LENGTH];
|
||||||
bool filenameIsDir;
|
bool filenameIsDir;
|
||||||
int lastnr; //last number of the autostart;
|
int lastnr; //last number of the autostart;
|
||||||
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
|
bool presort_flag;
|
||||||
|
char dir_names[MAX_DIR_DEPTH][9];
|
||||||
|
#endif // SDCARD_SORT_ALPHA
|
||||||
private:
|
private:
|
||||||
SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH];
|
SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH];
|
||||||
uint16_t workDirDepth;
|
uint16_t workDirDepth;
|
||||||
|
|
@ -155,7 +159,7 @@ private:
|
||||||
int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
|
int16_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;
|
char* diveDirName;
|
||||||
|
|
||||||
void diveSubfolder (const char *fileName, SdFile& dir);
|
bool diveSubfolder (const char *&fileName);
|
||||||
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
|
void lsDive(const char *prepend, SdFile parent, const char * const match=NULL);
|
||||||
#ifdef SDCARD_SORT_ALPHA
|
#ifdef SDCARD_SORT_ALPHA
|
||||||
void flush_presort();
|
void flush_presort();
|
||||||
|
|
|
||||||
|
|
@ -197,3 +197,4 @@ const char MSG_M112_KILL[] PROGMEM_N1 = "M112 called. Emergency Stop."; ////c=20
|
||||||
const char MSG_ADVANCE_K[] PROGMEM_N1 = "Advance K:"; ////c=13
|
const char MSG_ADVANCE_K[] PROGMEM_N1 = "Advance K:"; ////c=13
|
||||||
const char MSG_POWERPANIC_DETECTED[] PROGMEM_N1 = "POWER PANIC DETECTED"; ////c=20
|
const char MSG_POWERPANIC_DETECTED[] PROGMEM_N1 = "POWER PANIC DETECTED"; ////c=20
|
||||||
const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed";
|
const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed";
|
||||||
|
const char MSG_FILE_SELECTED[] PROGMEM_N1 = "File selected"; ////c=20
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@ extern const char MSG_M112_KILL[];
|
||||||
extern const char MSG_ADVANCE_K[];
|
extern const char MSG_ADVANCE_K[];
|
||||||
extern const char MSG_POWERPANIC_DETECTED[];
|
extern const char MSG_POWERPANIC_DETECTED[];
|
||||||
extern const char MSG_LCD_STATUS_CHANGED[];
|
extern const char MSG_LCD_STATUS_CHANGED[];
|
||||||
|
extern const char MSG_FILE_SELECTED[];
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4317,7 +4317,7 @@ static void lcd_sort_type_set() {
|
||||||
default: sdSort = SD_SORT_TIME;
|
default: sdSort = SD_SORT_TIME;
|
||||||
}
|
}
|
||||||
eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
|
eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
|
||||||
presort_flag = true;
|
card.presort_flag = true;
|
||||||
}
|
}
|
||||||
#endif //SDCARD_SORT_ALPHA
|
#endif //SDCARD_SORT_ALPHA
|
||||||
|
|
||||||
|
|
@ -8548,7 +8548,7 @@ static void menu_action_sdfile(const char* filename)
|
||||||
|
|
||||||
for (uint_least8_t i = 0; i < depth; i++) {
|
for (uint_least8_t i = 0; i < depth; i++) {
|
||||||
for (uint_least8_t j = 0; j < 8; j++) {
|
for (uint_least8_t j = 0; j < 8; j++) {
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
|
eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -8566,12 +8566,8 @@ static void menu_action_sdfile(const char* filename)
|
||||||
|
|
||||||
void menu_action_sddirectory(const char* filename)
|
void menu_action_sddirectory(const char* filename)
|
||||||
{
|
{
|
||||||
uint8_t depth = (uint8_t)card.getWorkDirDepth();
|
card.chdir(filename, true);
|
||||||
|
lcd_encoder = 0;
|
||||||
strcpy(dir_names[depth], filename);
|
|
||||||
MYSERIAL.println(dir_names[depth]);
|
|
||||||
card.chdir(filename);
|
|
||||||
lcd_encoder = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** LCD API **/
|
/** LCD API **/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue