From 1ed39133333ac534cd89c4dc9a6d3652cc08d0e0 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Jan 2015 22:55:13 -0800 Subject: [PATCH 1/2] Rename lastnr to autostart_index and... Replace instances of the number 13 with FILENAME_LENGTH where appropriate. --- Marlin/SdBaseFile.cpp | 6 +++--- Marlin/SdFatConfig.h | 8 +++++--- Marlin/cardreader.cpp | 18 +++++++++--------- Marlin/cardreader.h | 10 +++++----- Marlin/ultralcd.cpp | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Marlin/SdBaseFile.cpp b/Marlin/SdBaseFile.cpp index dbcf77fbdc..c72eced73c 100644 --- a/Marlin/SdBaseFile.cpp +++ b/Marlin/SdBaseFile.cpp @@ -1012,7 +1012,7 @@ void SdBaseFile::printFatTime( uint16_t fatTime) { * the value zero, false, is returned for failure. */ bool SdBaseFile::printName() { - char name[13]; + char name[FILENAME_LENGTH]; if (!getFilename(name)) return false; MYSERIAL.print(name); return true; @@ -1135,7 +1135,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) { if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES) { //TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table. - n = ((VFAT->sequenceNumber & 0x1F) - 1) * 13; + n = ((VFAT->sequenceNumber & 0x1F) - 1) * FILENAME_LENGTH; longFilename[n+0] = VFAT->name1[0]; longFilename[n+1] = VFAT->name1[1]; longFilename[n+2] = VFAT->name1[2]; @@ -1151,7 +1151,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) { longFilename[n+12] = VFAT->name3[1]; //If this VFAT entry is the last one, add a NUL terminator at the end of the string if (VFAT->sequenceNumber & 0x40) - longFilename[n+13] = '\0'; + longFilename[n+FILENAME_LENGTH] = '\0'; } } // return if normal file or subdirectory diff --git a/Marlin/SdFatConfig.h b/Marlin/SdFatConfig.h index 24caf6f3eb..a549835f70 100644 --- a/Marlin/SdFatConfig.h +++ b/Marlin/SdFatConfig.h @@ -108,15 +108,17 @@ uint8_t const SOFT_SPI_SCK_PIN = 13; * a pure virtual function is called. */ #define USE_CXA_PURE_VIRTUAL 1 + +/** Number of UTF-16 characters per entry */ +#define FILENAME_LENGTH 13 + /** * Defines for long (vfat) filenames */ /** Number of VFAT entries used. Every entry has 13 UTF-16 characters */ #define MAX_VFAT_ENTRIES (2) -/** Number of UTF-16 characters per entry */ -#define FILENAME_LENGTH 13 /** Total size of the buffer used to store the long filenames */ -#define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) +#define LONG_FILENAME_LENGTH (FILENAME_LENGTH*MAX_VFAT_ENTRIES+1) #endif // SdFatConfig_h diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index e22f3436b6..83671e00d0 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -23,7 +23,7 @@ CardReader::CardReader() memset(workDirParents, 0, sizeof(workDirParents)); 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; + autostart_index=0; //power to SD reader #if SDPOWER > -1 SET_OUTPUT(SDPOWER); @@ -60,8 +60,8 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename) // hence LS_SerialPrint { - char path[13*2]; - char lfilename[13]; + char path[FILENAME_LENGTH*2]; + char lfilename[FILENAME_LENGTH]; createFilename(lfilename,p); path[0]=0; @@ -241,7 +241,7 @@ void CardReader::getAbsFilename(char *t) while(*t!=0 && cnt< MAXPATHNAMELENGTH) {t++;cnt++;} //crawl counter forward. } - if(cnt0 && dirname_end>dirname_start) { - char subdirname[13]; + char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -408,7 +408,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[13]; + char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -510,7 +510,7 @@ void CardReader::checkautostart(bool force) } char autoname[30]; - sprintf_P(autoname, PSTR("auto%i.g"), lastnr); + sprintf_P(autoname, PSTR("auto%i.g"), autostart_index); for(int8_t i=0;i<(int8_t)strlen(autoname);i++) autoname[i]=tolower(autoname[i]); dir_t p; @@ -537,9 +537,9 @@ void CardReader::checkautostart(bool force) } } if(!found) - lastnr=-1; + autostart_index=-1; else - lastnr++; + autostart_index++; } void CardReader::closefile(bool store_location) diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index e513dc064f..a1da3d64a3 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -50,12 +50,12 @@ public: public: bool saving; bool logging; - bool sdprinting ; - bool cardOK ; - char filename[13]; + bool sdprinting; + bool cardOK; + char filename[FILENAME_LENGTH]; char longFilename[LONG_FILENAME_LENGTH]; bool filenameIsDir; - int lastnr; //last number of the autostart; + int autostart_index; private: SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; uint16_t workDirDepth; @@ -63,7 +63,7 @@ private: SdVolume volume; SdFile file; #define SD_PROCEDURE_DEPTH 1 - #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) + #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) uint8_t file_subcall_ctr; uint32_t filespos[SD_PROCEDURE_DEPTH]; char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 0f7645c873..a1ee315155 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -377,7 +377,7 @@ static void lcd_main_menu() #ifdef SDSUPPORT static void lcd_autostart_sd() { - card.lastnr=0; + card.autostart_index=0; card.setroot(); card.checkautostart(true); } From 03c9cb60e89e99cbd05377cdd0a5e7ad043a288d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Jan 2015 22:55:13 -0800 Subject: [PATCH 2/2] Rename lastnr to autostart_index and... Replace instances of the number 13 with FILENAME_LENGTH where appropriate. --- Marlin/SdBaseFile.cpp | 6 +++--- Marlin/SdFatConfig.h | 8 +++++--- Marlin/cardreader.cpp | 18 +++++++++--------- Marlin/cardreader.h | 10 +++++----- Marlin/ultralcd.cpp | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Marlin/SdBaseFile.cpp b/Marlin/SdBaseFile.cpp index dbcf77fbdc..c72eced73c 100644 --- a/Marlin/SdBaseFile.cpp +++ b/Marlin/SdBaseFile.cpp @@ -1012,7 +1012,7 @@ void SdBaseFile::printFatTime( uint16_t fatTime) { * the value zero, false, is returned for failure. */ bool SdBaseFile::printName() { - char name[13]; + char name[FILENAME_LENGTH]; if (!getFilename(name)) return false; MYSERIAL.print(name); return true; @@ -1135,7 +1135,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) { if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES) { //TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table. - n = ((VFAT->sequenceNumber & 0x1F) - 1) * 13; + n = ((VFAT->sequenceNumber & 0x1F) - 1) * FILENAME_LENGTH; longFilename[n+0] = VFAT->name1[0]; longFilename[n+1] = VFAT->name1[1]; longFilename[n+2] = VFAT->name1[2]; @@ -1151,7 +1151,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) { longFilename[n+12] = VFAT->name3[1]; //If this VFAT entry is the last one, add a NUL terminator at the end of the string if (VFAT->sequenceNumber & 0x40) - longFilename[n+13] = '\0'; + longFilename[n+FILENAME_LENGTH] = '\0'; } } // return if normal file or subdirectory diff --git a/Marlin/SdFatConfig.h b/Marlin/SdFatConfig.h index 24caf6f3eb..a549835f70 100644 --- a/Marlin/SdFatConfig.h +++ b/Marlin/SdFatConfig.h @@ -108,15 +108,17 @@ uint8_t const SOFT_SPI_SCK_PIN = 13; * a pure virtual function is called. */ #define USE_CXA_PURE_VIRTUAL 1 + +/** Number of UTF-16 characters per entry */ +#define FILENAME_LENGTH 13 + /** * Defines for long (vfat) filenames */ /** Number of VFAT entries used. Every entry has 13 UTF-16 characters */ #define MAX_VFAT_ENTRIES (2) -/** Number of UTF-16 characters per entry */ -#define FILENAME_LENGTH 13 /** Total size of the buffer used to store the long filenames */ -#define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) +#define LONG_FILENAME_LENGTH (FILENAME_LENGTH*MAX_VFAT_ENTRIES+1) #endif // SdFatConfig_h diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index e22f3436b6..83671e00d0 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -23,7 +23,7 @@ CardReader::CardReader() memset(workDirParents, 0, sizeof(workDirParents)); 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; + autostart_index=0; //power to SD reader #if SDPOWER > -1 SET_OUTPUT(SDPOWER); @@ -60,8 +60,8 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename) // hence LS_SerialPrint { - char path[13*2]; - char lfilename[13]; + char path[FILENAME_LENGTH*2]; + char lfilename[FILENAME_LENGTH]; createFilename(lfilename,p); path[0]=0; @@ -241,7 +241,7 @@ void CardReader::getAbsFilename(char *t) while(*t!=0 && cnt< MAXPATHNAMELENGTH) {t++;cnt++;} //crawl counter forward. } - if(cnt0 && dirname_end>dirname_start) { - char subdirname[13]; + char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -408,7 +408,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[13]; + char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end-dirname_start); subdirname[dirname_end-dirname_start]=0; SERIAL_ECHOLN(subdirname); @@ -510,7 +510,7 @@ void CardReader::checkautostart(bool force) } char autoname[30]; - sprintf_P(autoname, PSTR("auto%i.g"), lastnr); + sprintf_P(autoname, PSTR("auto%i.g"), autostart_index); for(int8_t i=0;i<(int8_t)strlen(autoname);i++) autoname[i]=tolower(autoname[i]); dir_t p; @@ -537,9 +537,9 @@ void CardReader::checkautostart(bool force) } } if(!found) - lastnr=-1; + autostart_index=-1; else - lastnr++; + autostart_index++; } void CardReader::closefile(bool store_location) diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index e513dc064f..a1da3d64a3 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -50,12 +50,12 @@ public: public: bool saving; bool logging; - bool sdprinting ; - bool cardOK ; - char filename[13]; + bool sdprinting; + bool cardOK; + char filename[FILENAME_LENGTH]; char longFilename[LONG_FILENAME_LENGTH]; bool filenameIsDir; - int lastnr; //last number of the autostart; + int autostart_index; private: SdFile root,*curDir,workDir,workDirParents[MAX_DIR_DEPTH]; uint16_t workDirDepth; @@ -63,7 +63,7 @@ private: SdVolume volume; SdFile file; #define SD_PROCEDURE_DEPTH 1 - #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) + #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) uint8_t file_subcall_ctr; uint32_t filespos[SD_PROCEDURE_DEPTH]; char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 0f7645c873..a1ee315155 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -377,7 +377,7 @@ static void lcd_main_menu() #ifdef SDSUPPORT static void lcd_autostart_sd() { - card.lastnr=0; + card.autostart_index=0; card.setroot(); card.checkautostart(true); }