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.
pull/1/head
Bob-the-Kuhn 8 years ago
committed by Scott Lahteine
parent
commit
76da81c1de
  1. 18
      Marlin/cardreader.cpp
  2. 2
      Marlin/cardreader.h
  3. 16
      Marlin/pins_RAMPS_RE_ARM.h
  4. 42
      Marlin/ultralcd.cpp

18
Marlin/cardreader.cpp

@ -74,9 +74,12 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
/** /**
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction: * Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
* LS_Count - Add +1 to nrFiles for every file within the parent * LS_Count - Add +1 to nrFiles for every file within the parent
* LS_GetFilename - Get the filename of the file indexed by nrFiles * LS_GetFilename - Get the filename of the file indexed by nrFile_index
* LS_SerialPrint - Print the full path and size of each file to serial output * LS_SerialPrint - Print the full path and size of each file to serial output
*/ */
uint16_t nrFile_index;
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) { void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
dir_t p; dir_t p;
uint8_t cnt = 0; uint8_t cnt = 0;
@ -130,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue; if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
switch (lsAction) { switch (lsAction) { // 1 based file count
case LS_Count: case LS_Count:
nrFiles++; nrFiles++;
break; break;
@ -148,7 +151,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
if (match != NULL) { if (match != NULL) {
if (strcasecmp(match, filename) == 0) return; if (strcasecmp(match, filename) == 0) return;
} }
else if (cnt == nrFiles) return; else if (cnt == nrFile_index) return; // 0 based index
cnt++; cnt++;
break; break;
} }
@ -596,7 +599,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
#endif // SDSORT_CACHE_NAMES #endif // SDSORT_CACHE_NAMES
curDir = &workDir; curDir = &workDir;
lsAction = LS_GetFilename; lsAction = LS_GetFilename;
nrFiles = nr; nrFile_index = nr;
curDir->rewind(); curDir->rewind();
lsDive("", *curDir, match); lsDive("", *curDir, match);
} }
@ -861,6 +864,13 @@ void CardReader::updir() {
#endif // SDCARD_SORT_ALPHA #endif // SDCARD_SORT_ALPHA
#if (ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES)
// if true - don't need to access the SD card for file names
uint16_t CardReader::get_num_Files() {return nrFiles;}
#else
uint16_t CardReader::get_num_Files() {return getnrfilenames(); }
#endif
void CardReader::printingHasFinished() { void CardReader::printingHasFinished() {
stepper.synchronize(); stepper.synchronize();
file.close(); file.close();

2
Marlin/cardreader.h

@ -69,6 +69,8 @@ public:
void updir(); void updir();
void setroot(); void setroot();
uint16_t get_num_Files();
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
void presort(); void presort();
void getfilename_sorted(const uint16_t nr); void getfilename_sorted(const uint16_t nr);

16
Marlin/pins_RAMPS_RE_ARM.h

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

42
Marlin/ultralcd.cpp

@ -3507,7 +3507,7 @@ void kill_screen(const char* lcd_msg) {
void lcd_sdcard_menu() { void lcd_sdcard_menu() {
ENCODER_DIRECTION_MENUS(); ENCODER_DIRECTION_MENUS();
if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card) if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
const uint16_t fileCnt = card.getnrfilenames(); const uint16_t fileCnt = card.get_num_Files();
START_MENU(); START_MENU();
MENU_BACK(MSG_MAIN); MENU_BACK(MSG_MAIN);
card.getWorkDirName(); card.getWorkDirName();
@ -3520,27 +3520,29 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir); MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
} }
for (uint16_t i = 0; i < fileCnt; i++) { if (fileCnt) {
if (_menuLineNr == _thisItemNr) { for (uint16_t i = 0; i < fileCnt; i++) {
const uint16_t nr = if (_menuLineNr == _thisItemNr) {
#if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA) const uint16_t nr =
fileCnt - 1 - #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
#endif fileCnt - 1 -
i; #endif
i;
#if ENABLED(SDCARD_SORT_ALPHA) #if ENABLED(SDCARD_SORT_ALPHA)
card.getfilename_sorted(nr); card.getfilename_sorted(nr);
#else #else
card.getfilename(nr); card.getfilename(nr);
#endif #endif
if (card.filenameIsDir) if (card.filenameIsDir)
MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename); MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
else else
MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename); MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
} }
else { else {
MENU_ITEM_DUMMY(); MENU_ITEM_DUMMY();
}
} }
} }
END_MENU(); END_MENU();

Loading…
Cancel
Save