Browse Source

improved progress bar, use bubble sort, sort switch moved to settings menu, manage heater, host keepalive messages, timeout prolonged, setup screen improved

PavelSindler 6 years ago
parent
commit
a280447610

+ 4 - 4
Firmware/Configuration_adv.h

@@ -261,15 +261,15 @@
   #define SD_SORT_ALPHA 1
   #define SD_SORT_NONE 2
 
-  #define SDSORT_LIMIT       30    // Maximum number of sorted items (10-256).
-  #define FOLDER_SORTING     0     // -1=above  0=none  1=below
+  #define SDSORT_LIMIT       100    // Maximum number of sorted items (10-256).
+  #define FOLDER_SORTING     -1     // -1=above  0=none  1=below
   #define SDSORT_GCODE       false  // Allow turning sorting on/off with LCD and M34 g-code.
   #define SDSORT_USES_RAM    false  // Pre-allocate a static array for faster pre-sorting.
   #define SDSORT_USES_STACK  false  // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
   #define SDSORT_CACHE_NAMES false  // Keep sorted items in RAM longer for speedy performance. Most expensive option.
   #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
-  #define SDSORT_POINTERS	 false //stores adresses of filenames on stack	
-  #define QUICKSORT 
+
+ // #define SDSORT_QUICKSORT 
 #endif
 
 #if defined(SDCARD_SORT_ALPHA)

+ 2 - 2
Firmware/Marlin_main.cpp

@@ -1099,8 +1099,6 @@ void setup()
 	tp_init();    // Initialize temperature loop
 	plan_init();  // Initialize planner;
 	watchdog_init();
-    lcd_print_at_PGM(0, 1, PSTR("   Original Prusa   ")); // we need to do this again for some reason, no time to research
-    lcd_print_at_PGM(0, 2, PSTR("    3D  Printers    "));
 	st_init();    // Initialize stepper, this enables interrupts!
 	setup_photpin();
 	servo_init();
@@ -1197,6 +1195,8 @@ void setup()
 	card.ToshibaFlashAir_enable(eeprom_read_byte((unsigned char*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY) == 1);
 	// Force SD card update. Otherwise the SD card update is done from loop() on card.checkautostart(false), 
 	// but this times out if a blocking dialog is shown in setup().
+	lcd_print_at_PGM(0, 1, PSTR("   Original Prusa   ")); // we need to do this again for some reason, no time to research
+	lcd_print_at_PGM(0, 2, PSTR("    3D  Printers    "));
 	card.initsd();
 
 	if (eeprom_read_dword((uint32_t*)(EEPROM_TOP - 4)) == 0x0ffffffff &&

+ 0 - 17
Firmware/SdBaseFile.cpp

@@ -1114,28 +1114,17 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
   int16_t n;
   // if not a directory file or miss-positioned return an error
   if (!isDir() || (0X1F & curPosition_)) {
-	  SERIAL_ECHOLNPGM("return -1");
 	  return -1;
   }
   
   //If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
   if (longFilename != NULL)
   {
-	//  SERIAL_ECHOPGM("; reseting long filename; ");
   	longFilename[0] = '\0';
   }
-  //int i_pom = 0;
   while (1) {
     n = read(dir, sizeof(dir_t));
 
-	/*SERIAL_ECHOPGM("Jsem uvnitr: ");
-	MYSERIAL.print(n);
-	uint32_t pom = curPosition();
-	SERIAL_ECHOPGM(": ");
-	MYSERIAL.println(pom, 10);*/
-	//SERIAL_ECHOPGM("i: ");
-	//MYSERIAL.println(i_pom++);
-
     if (n != sizeof(dir_t)) return n == 0 ? 0 : -1;
     // last entry if DIR_NAME_FREE
 	if (dir->name[0] == DIR_NAME_FREE) {
@@ -1144,20 +1133,16 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
 	}
     // skip empty entries and entry for .  and ..
 	if (dir->name[0] == DIR_NAME_DELETED || dir->name[0] == '.') {
-		//SERIAL_ECHOLNPGM("Empty entry, . or ..");
 		continue;
 	}
     //Fill the long filename if we have a long filename entry,
 	// long filename entries are stored before the actual filename.
 	if (DIR_IS_LONG_NAME(dir) && longFilename != NULL)
     {
-		//SERIAL_ECHOLNPGM("We have long filename entry");
     	vfat_t *VFAT = (vfat_t*)dir;
 		//Sanity check the VFAT entry. The first cluster is always set to zero. And th esequence number should be higher then 0
     	if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES)
     	{
-			//SERIAL_ECHOPGM("VFAT Entries no:");
-			//MYSERIAL.println(VFAT->sequenceNumber & 0x1F);
 			//TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
     		n = ((VFAT->sequenceNumber & 0x1F) - 1) * 13;
 			longFilename[n+0] = VFAT->name1[0];
@@ -1176,8 +1161,6 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
 			//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';
-				//SERIAL_ECHOPGM("LOng F");
-				//MYSERIAL.println(longFilename);
 			}
 		}
     }

+ 80 - 150
Firmware/cardreader.cpp

@@ -97,20 +97,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
 	dir_t p;
 	uint8_t cnt = 0;
 
-	/*SERIAL_ECHOPGM("Cur pos. first: ");
-	uint32_t pom = parent.curPosition();
-	MYSERIAL.println(pom, 10);*/
-
 	// Read the next entry from a directory
 	while (parent.readDir(p, longFilename) > 0) {
-		//MYSERIAL.print(int(cnt));
-		//uint32_t pom = parent.curCluster();
-		//SERIAL_ECHOPGM(": ");
-		//MYSERIAL.print(pom, 10);
-		//SERIAL_ECHOPGM("; ");
-		//SERIAL_ECHOPGM("Cur pos.: ");
-		//uint32_t pom = parent.curPosition();
-		//MYSERIAL.println(pom, 10);
+		
 		// If the entry is a directory and the action is LS_SerialPrint
 		if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
 
@@ -171,25 +160,12 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
 				break;
 
 			case LS_GetFilename:
-				//SERIAL_ECHOPGM("File: ");				
 				createFilename(filename, p);
-				//MYSERIAL.println(p.name);
-				/*MYSERIAL.println(filename);
-				SERIAL_ECHOPGM("Write date: ");
-				writeDate = p.lastWriteDate;
-				MYSERIAL.println(writeDate);
-				writeTime = p.lastWriteTime;
-				SERIAL_ECHOPGM("Creation date: ");
-				MYSERIAL.println(p.creationDate);
-				SERIAL_ECHOPGM("Access date: ");
-				MYSERIAL.println(p.lastAccessDate);
-				SERIAL_ECHOLNPGM("");*/
 				cluster = parent.curCluster();
 				position = parent.curPosition();
 				creationDate = p.creationDate;
 				creationTime = p.creationTime;
-				//writeDate = p.lastAccessDate;
-				
+								
 				if (match != NULL) {
 					if (strcasecmp(match, filename) == 0) return;
 				}
@@ -672,16 +648,6 @@ void CardReader::closefile(bool store_location)
   
 }
 
-/*void CardReader::getfilename_adress(uint16_t nr, const char * const match)
-{
-	curDir = &workDir;
-	lsAction = LS_GetFilenameAdress;
-	nrFiles = nr;
-	curDir->rewind();
-	lsDive("", *curDir, match);
-
-}*/
-
 void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/)
 {
   curDir=&workDir;
@@ -697,7 +663,6 @@ void CardReader::getfilename_simple(uint32_t position, const char * const match/
 	curDir = &workDir;
 	lsAction = LS_GetFilename;
 	nrFiles = 0;
-	//curDir->rewind();
 	curDir->seekSet(position);
 	lsDive("", *curDir, match);	
 }
@@ -765,15 +730,14 @@ void CardReader::getfilename_sorted(const uint16_t nr) {
 	);
 }
 
-
-void CardReader::swap(uint8_t array[], uint8_t left, uint8_t right) {
-	uint8_t tmp = array[right];
-	array[right] = array[left];
-	array[left] = tmp;
-	//SERIAL_ECHOLNPGM("Did swap");
+#ifdef SDSORT_QUICKSORT
+void CardReader::swap(uint8_t left, uint8_t right) {
+	uint8_t tmp = sort_order[right];
+	sort_order[right] = sort_order[left];
+	sort_order[left] = tmp;
 }
 
-void CardReader::quicksort(uint8_t array[], uint8_t left, uint8_t right, uint32_t positions[]) {
+void CardReader::quicksort(uint8_t left, uint8_t right) {
 	if (left < right) {
 		char name_left[LONG_FILENAME_LENGTH + 1];
 		char name_i[LONG_FILENAME_LENGTH + 1];
@@ -782,37 +746,27 @@ void CardReader::quicksort(uint8_t array[], uint8_t left, uint8_t right, uint32_
 
 		uint8_t boundary = left;
 		for (uint8_t i = left+1; i < right; i++) {
-			uint8_t o_left = array[left];
-			uint8_t o_i = array[i];
+			uint8_t o_left = sort_order[left];
+			uint8_t o_i = sort_order[i];
 			getfilename_simple(positions[o_left]);
 			strcpy(name_left, LONGEST_FILENAME); // save (or getfilename below will trounce it)
 			creation_date_left = creationDate;
 			creation_time_left = creationTime;
 			getfilename_simple(positions[o_i]);
 			
-			/*SERIAL_ECHOLNPGM(" ");
-			MYSERIAL.print(int(o_left));
-			SERIAL_ECHOPGM(": ");
-			MYSERIAL.print(positions[o_left]);
-			SERIAL_ECHOPGM(": ");
-			MYSERIAL.println(name_left);
-			MYSERIAL.print(int(o_i));
-			SERIAL_ECHOPGM(": ");
-			MYSERIAL.print(positions[o_i]);
-			SERIAL_ECHOPGM(": ");
-			MYSERIAL.println(LONGEST_FILENAME);*/
 			strcpy(name_i, LONGEST_FILENAME);
 
 			
 			if (strcasecmp(name_left, name_i) > 0) {
-				swap(array, i, ++boundary);
+				swap(i, ++boundary);
 			}
 		}
-		swap(array, left, boundary);
-		quicksort(array, left, boundary, positions);
-		quicksort(array, boundary + 1, right, positions);
+		swap(left, boundary);
+		quicksort(left, boundary);
+		quicksort(boundary + 1, right);
 	}
 }
+#endif //SDSORT_QUICKSORT
 
 
 /**
@@ -824,22 +778,15 @@ void CardReader::quicksort(uint8_t array[], uint8_t left, uint8_t right, uint32_
 *  - Most RAM: Buffer the directory and return filenames from RAM
 */
 void CardReader::presort() {
-	
-	unsigned long start_time = millis();
-	if (farm_mode) return; //sorting is not used in farm mode
+	if (farm_mode || IS_SD_INSERTED == false) return; //sorting is not used in farm mode
 	uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
 	
 	if (sdSort == SD_SORT_NONE) return; //sd sort is turned off
-	#if !SDSORT_USES_RAM
-	  lcd_set_progress();
-	#endif
-	lcd_implementation_clear();
-	lcd_print_at_PGM(0, 1, MSG_SORTING);
 
 	#if SDSORT_GCODE
 	 if (!sort_alpha) return;
 	#endif
-
+	KEEPALIVE_STATE(IN_HANDLER);
 	// Throw away old sort index
 	flush_presort();
 
@@ -849,7 +796,15 @@ void CardReader::presort() {
 
 		// Never sort more than the max allowed
 		// If you use folders to organize, 20 may be enough
-		if (fileCnt > SDSORT_LIMIT) fileCnt = SDSORT_LIMIT;
+		if (fileCnt > SDSORT_LIMIT) {
+			lcd_show_fullscreen_message_and_wait_P(MSG_FILE_CNT);
+			fileCnt = SDSORT_LIMIT;
+		}
+		lcd_implementation_clear();
+		#if !SDSORT_USES_RAM
+		  lcd_set_progress();
+		#endif
+		lcd_print_at_PGM(0, 1, MSG_SORTING);
 
 		// Sort order is always needed. May be static or dynamic.
 		#if SDSORT_DYNAMIC_RAM
@@ -868,9 +823,8 @@ void CardReader::presort() {
 			#endif
 		  #elif SDSORT_USES_STACK
 			char sortnames[fileCnt][LONG_FILENAME_LENGTH];
-			uint16_t creation_time[SDSORT_LIMIT];
-			uint16_t creation_date[SDSORT_LIMIT];
-		  //#elif SDSORT_POINTERS
+			uint16_t creation_time[fileCnt];
+			uint16_t creation_date[fileCnt];
 		   
 		  #endif
 
@@ -884,10 +838,8 @@ void CardReader::presort() {
 		  #endif
 
 		#else // !SDSORT_USES_RAM
-		// uint32_t clusters [fileCnt];
-		 uint32_t positions [fileCnt];
-		// char *names[fileCnt];
 
+		  uint32_t positions[fileCnt];
 
 		  // By default re-read the names from SD for every compare
 		  // retaining only two filenames at a time. This is very
@@ -901,28 +853,12 @@ void CardReader::presort() {
 		if (fileCnt > 1) {
 			// Init sort order.
 			for (uint16_t i = 0; i < fileCnt; i++) {
+				manage_heater();
 				sort_order[i] = i;
-				/*MYSERIAL.print(i);
-				SERIAL_ECHOPGM(": ");
-				MYSERIAL.print(position);
-				SERIAL_ECHOPGM("; ");
-				MYSERIAL.print(cluster);
-				SERIAL_ECHOPGM(" ");*/
 
 				positions[i] = position;
 				getfilename(i);			
-				//MYSERIAL.print(LONGEST_FILENAME);
-				//names[i] = 
-				//clusters[i] = cluster;
-				//if (longFilename[0]) SERIAL_ECHOPGM("; Long; ");
 				
-				//MYSERIAL.println(i);
-				/*SERIAL_ECHOPGM("; ");
-				MYSERIAL.print(position);
-				SERIAL_ECHOPGM("; ");
-				MYSERIAL.print(positions[i]);
-				SERIAL_ECHOPGM("; ");
-				MYSERIAL.println(cluster);*/
 				// If using RAM then read all filenames now.
 				#if SDSORT_USES_RAM
 					getfilename(i);
@@ -953,63 +889,65 @@ void CardReader::presort() {
 					#endif
 				#endif
 			}
-			/*SERIAL_ECHOPGM("Mezicas:");
-			MYSERIAL.println(millis() - start_time);*/
-			
+						
 #ifdef QUICKSORT
-			quicksort(sort_order, 0, fileCnt - 1, positions);
+			quicksort(0, fileCnt - 1);
 #else //Qicksort not defined, use Bubble Sort
-			uint16_t counter = 0;
+			uint32_t counter = 0;
+			uint16_t total = 0.5*(fileCnt-1)*(fileCnt);
+
+			// Compare names from the array or just the two buffered names
+			#if SDSORT_USES_RAM
+			#define _SORT_CMP_NODIR() (strcasecmp(sortnames[o1], sortnames[o2]) > 0)
+			#define _SORT_CMP_TIME_NODIR() (((creation_date[o1] == creation_date[o2]) && (creation_time[o1] < creation_time[o2])) || \
+																	(creation_date[o1] < creation_date [o2]))
+			#else
+			#define _SORT_CMP_NODIR() (strcasecmp(name1, name2) > 0) //true if lowercase(name1) > lowercase(name2)
+			#define _SORT_CMP_TIME_NODIR() (((creation_date_bckp == creationDate) && (creation_time_bckp > creationTime)) || \
+																	(creation_date_bckp > creationDate))
+
+			#endif
+
+			#if HAS_FOLDER_SORTING
+			#if SDSORT_USES_RAM
+						// Folder sorting needs an index and bit to test for folder-ness.
+						const uint8_t ind1 = o1 >> 3, bit1 = o1 & 0x07,
+							ind2 = o2 >> 3, bit2 = o2 & 0x07;
+			#define _SORT_CMP_DIR(fs) \
+										  (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
+											? _SORT_CMP_NODIR() \
+											: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
+			#define _SORT_CMP_TIME_DIR(fs) \
+										  (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
+											? _SORT_CMP_TIME_NODIR() \
+											: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
+			#else
+			#define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
+			#define _SORT_CMP_TIME_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_TIME_NODIR() : (fs < 0 ? dir1 : !dir1))
+			#endif
+			#endif
+
 			for (uint16_t i = fileCnt; --i;) {
 				bool didSwap = false;
-
 				#if !SDSORT_USES_RAM //show progresss bar only if slow sorting method is used
-				   int8_t percent = ((counter * 100) / (fileCnt-1));
+				int8_t percent = (counter * 100) / total;//((counter * 100) / pow((fileCnt-1),2));
 				   for (int column = 0; column < 20; column++) {
 					   if (column < (percent/5)) lcd_implementation_print_at(column, 2, "\x01"); //simple progress bar
 				   }
-				  counter++;
+				  
 				#endif
 
 				//MYSERIAL.println(int(i));
 				for (uint16_t j = 0; j < i; ++j) {
+					manage_heater();
 					const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1];					
-					// Compare names from the array or just the two buffered names
-					#if SDSORT_USES_RAM
-						#define _SORT_CMP_NODIR() (strcasecmp(sortnames[o1], sortnames[o2]) > 0)
-						#define _SORT_CMP_TIME_NODIR() (((creation_date[o1] == creation_date[o2]) && (creation_time[o1] < creation_time[o2])) || \
-														(creation_date[o1] < creation_date [o2]))
-					#else
-						#define _SORT_CMP_NODIR() (strcasecmp(name1, name2) > 0) //true if lowercase(name1) > lowercase(name2)
-						#define _SORT_CMP_TIME_NODIR() (((creation_date_bckp == creationDate) && (creation_time_bckp < creationTime)) || \
-														(creation_date_bckp < creationDate))
-					#endif
-					 
-					#if HAS_FOLDER_SORTING
-						#if SDSORT_USES_RAM
-							// Folder sorting needs an index and bit to test for folder-ness.
-							const uint8_t ind1 = o1 >> 3, bit1 = o1 & 0x07,
-								ind2 = o2 >> 3, bit2 = o2 & 0x07;
-							#define _SORT_CMP_DIR(fs) \
-							  (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
-								? _SORT_CMP_NODIR() \
-								: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
-							#define _SORT_CMP_TIME_DIR(fs) \
-							  (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
-								? _SORT_CMP_TIME_NODIR() \
-								: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
-						#else
-							#define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
-							#define _SORT_CMP_TIME_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_TIME_NODIR() : (fs > 0 ? dir1 : !dir1))
-						#endif
-					#endif
+
 
 					// The most economical method reads names as-needed
 					// throughout the loop. Slow if there are many.
 					#if !SDSORT_USES_RAM
-
+						counter++;
 						getfilename_simple(positions[o1]);
-					//getfilename(o1);
 						strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
 						creation_date_bckp = creationDate;
 						creation_time_bckp = creationTime;
@@ -1017,14 +955,8 @@ void CardReader::presort() {
 							bool dir1 = filenameIsDir;
 						#endif
 						getfilename_simple(positions[o2]);
-						//	getfilename(o2);
-							char *name2 = LONGEST_FILENAME; // use the string in-place
+						char *name2 = LONGEST_FILENAME; // use the string in-place
 						
-						//SERIAL_ECHOPGM("NAMES:");
-						//MYSERIAL.println(name1);
-						//MYSERIAL.println(name2);
-							
-
 					#endif // !SDSORT_USES_RAM
 
 					// Sort the current pair according to settings.
@@ -1038,11 +970,8 @@ void CardReader::presort() {
 					{
 						sort_order[j] = o2;
 						sort_order[j + 1] = o1;
-						didSwap = true;
-						//SERIAL_ECHOLNPGM("did swap");
-						
+						didSwap = true;						
 					}
-					//SERIAL_ECHOLNPGM("");
 				}
 				if (!didSwap) break;
 			} //end of bubble sort loop
@@ -1077,14 +1006,15 @@ void CardReader::presort() {
 
 		sort_count = fileCnt;
 	}
-    #if !SDSORT_USES_RAM //show progresss bar only if slow sorting method is used
-	for(int column = 0; column <=19; column++ )	lcd_implementation_print_at(column, 2, "\x01"); //simple progress bar	
-	  delay(500);
-	  lcd_set_arrows();
+    #if !SDSORT_USES_RAM //show progress bar only if slow sorting method is used
+	  for (int column = 0; column <= 19; column++)	lcd_implementation_print_at(column, 2, "\x01"); //simple progress bar
+	  delay(300);
+	  lcd_set_degree();
+	  lcd_implementation_clear();
 	  lcd_update(2);
 	#endif
-	  SERIAL_ECHOPGM("Sort time:");
-	  MYSERIAL.println(millis() - start_time);
+	  KEEPALIVE_STATE(NOT_BUSY);
+	  lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
 }
 
 void CardReader::flush_presort() {

+ 4 - 2
Firmware/cardreader.h

@@ -45,8 +45,10 @@ public:
 
   #ifdef SDCARD_SORT_ALPHA
 	void presort();
-	void swap(uint8_t array[], uint8_t left, uint8_t right);
-	void quicksort(uint8_t array[], uint8_t left, uint8_t right, uint32_t positions[]);
+  #ifdef SDSORT_QUICKSORT
+	void swap(uint8_t left, uint8_t right);
+	void quicksort(uint8_t left, uint8_t right);
+  #endif //SDSORT_QUICKSORT
 	void getfilename_sorted(const uint16_t nr);
 	#if SDSORT_GCODE
 	  FORCE_INLINE void setSortOn(bool b) { sort_alpha = b; presort(); }

+ 5 - 0
Firmware/language_all.cpp

@@ -1092,6 +1092,11 @@ const char * const MSG_FILAMENT_LOADING_T3_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_FILAMENT_LOADING_T3_DE
 };
 
+const char MSG_FILE_CNT_EN[] PROGMEM = "Some files will not be sorted. Max. No. of files in 1 folder for sorting is 100.";
+const char * const MSG_FILE_CNT_LANG_TABLE[1] PROGMEM = {
+	MSG_FILE_CNT_EN
+};
+
 const char MSG_FILE_INCOMPLETE_EN[] PROGMEM = "File incomplete. Continue anyway?";
 const char * const MSG_FILE_INCOMPLETE_LANG_TABLE[1] PROGMEM = {
 	MSG_FILE_INCOMPLETE_EN

+ 2 - 0
Firmware/language_all.h

@@ -218,6 +218,8 @@ extern const char* const MSG_FILAMENT_LOADING_T2_LANG_TABLE[LANG_NUM];
 #define MSG_FILAMENT_LOADING_T2 LANG_TABLE_SELECT(MSG_FILAMENT_LOADING_T2_LANG_TABLE)
 extern const char* const MSG_FILAMENT_LOADING_T3_LANG_TABLE[LANG_NUM];
 #define MSG_FILAMENT_LOADING_T3 LANG_TABLE_SELECT(MSG_FILAMENT_LOADING_T3_LANG_TABLE)
+extern const char* const MSG_FILE_CNT_LANG_TABLE[1];
+#define MSG_FILE_CNT LANG_TABLE_SELECT_EXPLICIT(MSG_FILE_CNT_LANG_TABLE, 0)
 extern const char* const MSG_FILE_INCOMPLETE_LANG_TABLE[1];
 #define MSG_FILE_INCOMPLETE LANG_TABLE_SELECT_EXPLICIT(MSG_FILE_INCOMPLETE_LANG_TABLE, 0)
 extern const char* const MSG_FILE_PRINTED_LANG_TABLE[1];

+ 1 - 0
Firmware/language_en.h

@@ -340,3 +340,4 @@
 #define MSG_WIZARD_INSERT_CORRECT_FILAMENT			"Please load PLA filament and then resume Wizard by rebooting the printer."
 #define MSG_PLA_FILAMENT_LOADED				"Is PLA filament loaded?"
 #define MSG_PLEASE_LOAD_PLA					"Please load PLA filament first."
+#define(length=20, lines=4) MSG_FILE_CNT	"Some files will not be sorted. Max. No. of files in 1 folder for sorting is 100."

+ 27 - 37
Firmware/ultralcd.cpp

@@ -100,6 +100,10 @@ int8_t SilentModeMenu = 0;
 uint8_t snmm_extruder = 0;
 #endif
 
+#ifdef SDCARD_SORT_ALPHA
+bool presort_flag = false;
+#endif
+
 int lcd_commands_type=LCD_COMMAND_IDLE;
 int lcd_commands_step=0;
 bool isPrintPaused = false;
@@ -2743,7 +2747,6 @@ void EEPROM_read(int pos, uint8_t* value, uint8_t size)
 #ifdef SDCARD_SORT_ALPHA
 static void lcd_sort_type_set() {
 	uint8_t sdSort;
-	
 	EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
 	switch (sdSort) {
 	case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
@@ -2751,11 +2754,8 @@ static void lcd_sort_type_set() {
 	default: sdSort = SD_SORT_TIME;
 	}
 	eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
-	lcd_goto_menu(lcd_sdcard_menu, 1);
-	//lcd_update(2);
-	//delay(1000);
-	
-	card.presort();
+	presort_flag = true;
+	lcd_goto_menu(lcd_settings_menu, 8);
 }
 #endif //SDCARD_SORT_ALPHA
 
@@ -2776,8 +2776,8 @@ static void lcd_set_lang(unsigned char lang) {
 }
 
 #if !SDSORT_USES_RAM
-void lcd_set_arrows() {
-	void lcd_set_custom_characters_arrows();
+void lcd_set_degree() {
+	lcd_set_custom_characters_degree();
 }
 
 void lcd_set_progress() {
@@ -3181,6 +3181,17 @@ static void lcd_settings_menu()
   } else {
     MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
   }
+#ifdef SDCARD_SORT_ALPHA
+  if (!farm_mode) {
+	  uint8_t sdSort;
+	  EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
+	  switch (sdSort) {
+	  case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
+	  case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
+	  default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
+	  }
+  }
+#endif // SDCARD_SORT_ALPHA
     
     if (farm_mode)
     {
@@ -4695,8 +4706,13 @@ void getFileDescription(char *name, char *description) {
 
 void lcd_sdcard_menu()
 {	
-  uint8_t sdSort;
+  uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
+
   int tempScrool = 0;
+  if (presort_flag == true) {
+	  presort_flag = false;
+	  card.presort();	  
+  }
   if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
     //delay(100);
   return; // nothing to do (so don't thrash the SD card)
@@ -4704,16 +4720,6 @@ void lcd_sdcard_menu()
     
   START_MENU();
   MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
-  if (!farm_mode) {
-#ifdef SDCARD_SORT_ALPHA
-	  EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
-	  switch (sdSort) {
-	  case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
-	  case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
-	  default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
-	  }
-#endif // SDCARD_SORT_ALPHA
-  }
   card.getWorkDirName();
   if (card.filename[0] == '/')
   {
@@ -4728,14 +4734,8 @@ void lcd_sdcard_menu()
   {
     if (_menuItemNr == _lineNr)
     {
-		const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode) ? (fileCnt - 1 - i) : i;
+		uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
 
-		 /* #ifdef SDCARD_RATHERRECENTFIRST
-			#ifndef SDCARD_SORT_ALPHA
-				fileCnt - 1 -
-			#endif
-		  #endif
-		i;*/
 		#ifdef SDCARD_SORT_ALPHA
 		if (sdSort == SD_SORT_NONE) card.getfilename(nr);
 		else card.getfilename_sorted(nr);
@@ -4754,17 +4754,6 @@ void lcd_sdcard_menu()
   END_MENU();
 }
 
-//char description [10] [31];
-
-/*void get_description() {
-	uint16_t fileCnt = card.getnrfilenames();
-	for (uint16_t i = 0; i < fileCnt; i++)
-	{
-		card.getfilename(fileCnt - 1 - i);
-		getFileDescription(card.filename, description[i]);
-	}
-}*/
-
 /*void lcd_farm_sdcard_menu() 
 {
 	static int i = 0;
@@ -5771,6 +5760,7 @@ void lcd_update(uint8_t lcdDrawUpdateOverride)
         (*currentMenu)();
         menuExiting = false;
       }
+		  lcd_implementation_clear();
 		  lcd_return_to_status();
 		  lcdDrawUpdate = 2;
 	  }

+ 2 - 2
Firmware/ultralcd.h

@@ -75,7 +75,7 @@ void lcd_mylang();
   #define LCD_ALERTMESSAGERPGM(x) lcd_setalertstatuspgm((x))
 
   #define LCD_UPDATE_INTERVAL 100
-  #define LCD_TIMEOUT_TO_STATUS 15000
+  #define LCD_TIMEOUT_TO_STATUS 30000
 
   #ifdef ULTIPANEL
   void lcd_buttons_update();
@@ -265,7 +265,7 @@ void display_loading();
 void lcd_service_mode_show_result();
 
 #if !SDSORT_USES_RAM
-void lcd_set_arrows();
+void lcd_set_degree();
 void lcd_set_progress();
 #endif