Browse Source

Fix bug: diveToFile breaks M23 (#13865)

Robby Candra 5 years ago
parent
commit
c369477cb0

+ 0
- 1
Marlin/src/feature/power_loss_recovery.cpp View File

392
 
392
 
393
   // Resume the SD file from the last position
393
   // Resume the SD file from the last position
394
   char *fn = info.sd_filename;
394
   char *fn = info.sd_filename;
395
-  while (*fn == '/') fn++;
396
   sprintf_P(cmd, PSTR("M23 %s"), fn);
395
   sprintf_P(cmd, PSTR("M23 %s"), fn);
397
   gcode.process_subcommands_now(cmd);
396
   gcode.process_subcommands_now(cmd);
398
   sprintf_P(cmd, PSTR("M24 S%ld T%ld"), info.sdpos, info.print_job_elapsed);
397
   sprintf_P(cmd, PSTR("M24 S%ld T%ld"), info.sdpos, info.print_job_elapsed);

+ 2
- 0
Marlin/src/gcode/sdcard/M23.cpp View File

29
 
29
 
30
 /**
30
 /**
31
  * M23: Open a file
31
  * M23: Open a file
32
+ *
33
+ * The path is relative to the root directory
32
  */
34
  */
33
 void GcodeSuite::M23() {
35
 void GcodeSuite::M23() {
34
   // Simplify3D includes the size, so zero out all spaces (#7227)
36
   // Simplify3D includes the size, so zero out all spaces (#7227)

+ 39
- 9
Marlin/src/sd/cardreader.cpp View File

461
   stopSDPrint();
461
   stopSDPrint();
462
 
462
 
463
   SdFile *curDir;
463
   SdFile *curDir;
464
-  const char * const fname = diveToFile(curDir, path, false);
464
+  const char * const fname = diveToFile(curDir, path);
465
   if (!fname) return;
465
   if (!fname) return;
466
 
466
 
467
   if (read) {
467
   if (read) {
501
   //stopSDPrint();
501
   //stopSDPrint();
502
 
502
 
503
   SdFile *curDir;
503
   SdFile *curDir;
504
-  const char * const fname = diveToFile(curDir, name, false);
504
+  const char * const fname = diveToFile(curDir, name);
505
   if (!fname) return;
505
   if (!fname) return;
506
 
506
 
507
   if (file.remove(curDir, fname)) {
507
   if (file.remove(curDir, fname)) {
641
  *
641
  *
642
  * A NULL result indicates an unrecoverable error.
642
  * A NULL result indicates an unrecoverable error.
643
  */
643
  */
644
-const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, const bool echo) {
645
-  SdFile myDir;
646
-  if (path[0] != '/') { curDir = &workDir; return path; }
644
+const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, const bool echo/*=false*/) {
645
+  // Track both parent and subfolder
646
+  static SdFile newDir1, newDir2;
647
+  SdFile *sub = &newDir1, *startDir;
648
+
649
+  const char *dirname_start = path;
650
+  char echo_fn[105];
651
+  
652
+  if (path[0] == '/') { 
653
+    curDir = &root;
654
+    workDirDepth = 0;
655
+    dirname_start++;
656
+  }
657
+  else
658
+    curDir = &workDir; 
659
+
660
+  startDir = curDir;
647
 
661
 
648
-  curDir = &root;
649
-  const char *dirname_start = &path[1];
662
+  // Start dive
650
   while (dirname_start) {
663
   while (dirname_start) {
664
+    // Find next sub
651
     char * const dirname_end = strchr(dirname_start, '/');
665
     char * const dirname_end = strchr(dirname_start, '/');
652
     if (dirname_end <= dirname_start) break;
666
     if (dirname_end <= dirname_start) break;
667
+
668
+    // Set subDirName
653
     const uint8_t len = dirname_end - dirname_start;
669
     const uint8_t len = dirname_end - dirname_start;
654
     char dosSubdirname[len + 1];
670
     char dosSubdirname[len + 1];
655
     strncpy(dosSubdirname, dirname_start, len);
671
     strncpy(dosSubdirname, dirname_start, len);
657
 
673
 
658
     if (echo) SERIAL_ECHOLN(dosSubdirname);
674
     if (echo) SERIAL_ECHOLN(dosSubdirname);
659
 
675
 
660
-    if (!myDir.open(curDir, dosSubdirname, O_READ)) {
676
+    // Open curDir
677
+    if (!sub->open(curDir, dosSubdirname, O_READ)) {
661
       SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, dosSubdirname, ".");
678
       SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, dosSubdirname, ".");
662
       return NULL;
679
       return NULL;
663
     }
680
     }
664
-    curDir = &myDir;
681
+
682
+    // Close curDir if not at starting-point
683
+    if (curDir != startDir) curDir->close();
684
+
685
+    // curDir now subDir
686
+    curDir = sub;
687
+
688
+    // Update workDirParents and workDirDepth
689
+    if (workDirDepth < MAX_DIR_DEPTH) workDirParents[workDirDepth++] = *curDir;
690
+
691
+    // Point sub pointer to unused newDir
692
+    sub = (curDir != &newDir1) ? &newDir1 : &newDir2;
693
+
694
+    // dirname_start point to next sub
665
     dirname_start = dirname_end + 1;
695
     dirname_start = dirname_end + 1;
666
   }
696
   }
667
   return dirname_start;
697
   return dirname_start;

+ 1
- 1
Marlin/src/sd/cardreader.h View File

88
   static int8_t updir();
88
   static int8_t updir();
89
   static void setroot();
89
   static void setroot();
90
 
90
 
91
-  static const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo);
91
+  static const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo=false);
92
 
92
 
93
   static uint16_t get_num_Files();
93
   static uint16_t get_num_Files();
94
 
94
 

Loading…
Cancel
Save