Browse Source

Merge branch 'MK3_ShellSort' into MK3_NEW_SD_COMPILATION

Alex Voinea 4 years ago
parent
commit
7028583e9b
6 changed files with 78 additions and 34 deletions
  1. 2 0
      Firmware/Configuration_adv.h
  2. 75 5
      Firmware/cardreader.cpp
  3. 0 15
      Firmware/lcd.cpp
  4. 0 1
      Firmware/lcd.h
  5. 1 10
      Firmware/ultralcd.cpp
  6. 0 3
      Firmware/ultralcd.h

+ 2 - 0
Firmware/Configuration_adv.h

@@ -236,6 +236,8 @@
 	  #define SD_SORT_TIME 0
 	  #define SD_SORT_ALPHA 1
 	  #define SD_SORT_NONE 2
+	  #define SHELLSORT
+	  // #define SORTING_DUMP
 	
 	  #define SDSORT_LIMIT       100    // Maximum number of sorted items (10-256).
 	  #define FOLDER_SORTING     -1     // -1=above  0=none  1=below

+ 75 - 5
Firmware/cardreader.cpp

@@ -739,7 +739,6 @@ void CardReader::presort() {
 			fileCnt = SDSORT_LIMIT;
 		}
 		lcd_clear();
-        lcd_set_progress();
 		lcd_puts_at_P(0, 1, _i("Sorting files"));////MSG_SORTING c=20 r=1
 
 		// uint32_t positions[fileCnt];
@@ -764,7 +763,72 @@ void CardReader::presort() {
 
 #ifdef QUICKSORT
 			quicksort(0, fileCnt - 1);
-#else //Qicksort not defined, use Bubble Sort
+#elif defined(SHELLSORT)
+
+#define _SORT_CMP_NODIR() (strcasecmp(name2, name1) > 0)
+#define _SORT_CMP_TIME_NODIR() (((modification_date_bckp == modificationDate) && (modification_time_bckp < modificationTime)) || (modification_date_bckp < modificationDate))
+#if HAS_FOLDER_SORTING
+#define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? filenameIsDir : !filenameIsDir))
+#define _SORT_CMP_TIME_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_TIME_NODIR() : (fs < 0 ? filenameIsDir : !filenameIsDir))
+#endif
+
+			uint16_t counter = 0;
+			uint16_t total = 0;
+			for (uint16_t i = fileCnt/2; i > 0; i /= 2) total += fileCnt - i; //total runs for progress bar
+			
+			for (uint16_t gap = fileCnt/2; gap > 0; gap /= 2)
+			{
+				for (uint16_t i = gap; i < fileCnt; i++)
+				{
+					if (!IS_SD_INSERTED) return;
+					
+					int8_t percent = (counter * 100) / total;
+					for (int column = 0; column < 20; column++) {
+						if (column < (percent / 5))
+						{
+							lcd_set_cursor(column, 2);
+							lcd_print('\xFF'); //simple progress bar
+						}
+					}
+					counter++;
+					
+					manage_heater();
+					uint8_t orderBckp = sort_order[i];
+					getfilename_simple(positions[orderBckp]);
+					strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
+					modification_date_bckp = modificationDate;
+					modification_time_bckp = modificationTime;
+					#if HAS_FOLDER_SORTING
+					bool dir1 = filenameIsDir;
+					#endif
+					
+					uint16_t j = i;
+					getfilename_simple(positions[sort_order[j - gap]]);
+					char *name2 = LONGEST_FILENAME; // use the string in-place
+					#if HAS_FOLDER_SORTING
+					while (j >= gap && ((sdSort == SD_SORT_TIME)?_SORT_CMP_TIME_DIR(FOLDER_SORTING):_SORT_CMP_DIR(FOLDER_SORTING)))
+					#else
+					while (j >= gap && ((sdSort == SD_SORT_TIME)?_SORT_CMP_TIME_NODIR():_SORT_CMP_NODIR()))
+					#endif
+					{
+						sort_order[j] = sort_order[j - gap];
+						j -= gap;
+						#ifdef SORTING_DUMP
+						for (uint16_t z = 0; z < fileCnt; z++)
+						{
+							printf_P(PSTR("%2u "), sort_order[z]);
+						}
+						printf_P(PSTR("i%2d j%2d gap%2d orderBckp%2d\n"), i, j, gap, orderBckp);
+						#endif
+						if (j < gap) break;
+						getfilename_simple(positions[sort_order[j - gap]]);
+						name2 = LONGEST_FILENAME; // use the string in-place
+					}
+					sort_order[j] = orderBckp;
+				}
+			}
+
+#else //Bubble Sort
 			uint32_t counter = 0;
 			uint16_t total = 0.5*(fileCnt - 1)*(fileCnt);
 
@@ -786,7 +850,7 @@ void CardReader::presort() {
 					if (column < (percent / 5))
 					{
 						lcd_set_cursor(column, 2);
-						lcd_print('\x01'); //simple progress bar
+						lcd_print('\xFF'); //simple progress bar
 					}
 				}
 				counter++;
@@ -794,6 +858,13 @@ void CardReader::presort() {
 				//MYSERIAL.println(int(i));
 				for (uint16_t j = 0; j < i; ++j) {
 					if (!IS_SD_INSERTED) return;
+					#ifdef SORTING_DUMP
+					for (uint16_t z = 0; z < fileCnt; z++)
+					{
+						printf_P(PSTR("%2u "), sort_order[z]);
+					}
+					MYSERIAL.println();
+					#endif
 					manage_heater();
 					const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1];
 
@@ -841,10 +912,9 @@ void CardReader::presort() {
 	for (int column = 0; column <= 19; column++)
 	{
 		lcd_set_cursor(column, 2);
-		lcd_print('\x01'); //simple progress bar
+		lcd_print('\xFF'); //simple progress bar
 	}
 	_delay(300);
-	lcd_set_degree();
 	lcd_clear();
 #endif
 	lcd_scrollTimer.start();

+ 0 - 15
Firmware/lcd.cpp

@@ -958,21 +958,6 @@ void lcd_set_custom_characters_arrows(void)
 	lcd_createChar_P(1, lcd_chardata_arrdown);
 }
 
-const uint8_t lcd_chardata_progress[8] PROGMEM = {
-	B11111,
-	B11111,
-	B11111,
-	B11111,
-	B11111,
-	B11111,
-	B11111,
-	B11111};
-
-void lcd_set_custom_characters_progress(void)
-{
-	lcd_createChar_P(1, lcd_chardata_progress);
-}
-
 const uint8_t lcd_chardata_arr2down[8] PROGMEM = {
 	B00000,
 	B00000,

+ 0 - 1
Firmware/lcd.h

@@ -203,7 +203,6 @@ private:
 
 extern void lcd_set_custom_characters(void);
 extern void lcd_set_custom_characters_arrows(void);
-extern void lcd_set_custom_characters_progress(void);
 extern void lcd_set_custom_characters_nextpage(void);
 extern void lcd_set_custom_characters_degree(void);
 

+ 1 - 10
Firmware/ultralcd.cpp

@@ -4502,17 +4502,10 @@ static void lcd_fsensor_state_set()
 }
 #endif //FILAMENT_SENSOR
 
-
-#if !SDSORT_USES_RAM
 void lcd_set_degree() {
 	lcd_set_custom_characters_degree();
 }
 
-void lcd_set_progress() {
-	lcd_set_custom_characters_progress();
-}
-#endif
-
 #if (LANG_MODE != 0)
 
 void menu_setlang(unsigned char lang)
@@ -8737,7 +8730,6 @@ static void lcd_connect_printer() {
 	
 	int i = 0;
 	int t = 0;
-	lcd_set_custom_characters_progress();
 	lcd_puts_at_P(0, 0, _i("Connect printer to")); 
 	lcd_puts_at_P(0, 1, _i("monitoring or hold"));
 	lcd_puts_at_P(0, 2, _i("the knob to continue"));
@@ -8754,12 +8746,11 @@ static void lcd_connect_printer() {
 			i = 0; 
 			lcd_puts_at_P(0, 3, PSTR("                    "));
 		}
-		if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
+		if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\xFF");
 		if (i == NC_BUTTON_LONG_PRESS * 10) {
 			no_response = false;
 		}
 	}
-	lcd_set_custom_characters_degree();
 	lcd_update_enable(true);
 	lcd_update(2);
 }

+ 0 - 3
Firmware/ultralcd.h

@@ -218,10 +218,7 @@ void lcd_temp_calibration_set();
 
 void display_loading();
 
-#if !SDSORT_USES_RAM
 void lcd_set_degree();
-void lcd_set_progress();
-#endif
 
 #if (LANG_MODE != 0)
 void lcd_language();