Просмотр исходного кода

Completed SORT_USES_MORE_RAM implementation

For the MORE_RAM option we need to buffer both the short and long
names, even though long names are sometimes redundant. Worst case, all
the names are max length. We can save some RAM by not storing these. We
could save more RAM by only storing the visible part of the long name.
Scott Lahteine 10 лет назад
Родитель
Сommit
8ebefe6d35
2 измененных файлов: 18 добавлений и 2 удалений
  1. 17
    2
      Marlin/cardreader.cpp
  2. 1
    0
      Marlin/cardreader.h

+ 17
- 2
Marlin/cardreader.cpp Просмотреть файл

203
   if(cardOK)
203
   if(cardOK)
204
   {
204
   {
205
     sdprinting = true;
205
     sdprinting = true;
206
+    flush_presort();
206
   }
207
   }
207
 }
208
 }
208
 
209
 
555
 {
556
 {
556
   #if defined(SDCARD_SORT_ALPHA) && SORT_USES_RAM && SORT_USES_MORE_RAM
557
   #if defined(SDCARD_SORT_ALPHA) && SORT_USES_RAM && SORT_USES_MORE_RAM
557
     if (nr < sort_count) {
558
     if (nr < sort_count) {
559
+      strcpy(filename, sortshort[nr]);
558
       strcpy(longFilename, sortnames[nr]);
560
       strcpy(longFilename, sortnames[nr]);
559
       filenameIsDir = isDir[nr];
561
       filenameIsDir = isDir[nr];
560
       return;
562
       return;
648
 
650
 
649
     #if SORT_USES_RAM
651
     #if SORT_USES_RAM
650
       #if SORT_USES_MORE_RAM
652
       #if SORT_USES_MORE_RAM
653
+        sortshort = (char**)calloc(fileCnt, sizeof(char*));
651
         sortnames = (char**)calloc(fileCnt, sizeof(char*));
654
         sortnames = (char**)calloc(fileCnt, sizeof(char*));
652
       #else
655
       #else
653
         char *sortnames[fileCnt];
656
         char *sortnames[fileCnt];
664
       #endif
667
       #endif
665
     #endif
668
     #endif
666
 
669
 
667
-    sort_count = fileCnt;
668
     sort_order = new uint8_t[fileCnt];
670
     sort_order = new uint8_t[fileCnt];
669
 
671
 
670
     if (fileCnt > 1) {
672
     if (fileCnt > 1) {
675
         #if SORT_USES_RAM
677
         #if SORT_USES_RAM
676
           getfilename(i);
678
           getfilename(i);
677
           sortnames[i] = strdup(longFilename[0] ? longFilename : filename);
679
           sortnames[i] = strdup(longFilename[0] ? longFilename : filename);
680
+          #if SORT_USES_MORE_RAM
681
+            sortshort[i] = strdup(filename);
682
+          #endif
678
           // char out[30];
683
           // char out[30];
679
           // sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
684
           // sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
680
           // SERIAL_ECHOLN(out);
685
           // SERIAL_ECHOLN(out);
729
       sort_order[0] = 0;
734
       sort_order[0] = 0;
730
       #if SORT_USES_RAM && SORT_USES_MORE_RAM
735
       #if SORT_USES_RAM && SORT_USES_MORE_RAM
731
         sortnames = (char**)malloc(sizeof(char*));
736
         sortnames = (char**)malloc(sizeof(char*));
737
+        sortshort = (char**)malloc(sizeof(char*));
732
         isDir = (uint8_t*)malloc(sizeof(uint8_t));
738
         isDir = (uint8_t*)malloc(sizeof(uint8_t));
733
         getfilename(0);
739
         getfilename(0);
734
         sortnames[0] = strdup(longFilename[0] ? longFilename : filename);
740
         sortnames[0] = strdup(longFilename[0] ? longFilename : filename);
741
+        sortshort[0] = strdup(filename);
735
         isDir[0] = filenameIsDir;
742
         isDir[0] = filenameIsDir;
736
       #endif
743
       #endif
737
     }
744
     }
738
 
745
 
746
+    sort_count = fileCnt;
739
   }
747
   }
740
 }
748
 }
741
 
749
 
742
 void CardReader::flush_presort() {
750
 void CardReader::flush_presort() {
743
   if (sort_count > 0) {
751
   if (sort_count > 0) {
744
     #if SORT_USES_RAM && SORT_USES_MORE_RAM
752
     #if SORT_USES_RAM && SORT_USES_MORE_RAM
745
-      for (uint8_t i=0; i<sort_count; ++i) free(sortnames[i]);
753
+      for (uint8_t i=0; i<sort_count; ++i) {
754
+        free(sortshort[i]);
755
+        free(sortnames[i]);
756
+      }
757
+      free(sortshort);
746
       free(sortnames);
758
       free(sortnames);
747
     #endif
759
     #endif
748
     delete sort_order;
760
     delete sort_order;
774
           enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
786
           enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
775
       }
787
       }
776
       autotempShutdown();
788
       autotempShutdown();
789
+      #ifdef SDCARD_SORT_ALPHA
790
+        presort();
791
+      #endif
777
     }
792
     }
778
 }
793
 }
779
 #endif //SDSUPPORT
794
 #endif //SDSUPPORT

+ 1
- 0
Marlin/cardreader.h Просмотреть файл

73
   uint16_t sort_count;
73
   uint16_t sort_count;
74
   uint8_t *sort_order;
74
   uint8_t *sort_order;
75
   #if SORT_USES_MORE_RAM
75
   #if SORT_USES_MORE_RAM
76
+    char **sortshort;
76
     char **sortnames;
77
     char **sortnames;
77
     uint8_t *isDir;
78
     uint8_t *isDir;
78
   #endif
79
   #endif

Загрузка…
Отмена
Сохранить