From a5cd582665d7df9213d3ca18215c875c668f3a1b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 4 May 2013 04:18:02 -0700 Subject: [PATCH] Support for 10 level deep SD folder hierarchy --- Marlin/cardreader.cpp | 19 +++++++++++++------ Marlin/cardreader.h | 5 ++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 89a77b9c0..791c4bbe3 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -18,6 +18,8 @@ CardReader::CardReader() saving = false; logging = false; autostart_atmillis=0; + workDirDepth = 0; + memset(workDirParents, 0, sizeof(workDirParents)); autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. lastnr=0; @@ -521,19 +523,24 @@ void CardReader::chdir(const char * relpath) } else { - workDirParentParent=workDirParent; - workDirParent=*parent; - + if (workDirDepth < MAX_DIR_DEPTH) { + for (int d = ++workDirDepth; d--;) + workDirParents[d+1] = workDirParents[d]; + workDirParents[0]=*parent; + } workDir=newfile; } } void CardReader::updir() { - if(!workDir.isRoot()) + if(workDirDepth > 0) { - workDir=workDirParent; - workDirParent=workDirParentParent; + --workDirDepth; + workDir = workDirParents[0]; + int d; + for (int d = 0; d < workDirDepth; d++) + workDirParents[d] = workDirParents[d+1]; } } diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index fe5c8b723..6e5964529 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -3,6 +3,8 @@ #ifdef SDSUPPORT +#define MAX_DIR_DEPTH 10 + #include "SdFile.h" enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename}; class CardReader @@ -53,7 +55,8 @@ public: bool filenameIsDir; int lastnr; //last number of the autostart; private: - SdFile root,*curDir,workDir,workDirParent,workDirParentParent; + SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; + uint16_t workDirDepth; Sd2Card card; SdVolume volume; SdFile file;