Kaynağa Gözat

minimize SD card reads when using SDCARD_SORT_ALPHA (Re-ARM board)

Because of the Re-ARM card's pinout there is only one SPI connected to
the RepRap Discount Full Graphic LCD display.  The LCD responds to ANY
SCK transitions no matter if it's enable is inactive.  The result is
garbage (usually bars) on the LCD display whenever there is SD card
activity.

This code minimizes this by only accessing the SD card when changing
directory levels if :
SDCARD_SORT_ALPHA is enabled
SDSORT_USES_RAM is true
SDSORT_CACHE_NAMES is true

The code changes result in file names being pulled from the ALPHA SORT
memory array rather than the SD card.

The code also gives the file count and file index functions their own
variables.  When they shared a common variable the index function
sometimes resulted in the file count being short by 1.

=======================================================================

cardreader.cpp & pins_RAMPS_RE_ARM.h changes

Added another condition to cardreader.cpp to enable getting file names
only from RAM.

pins_RAMPS_RE_ARM.h :
Added comments about the SD card accesses and the LCD display
Combined all versions into this one.
Bob-the-Kuhn 6 yıl önce
ebeveyn
işleme
76da81c1de
4 değiştirilmiş dosya ile 46 ekleme ve 32 silme
  1. 14
    4
      Marlin/cardreader.cpp
  2. 2
    0
      Marlin/cardreader.h
  3. 8
    8
      Marlin/pins_RAMPS_RE_ARM.h
  4. 22
    20
      Marlin/ultralcd.cpp

+ 14
- 4
Marlin/cardreader.cpp Dosyayı Görüntüle

@@ -74,9 +74,12 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
74 74
 /**
75 75
  * Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
76 76
  *   LS_Count       - Add +1 to nrFiles for every file within the parent
77
- *   LS_GetFilename - Get the filename of the file indexed by nrFiles
77
+ *   LS_GetFilename - Get the filename of the file indexed by nrFile_index
78 78
  *   LS_SerialPrint - Print the full path and size of each file to serial output
79 79
  */
80
+ 
81
+uint16_t nrFile_index;
82
+
80 83
 void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
81 84
   dir_t p;
82 85
   uint8_t cnt = 0;
@@ -130,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
130 133
 
131 134
       if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
132 135
 
133
-      switch (lsAction) {
136
+      switch (lsAction) {  // 1 based file count
134 137
         case LS_Count:
135 138
           nrFiles++;
136 139
           break;
@@ -148,7 +151,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
148 151
           if (match != NULL) {
149 152
             if (strcasecmp(match, filename) == 0) return;
150 153
           }
151
-          else if (cnt == nrFiles) return;
154
+          else if (cnt == nrFile_index) return;  // 0 based index
152 155
           cnt++;
153 156
           break;
154 157
       }
@@ -596,7 +599,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
596 599
   #endif // SDSORT_CACHE_NAMES
597 600
   curDir = &workDir;
598 601
   lsAction = LS_GetFilename;
599
-  nrFiles = nr;
602
+  nrFile_index = nr;
600 603
   curDir->rewind();
601 604
   lsDive("", *curDir, match);
602 605
 }
@@ -861,6 +864,13 @@ void CardReader::updir() {
861 864
 
862 865
 #endif // SDCARD_SORT_ALPHA
863 866
 
867
+#if (ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES)  
868
+ // if true - don't need to access the SD card for file names
869
+  uint16_t CardReader::get_num_Files() {return nrFiles;}
870
+#else
871
+  uint16_t CardReader::get_num_Files() {return getnrfilenames(); } 
872
+#endif
873
+
864 874
 void CardReader::printingHasFinished() {
865 875
   stepper.synchronize();
866 876
   file.close();

+ 2
- 0
Marlin/cardreader.h Dosyayı Görüntüle

@@ -69,6 +69,8 @@ public:
69 69
   void updir();
70 70
   void setroot();
71 71
 
72
+  uint16_t get_num_Files();
73
+  
72 74
   #if ENABLED(SDCARD_SORT_ALPHA)
73 75
     void presort();
74 76
     void getfilename_sorted(const uint16_t nr);

+ 8
- 8
Marlin/pins_RAMPS_RE_ARM.h Dosyayı Görüntüle

@@ -52,7 +52,7 @@
52 52
 //
53 53
 // Servos
54 54
 //
55
-#define SERVO0_PIN         11  
55
+#define SERVO0_PIN         11
56 56
 #define SERVO1_PIN          6  // also on J5-1
57 57
 #define SERVO2_PIN          5
58 58
 #define SERVO3_PIN          4  // 5V output - PWM capable
@@ -214,9 +214,9 @@
214 214
  *
215 215
  * All controllers can use J3 and J5 on the Re-ARM board.  Custom cabling will be required.
216 216
  */
217
- 
218
-/** 
219
- * Smart LCD adapter 
217
+
218
+/**
219
+ * Smart LCD adapter
220 220
  *
221 221
  * The Smart LCD adapter can be used for the two 10 pin LCD controllers such as
222 222
  * REPRAP_DISCOUNT_SMART_CONTROLLER.  It can't be used for controllers that use
@@ -224,7 +224,7 @@
224 224
  * is needed to pick up 5V for the EXP1 connection.
225 225
  *
226 226
  * SD card on the LCD uses the same SPI signals as the LCD. This results in garbage/lines
227
- * on the LCD display during accesses of the SD card. The menus/code has been arranged so 
227
+ * on the LCD display during accesses of the SD card. The menus/code has been arranged so
228 228
  * that the garbage/lines are erased immediately after the SD card accesses are completed.
229 229
  */
230 230
 
@@ -248,7 +248,7 @@
248 248
   #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) && ENABLED(SDSUPPORT)
249 249
     #define SDCARD_SORT_ALPHA           // Using SORT feature to keep one directory level in RAM
250 250
                                         // When going up/down directory levels the SD card is
251
-                                        // accessed but the garbage/lines are removed when the 
251
+                                        // accessed but the garbage/lines are removed when the
252 252
                                         // LCD updates
253 253
 
254 254
     // SD Card Sorting options
@@ -262,7 +262,7 @@
262 262
       #define SDSORT_DYNAMIC_RAM false  // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
263 263
     #endif
264 264
   #endif
265
-  
265
+
266 266
   #define BTN_EN1             31  // J3-2 & AUX-4
267 267
   #define BTN_EN2             33  // J3-4 & AUX-4
268 268
   #define BTN_ENC             35  // J3-3 & AUX-4
@@ -286,7 +286,7 @@
286 286
   //#define MOSI                51  // system defined J3-10 & AUX-3
287 287
   //#define SCK                 52  // system defined J3-9 & AUX-3
288 288
   //#define SS_PIN              53  // system defined J3-5 & AUX-3 - sometimes called SDSS
289
- 
289
+
290 290
 
291 291
   #if ENABLED(VIKI2) || ENABLED(miniVIKI)
292 292
     #define LCD_SCREEN_ROT_180

+ 22
- 20
Marlin/ultralcd.cpp Dosyayı Görüntüle

@@ -3507,7 +3507,7 @@ void kill_screen(const char* lcd_msg) {
3507 3507
     void lcd_sdcard_menu() {
3508 3508
       ENCODER_DIRECTION_MENUS();
3509 3509
       if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
3510
-      const uint16_t fileCnt = card.getnrfilenames();
3510
+      const uint16_t fileCnt = card.get_num_Files();
3511 3511
       START_MENU();
3512 3512
       MENU_BACK(MSG_MAIN);
3513 3513
       card.getWorkDirName();
@@ -3520,27 +3520,29 @@ void kill_screen(const char* lcd_msg) {
3520 3520
         MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
3521 3521
       }
3522 3522
 
3523
-      for (uint16_t i = 0; i < fileCnt; i++) {
3524
-        if (_menuLineNr == _thisItemNr) {
3525
-          const uint16_t nr =
3526
-            #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
3527
-              fileCnt - 1 -
3528
-            #endif
3529
-          i;
3523
+      if (fileCnt) {
3524
+        for (uint16_t i = 0; i < fileCnt; i++) {
3525
+          if (_menuLineNr == _thisItemNr) {
3526
+            const uint16_t nr =
3527
+              #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
3528
+                fileCnt - 1 -
3529
+              #endif
3530
+            i;
3530 3531
 
3531
-          #if ENABLED(SDCARD_SORT_ALPHA)
3532
-            card.getfilename_sorted(nr);
3533
-          #else
3534
-            card.getfilename(nr);
3535
-          #endif
3532
+            #if ENABLED(SDCARD_SORT_ALPHA)
3533
+              card.getfilename_sorted(nr);
3534
+            #else
3535
+              card.getfilename(nr);
3536
+            #endif
3536 3537
 
3537
-          if (card.filenameIsDir)
3538
-            MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
3539
-          else
3540
-            MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
3541
-        }
3542
-        else {
3543
-          MENU_ITEM_DUMMY();
3538
+            if (card.filenameIsDir)
3539
+              MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
3540
+            else
3541
+              MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
3542
+          }
3543
+          else {
3544
+            MENU_ITEM_DUMMY();
3545
+          }
3544 3546
         }
3545 3547
       }
3546 3548
       END_MENU();

Loading…
İptal
Kaydet