Browse Source

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 8 years ago
parent
commit
76da81c1de
4 changed files with 46 additions and 32 deletions
  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 View File

74
 /**
74
 /**
75
  * Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
75
  * Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
76
  *   LS_Count       - Add +1 to nrFiles for every file within the parent
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
  *   LS_SerialPrint - Print the full path and size of each file to serial output
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
 void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
83
 void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
81
   dir_t p;
84
   dir_t p;
82
   uint8_t cnt = 0;
85
   uint8_t cnt = 0;
130
 
133
 
131
       if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
134
       if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
132
 
135
 
133
-      switch (lsAction) {
136
+      switch (lsAction) {  // 1 based file count
134
         case LS_Count:
137
         case LS_Count:
135
           nrFiles++;
138
           nrFiles++;
136
           break;
139
           break;
148
           if (match != NULL) {
151
           if (match != NULL) {
149
             if (strcasecmp(match, filename) == 0) return;
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
           cnt++;
155
           cnt++;
153
           break;
156
           break;
154
       }
157
       }
596
   #endif // SDSORT_CACHE_NAMES
599
   #endif // SDSORT_CACHE_NAMES
597
   curDir = &workDir;
600
   curDir = &workDir;
598
   lsAction = LS_GetFilename;
601
   lsAction = LS_GetFilename;
599
-  nrFiles = nr;
602
+  nrFile_index = nr;
600
   curDir->rewind();
603
   curDir->rewind();
601
   lsDive("", *curDir, match);
604
   lsDive("", *curDir, match);
602
 }
605
 }
861
 
864
 
862
 #endif // SDCARD_SORT_ALPHA
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
 void CardReader::printingHasFinished() {
874
 void CardReader::printingHasFinished() {
865
   stepper.synchronize();
875
   stepper.synchronize();
866
   file.close();
876
   file.close();

+ 2
- 0
Marlin/cardreader.h View File

69
   void updir();
69
   void updir();
70
   void setroot();
70
   void setroot();
71
 
71
 
72
+  uint16_t get_num_Files();
73
+  
72
   #if ENABLED(SDCARD_SORT_ALPHA)
74
   #if ENABLED(SDCARD_SORT_ALPHA)
73
     void presort();
75
     void presort();
74
     void getfilename_sorted(const uint16_t nr);
76
     void getfilename_sorted(const uint16_t nr);

+ 8
- 8
Marlin/pins_RAMPS_RE_ARM.h View File

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

+ 22
- 20
Marlin/ultralcd.cpp View File

3507
     void lcd_sdcard_menu() {
3507
     void lcd_sdcard_menu() {
3508
       ENCODER_DIRECTION_MENUS();
3508
       ENCODER_DIRECTION_MENUS();
3509
       if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
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
       START_MENU();
3511
       START_MENU();
3512
       MENU_BACK(MSG_MAIN);
3512
       MENU_BACK(MSG_MAIN);
3513
       card.getWorkDirName();
3513
       card.getWorkDirName();
3520
         MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
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
       END_MENU();
3548
       END_MENU();

Loading…
Cancel
Save