From ab355a90d33ed457d964fe97f675f79720863585 Mon Sep 17 00:00:00 2001 From: alexborro Date: Wed, 17 Dec 2014 14:50:59 -0200 Subject: [PATCH] Revert "SD Sort and Buffer" --- Marlin/Configuration_adv.h | 1 - Marlin/SdFatConfig.h | 4 +- Marlin/cardreader.cpp | 219 +++--------------- Marlin/cardreader.h | 36 +-- .../SCARA/Configuration_adv.h | 1 - .../delta/Configuration_adv.h | 1 - .../makibox/Configuration_adv.h | 1 - Marlin/ultralcd.cpp | 29 +-- 8 files changed, 52 insertions(+), 240 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index d0f988c179..bce45851df 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -292,7 +292,6 @@ #define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. -//#define SDCARD_SORT_ALPHA // Sort SD file listings in ASCII order. Find additional options in cardreader.h #define SDCARD_RATHERRECENTFIRST //reverse file order of sd card menu display. Its sorted practically after the file system block order. // if a file is deleted, it frees a block. hence, the order is not purely chronological. To still have auto0.g accessible, there is again the option to do that. // using: diff --git a/Marlin/SdFatConfig.h b/Marlin/SdFatConfig.h index 39ef381300..710b1f7924 100644 --- a/Marlin/SdFatConfig.h +++ b/Marlin/SdFatConfig.h @@ -111,12 +111,10 @@ uint8_t const SOFT_SPI_SCK_PIN = 13; /** * Defines for long (vfat) filenames */ -/** Number of UTF-16 characters per entry */ -#define FILENAME_LENGTH 13 /** Number of VFAT entries used. Every entry has 13 UTF-16 characters */ #define MAX_VFAT_ENTRIES (2) /** Total size of the buffer used to store the long filenames */ -#define LONG_FILENAME_LENGTH (FILENAME_LENGTH*MAX_VFAT_ENTRIES+1) +#define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) #endif // SdFatConfig_h diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 57a91040b3..d2fb418fba 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -11,9 +11,6 @@ CardReader::CardReader() { - #ifdef SDCARD_SORT_ALPHA - sort_count = 0; - #endif filesize = 0; sdpos = 0; sdprinting = false; @@ -36,15 +33,19 @@ CardReader::CardReader() autostart_atmillis=millis()+5000; } -char *createFilename(char *buffer, const dir_t &p) //buffer>12characters +char *createFilename(char *buffer,const dir_t &p) //buffer>12characters { char *pos=buffer; - for (uint8_t i = 0; i < 11; i++) { - if (p.name[i] == ' ') continue; - if (i == 8) *pos++ = '.'; - *pos++ = p.name[i]; + for (uint8_t i = 0; i < 11; i++) + { + if (p.name[i] == ' ')continue; + if (i == 8) + { + *pos++='.'; + } + *pos++=p.name[i]; } - *pos++ = 0; + *pos++=0; return buffer; } @@ -52,15 +53,15 @@ char *createFilename(char *buffer, const dir_t &p) //buffer>12characters void CardReader::lsDive(const char *prepend,SdFile parent) { dir_t p; - uint8_t cnt=0; + uint8_t cnt=0; while (parent.readDir(p, longFilename) > 0) { if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename) // hence LS_SerialPrint { - char path[FILENAME_LENGTH*2]; - char lfilename[FILENAME_LENGTH]; + char path[13*2]; + char lfilename[13]; createFilename(lfilename,p); path[0]=0; @@ -86,6 +87,8 @@ void CardReader::lsDive(const char *prepend,SdFile parent) } lsDive(path,dir); //close done automatically by destructor of SdFile + + } else { @@ -98,10 +101,11 @@ void CardReader::lsDive(const char *prepend,SdFile parent) if ( p.name[1] != '.') continue; } - + if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue; filenameIsDir=DIR_IS_SUBDIR(&p); - + + if(!filenameIsDir) { if(p.name[8]!='G') continue; @@ -120,8 +124,10 @@ void CardReader::lsDive(const char *prepend,SdFile parent) } else if(lsAction==LS_GetFilename) { - if (cnt == nrFiles) return; + if(cnt==nrFiles) + return; cnt++; + } } } @@ -130,6 +136,9 @@ void CardReader::lsDive(const char *prepend,SdFile parent) void CardReader::ls() { lsAction=LS_SerialPrint; + if(lsAction==LS_Count) + nrFiles=0; + root.rewind(); lsDive("",root); } @@ -168,9 +177,6 @@ void CardReader::initsd() } workDir=root; curDir=&root; - #ifdef SDCARD_SORT_ALPHA - presort(); - #endif /* if(!workDir.openRoot(&volume)) { @@ -187,10 +193,8 @@ void CardReader::setroot() SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL); }*/ workDir=root; + curDir=&workDir; - #ifdef SDCARD_SORT_ALPHA - presort(); - #endif } void CardReader::release() { @@ -203,7 +207,6 @@ void CardReader::startFileprint() if(cardOK) { sdprinting = true; - flush_presort(); } } @@ -232,7 +235,7 @@ void CardReader::getAbsFilename(char *t) while(*t!=0 && cnt< MAXPATHNAMELENGTH) {t++;cnt++;} //crawl counter forward. } - if(cnt0 && dirname_end>dirname_start) { - char subdirname[FILENAME_LENGTH]; + char subdirname[13]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -398,7 +401,7 @@ void CardReader::removeFile(char* name) //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name)); if(dirname_end>0 && dirname_end>dirname_start) { - char subdirname[FILENAME_LENGTH]; + char subdirname[13]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -436,9 +439,6 @@ void CardReader::removeFile(char* name) SERIAL_PROTOCOLPGM("File deleted:"); SERIAL_PROTOCOLLN(fname); sdpos = 0; - #ifdef SDCARD_SORT_ALPHA - presort(); - #endif } else { @@ -552,21 +552,14 @@ void CardReader::closefile(bool store_location) } -void CardReader::getfilename(const uint16_t nr) +void CardReader::getfilename(const uint8_t nr) { - #if defined(SDCARD_SORT_ALPHA) && SORT_USES_RAM && SORT_USES_MORE_RAM - if (nr < sort_count) { - strcpy(filename, sortshort[nr]); - strcpy(longFilename, sortnames[nr]); - filenameIsDir = isDir[nr]; - return; - } - #endif curDir=&workDir; lsAction=LS_GetFilename; nrFiles=nr; curDir->rewind(); lsDive("",*curDir); + } uint16_t CardReader::getnrfilenames() @@ -584,7 +577,7 @@ void CardReader::chdir(const char * relpath) { SdFile newfile; SdFile *parent=&root; - + if(workDir.isOpen()) parent=&workDir; @@ -602,164 +595,21 @@ void CardReader::chdir(const char * relpath) workDirParents[0]=*parent; } workDir=newfile; - #ifdef SDCARD_SORT_ALPHA - presort(); - #endif } } void CardReader::updir() { - if (workDirDepth > 0) + if(workDirDepth > 0) { --workDirDepth; workDir = workDirParents[0]; + int d; for (int d = 0; d < workDirDepth; d++) workDirParents[d] = workDirParents[d+1]; - #ifdef SDCARD_SORT_ALPHA - presort(); - #endif } } -#ifdef SDCARD_SORT_ALPHA - -/** - * Get the name of a file in the current directory by sort-index - */ -void CardReader::getfilename_sorted(const uint16_t nr) { - getfilename(nr < sort_count ? sort_order[nr] : nr); -} - -/** - * Read all the files and produce a sort key - * - * We can do this in 3 ways... - * - Minimal RAM: Read two filenames at a time sorting along... - * - Some RAM: Buffer the directory and return filenames from RAM - * - Some RAM: Buffer the directory just for this sort - */ -void CardReader::presort() -{ - flush_presort(); - - uint16_t fileCnt = getnrfilenames(); - if (fileCnt > 0) { - - if (fileCnt > SORT_LIMIT) fileCnt = SORT_LIMIT; - - #if SORT_USES_RAM - #if SORT_USES_MORE_RAM - sortshort = (char**)calloc(fileCnt, sizeof(char*)); - sortnames = (char**)calloc(fileCnt, sizeof(char*)); - #else - char *sortnames[fileCnt]; - #endif - #else - char name1[LONG_FILENAME_LENGTH+1]; - #endif - - #if FOLDER_SORTING != 0 - #if SORT_USES_RAM && SORT_USES_MORE_RAM - isDir = (uint8_t*)calloc(fileCnt, sizeof(uint8_t)); - #else - uint8_t isDir[fileCnt]; - #endif - #endif - - sort_order = new uint8_t[fileCnt]; - - if (fileCnt > 1) { - - // Init sort order. If using RAM then read all filenames now. - for (uint16_t i=0; i 0) : isDir[FOLDER_SORTING > 0 ? o1 : o2]; - #else - cmp = strcasecmp(sortnames[o1], sortnames[o2]) > 0; - #endif - #else - getfilename(o1); - strcpy(name1, longFilename[0] ? longFilename : filename); - #if FOLDER_SORTING != 0 - bool dir1 = filenameIsDir; - #endif - getfilename(o2); - char *name2 = longFilename[0] ? longFilename : filename; - #if FOLDER_SORTING != 0 - cmp = (dir1 == filenameIsDir) ? (strcasecmp(name1, name2) > 0) : (FOLDER_SORTING > 0 ? dir1 : !dir1); - #else - cmp = strcasecmp(name1, name2) > 0; - #endif - #endif - if (cmp) { - sort_order[s1] = o2; - sort_order[s2] = o1; - didSwap = true; - } - } - if (!didSwap) break; - } - - #if SORT_USES_RAM && !SORT_USES_MORE_RAM - for (uint16_t i=0; i 0) { - #if SORT_USES_RAM && SORT_USES_MORE_RAM - for (uint8_t i=0; i=filesize ;}; @@ -63,29 +50,20 @@ public: public: bool saving; bool logging; - bool sdprinting; - bool cardOK; - char filename[FILENAME_LENGTH]; + bool sdprinting ; + bool cardOK ; + char filename[13]; char longFilename[LONG_FILENAME_LENGTH]; bool filenameIsDir; int lastnr; //last number of the autostart; private: SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; uint16_t workDirDepth; -#ifdef SDCARD_SORT_ALPHA - uint16_t sort_count; - uint8_t *sort_order; - #if SORT_USES_MORE_RAM - char **sortshort; - char **sortnames; - uint8_t *isDir; - #endif -#endif Sd2Card card; SdVolume volume; SdFile file; #define SD_PROCEDURE_DEPTH 1 - #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) + #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) uint8_t file_subcall_ctr; uint32_t filespos[SD_PROCEDURE_DEPTH]; char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; @@ -97,7 +75,7 @@ private: bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. LsAction lsAction; //stored for recursion. - uint16_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; void lsDive(const char *prepend,SdFile parent); }; diff --git a/Marlin/example_configurations/SCARA/Configuration_adv.h b/Marlin/example_configurations/SCARA/Configuration_adv.h index 10fbe9b316..7a01bccb6c 100644 --- a/Marlin/example_configurations/SCARA/Configuration_adv.h +++ b/Marlin/example_configurations/SCARA/Configuration_adv.h @@ -295,7 +295,6 @@ #define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. -//#define SDCARD_SORT_ALPHA // Sort SD file listings in ASCII order. Find additional options in cardreader.h #define SDCARD_RATHERRECENTFIRST //reverse file order of sd card menu display. Its sorted practically after the file system block order. // if a file is deleted, it frees a block. hence, the order is not purely chronological. To still have auto0.g accessible, there is again the option to do that. // using: diff --git a/Marlin/example_configurations/delta/Configuration_adv.h b/Marlin/example_configurations/delta/Configuration_adv.h index 6c9d56886d..ee42481be1 100644 --- a/Marlin/example_configurations/delta/Configuration_adv.h +++ b/Marlin/example_configurations/delta/Configuration_adv.h @@ -287,7 +287,6 @@ #define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. -//#define SDCARD_SORT_ALPHA // Sort SD file listings in ASCII order. Find additional options in cardreader.h #define SDCARD_RATHERRECENTFIRST //reverse file order of sd card menu display. Its sorted practically after the filesystem block order. // if a file is deleted, it frees a block. hence, the order is not purely cronological. To still have auto0.g accessible, there is again the option to do that. // using: diff --git a/Marlin/example_configurations/makibox/Configuration_adv.h b/Marlin/example_configurations/makibox/Configuration_adv.h index 312b2b9647..7883c79996 100644 --- a/Marlin/example_configurations/makibox/Configuration_adv.h +++ b/Marlin/example_configurations/makibox/Configuration_adv.h @@ -291,7 +291,6 @@ #define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. -//#define SDCARD_SORT_ALPHA // Sort SD file listings in ASCII order. Find additional options in cardreader.h #define SDCARD_RATHERRECENTFIRST //reverse file order of sd card menu display. Its sorted practically after the file system block order. // if a file is deleted, it frees a block. hence, the order is not purely chronological. To still have auto0.g accessible, there is again the option to do that. // using: diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 513f493bb6..550b9cb0b0 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -993,9 +993,9 @@ void lcd_sdcard_menu() card.getWorkDirName(); if(card.filename[0]=='/') { - #if SDCARDDETECT == -1 +#if SDCARDDETECT == -1 MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh); - #endif +#endif }else{ MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir); } @@ -1004,23 +1004,16 @@ void lcd_sdcard_menu() { if (_menuItemNr == _lineNr) { - #if defined(SDCARD_RATHERRECENTFIRST) && !defined(SDCARD_SORT_ALPHA) - int nr = fileCnt-1-i; + #ifndef SDCARD_RATHERRECENTFIRST + card.getfilename(i); #else - int nr = i; + card.getfilename(fileCnt-1-i); #endif - - #ifdef SDCARD_SORT_ALPHA - card.getfilename_sorted(nr); - #else - card.getfilename(nr); - #endif - - if (card.filenameIsDir) { - MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename); - } - else { - MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename); + if (card.filenameIsDir) + { + MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename); + }else{ + MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename); } }else{ MENU_ITEM_DUMMY(); @@ -1226,7 +1219,7 @@ void lcd_init() #endif // SR_LCD_2W_NL #endif//!NEWPANEL -#if defined(SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0) +#if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0) pinMode(SDCARDDETECT,INPUT); WRITE(SDCARDDETECT, HIGH); lcd_oldcardstatus = IS_SD_INSERTED;