mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-12-03 17:21:29 +00:00
Fix bug: diveToFile breaks M23 (#13865)
This commit is contained in:
parent
e5438a9a03
commit
c369477cb0
@ -392,7 +392,6 @@ void PrintJobRecovery::resume() {
|
|||||||
|
|
||||||
// Resume the SD file from the last position
|
// Resume the SD file from the last position
|
||||||
char *fn = info.sd_filename;
|
char *fn = info.sd_filename;
|
||||||
while (*fn == '/') fn++;
|
|
||||||
sprintf_P(cmd, PSTR("M23 %s"), fn);
|
sprintf_P(cmd, PSTR("M23 %s"), fn);
|
||||||
gcode.process_subcommands_now(cmd);
|
gcode.process_subcommands_now(cmd);
|
||||||
sprintf_P(cmd, PSTR("M24 S%ld T%ld"), info.sdpos, info.print_job_elapsed);
|
sprintf_P(cmd, PSTR("M24 S%ld T%ld"), info.sdpos, info.print_job_elapsed);
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* M23: Open a file
|
* M23: Open a file
|
||||||
|
*
|
||||||
|
* The path is relative to the root directory
|
||||||
*/
|
*/
|
||||||
void GcodeSuite::M23() {
|
void GcodeSuite::M23() {
|
||||||
// Simplify3D includes the size, so zero out all spaces (#7227)
|
// Simplify3D includes the size, so zero out all spaces (#7227)
|
||||||
|
@ -461,7 +461,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
|
|||||||
stopSDPrint();
|
stopSDPrint();
|
||||||
|
|
||||||
SdFile *curDir;
|
SdFile *curDir;
|
||||||
const char * const fname = diveToFile(curDir, path, false);
|
const char * const fname = diveToFile(curDir, path);
|
||||||
if (!fname) return;
|
if (!fname) return;
|
||||||
|
|
||||||
if (read) {
|
if (read) {
|
||||||
@ -501,7 +501,7 @@ void CardReader::removeFile(const char * const name) {
|
|||||||
//stopSDPrint();
|
//stopSDPrint();
|
||||||
|
|
||||||
SdFile *curDir;
|
SdFile *curDir;
|
||||||
const char * const fname = diveToFile(curDir, name, false);
|
const char * const fname = diveToFile(curDir, name);
|
||||||
if (!fname) return;
|
if (!fname) return;
|
||||||
|
|
||||||
if (file.remove(curDir, fname)) {
|
if (file.remove(curDir, fname)) {
|
||||||
@ -641,15 +641,31 @@ uint16_t CardReader::getnrfilenames() {
|
|||||||
*
|
*
|
||||||
* A NULL result indicates an unrecoverable error.
|
* A NULL result indicates an unrecoverable error.
|
||||||
*/
|
*/
|
||||||
const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, const bool echo) {
|
const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, const bool echo/*=false*/) {
|
||||||
SdFile myDir;
|
// Track both parent and subfolder
|
||||||
if (path[0] != '/') { curDir = &workDir; return path; }
|
static SdFile newDir1, newDir2;
|
||||||
|
SdFile *sub = &newDir1, *startDir;
|
||||||
|
|
||||||
curDir = &root;
|
const char *dirname_start = path;
|
||||||
const char *dirname_start = &path[1];
|
char echo_fn[105];
|
||||||
|
|
||||||
|
if (path[0] == '/') {
|
||||||
|
curDir = &root;
|
||||||
|
workDirDepth = 0;
|
||||||
|
dirname_start++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
curDir = &workDir;
|
||||||
|
|
||||||
|
startDir = curDir;
|
||||||
|
|
||||||
|
// Start dive
|
||||||
while (dirname_start) {
|
while (dirname_start) {
|
||||||
|
// Find next sub
|
||||||
char * const dirname_end = strchr(dirname_start, '/');
|
char * const dirname_end = strchr(dirname_start, '/');
|
||||||
if (dirname_end <= dirname_start) break;
|
if (dirname_end <= dirname_start) break;
|
||||||
|
|
||||||
|
// Set subDirName
|
||||||
const uint8_t len = dirname_end - dirname_start;
|
const uint8_t len = dirname_end - dirname_start;
|
||||||
char dosSubdirname[len + 1];
|
char dosSubdirname[len + 1];
|
||||||
strncpy(dosSubdirname, dirname_start, len);
|
strncpy(dosSubdirname, dirname_start, len);
|
||||||
@ -657,11 +673,25 @@ const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, con
|
|||||||
|
|
||||||
if (echo) SERIAL_ECHOLN(dosSubdirname);
|
if (echo) SERIAL_ECHOLN(dosSubdirname);
|
||||||
|
|
||||||
if (!myDir.open(curDir, dosSubdirname, O_READ)) {
|
// Open curDir
|
||||||
|
if (!sub->open(curDir, dosSubdirname, O_READ)) {
|
||||||
SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, dosSubdirname, ".");
|
SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, dosSubdirname, ".");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
curDir = &myDir;
|
|
||||||
|
// Close curDir if not at starting-point
|
||||||
|
if (curDir != startDir) curDir->close();
|
||||||
|
|
||||||
|
// curDir now subDir
|
||||||
|
curDir = sub;
|
||||||
|
|
||||||
|
// Update workDirParents and workDirDepth
|
||||||
|
if (workDirDepth < MAX_DIR_DEPTH) workDirParents[workDirDepth++] = *curDir;
|
||||||
|
|
||||||
|
// Point sub pointer to unused newDir
|
||||||
|
sub = (curDir != &newDir1) ? &newDir1 : &newDir2;
|
||||||
|
|
||||||
|
// dirname_start point to next sub
|
||||||
dirname_start = dirname_end + 1;
|
dirname_start = dirname_end + 1;
|
||||||
}
|
}
|
||||||
return dirname_start;
|
return dirname_start;
|
||||||
|
@ -88,7 +88,7 @@ public:
|
|||||||
static int8_t updir();
|
static int8_t updir();
|
||||||
static void setroot();
|
static void setroot();
|
||||||
|
|
||||||
static const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo);
|
static const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo=false);
|
||||||
|
|
||||||
static uint16_t get_num_Files();
|
static uint16_t get_num_Files();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user