Add card.longest_filename, more lcd_strlen updates

This commit is contained in:
Scott Lahteine 2018-07-17 17:33:01 -05:00
parent 036f25e159
commit 7e648f3721
6 changed files with 39 additions and 44 deletions

View file

@ -586,7 +586,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
#if ENABLED(SDSUPPORT)
static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, CardReader& theCard, const bool isDir) {
UNUSED(pstr);
lcd_implementation_mark_as_selected(row, isSelected);
@ -594,23 +594,23 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
if (!PAGE_CONTAINS(row_y1, row_y2)) return;
constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
const char *outstr = longFilename[0] ? longFilename : filename;
if (longFilename[0]) {
const char *outstr = theCard.longest_filename();
if (theCard.longFilename[0]) {
#if ENABLED(SCROLL_LONG_FILENAMES)
if (isSelected) {
uint8_t name_hash = row;
for (uint8_t l = FILENAME_LENGTH; l--;)
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l]; // rotate, xor
if (filename_scroll_hash != name_hash) { // If the hash changed...
filename_scroll_hash = name_hash; // Save the new hash
filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit
filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
filename_scroll_pos = 0; // Reset scroll to the start
lcd_status_update_delay = 8; // Don't scroll right away
}
outstr += filename_scroll_pos;
}
#else
longFilename[maxlen] = '\0'; // cutoff at screen edge
theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
#endif
}
@ -625,8 +625,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
while (n) { --n; u8g.print(' '); }
}
#define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
#define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
#define lcd_implementation_drawmenu_sdfile(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, false)
#define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, true)
#endif // SDSUPPORT