Add card.longest_filename method

This commit is contained in:
Scott Lahteine
2018-07-13 01:44:27 -05:00
parent 71df1f7f57
commit 065e9c3d66
5 changed files with 41 additions and 43 deletions

View File

@ -277,8 +277,8 @@ uint16_t max_display_update_time = 0;
#if ENABLED(SDSUPPORT)
void lcd_sdcard_menu();
void menu_action_sdfile(const char* filename, char* longFilename);
void menu_action_sddirectory(const char* filename, char* longFilename);
void menu_action_sdfile(CardReader &theCard);
void menu_action_sddirectory(CardReader &theCard);
#endif
////////////////////////////////////////////
@ -768,7 +768,7 @@ void lcd_reset_status() {
msg = paused;
#if ENABLED(SDSUPPORT)
else if (card.sdprinting)
return lcd_setstatus(card.longFilename[0] ? card.longFilename : card.filename, true);
return lcd_setstatus(card.longest_filename(), true);
#endif
else if (print_job_timer.isRunning())
msg = printing;
@ -1002,9 +1002,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
bar_percent = constrain(bar_percent, 0, 100);
encoderPosition = 0;
lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
lcd.print(itostr3(bar_percent)); lcd.write('%');
lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
lcd_put_u8str(int(bar_percent)); lcd_put_wchar('%');
lcd_moveto(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
}
void _progress_bar_test() {
@ -2938,7 +2938,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
destination[manual_move_axis] += manual_move_offset;
// Reset for the next move
manual_move_offset = 0.0;
manual_move_offset = 0;
manual_move_axis = (int8_t)NO_AXIS;
// DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
@ -4042,9 +4042,9 @@ void lcd_quick_feedback(const bool clear_buttons) {
#endif
if (card.filenameIsDir)
MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
else
MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
MENU_ITEM(sdfile, MSG_CARD_MENU, card);
}
else {
MENU_ITEM_DUMMY();
@ -4965,19 +4965,17 @@ void lcd_quick_feedback(const bool clear_buttons) {
#if ENABLED(SDSUPPORT)
void menu_action_sdfile(const char* filename, char* longFilename) {
void menu_action_sdfile(CardReader &theCard) {
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
#endif
UNUSED(longFilename);
card.openAndPrintFile(filename);
card.openAndPrintFile(theCard.filename);
lcd_return_to_status();
lcd_reset_status();
}
void menu_action_sddirectory(const char* filename, char* longFilename) {
UNUSED(longFilename);
card.chdir(filename);
void menu_action_sddirectory(CardReader &theCard) {
card.chdir(theCard.filename);
encoderTopLine = 0;
encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
screen_changed = true;

View File

@ -518,7 +518,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);
@ -526,23 +526,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
}
@ -554,8 +554,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
}
#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

View File

@ -926,29 +926,29 @@ static void lcd_implementation_status_screen() {
#if ENABLED(SDSUPPORT)
static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const uint8_t concat, const char post_char) {
static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, CardReader &theCard, const uint8_t concat, const char post_char) {
UNUSED(pstr);
lcd_moveto(0, row);
lcd_put_wchar(sel ? '>' : ' ');
uint8_t n = LCD_WIDTH - concat;
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 (sel) {
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) - n); // Update the scroll limit
filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - n); // 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[n] = '\0'; // cutoff at screen edge
theCard.longFilename[n] = '\0'; // cutoff at screen edge
#endif
}
@ -960,12 +960,12 @@ static void lcd_implementation_status_screen() {
lcd_put_wchar(post_char);
}
static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, ' ');
}
static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, CardReader &theCard) {
lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, LCD_STR_FOLDER[0]);
}
#endif // SDSUPPORT