From 73ddc762c8026e12866b76cb530a9448fa524930 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 22 Nov 2017 17:44:56 -0600 Subject: [PATCH] Fix up LCD init / charset --- Marlin/Marlin_main.cpp | 3 - Marlin/ultralcd.cpp | 26 +++-- Marlin/ultralcd_impl_HD44780.h | 177 +++++++++++++++++++-------------- 3 files changed, 113 insertions(+), 93 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index cfa0f41e2..9ff3d71d4 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -13904,9 +13904,6 @@ void setup() { #if ENABLED(SHOW_BOOTSCREEN) lcd_bootscreen(); - #if DISABLED(DOGLCD) && ENABLED(ULTRA_LCD) && DISABLED(SDSUPPORT) - lcd_init(); - #endif #endif #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1 diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index a65b5257a..6ae5d1ede 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -521,13 +521,15 @@ uint16_t max_display_update_time = 0; lcd_implementation_clear(); // Re-initialize custom characters that may be re-used #if DISABLED(DOGLCD) && ENABLED(AUTO_BED_LEVELING_UBL) - if (!ubl_lcd_map_control) lcd_set_custom_characters( - #if ENABLED(LCD_PROGRESS_BAR) - screen == lcd_status_screen - #endif - ); + if (!ubl_lcd_map_control) { + lcd_set_custom_characters( + #if ENABLED(LCD_PROGRESS_BAR) + screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU + #endif + ); + } #elif ENABLED(LCD_PROGRESS_BAR) - lcd_set_custom_characters(screen == lcd_status_screen); + lcd_set_custom_characters(screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU); #endif lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; screen_changed = true; @@ -669,7 +671,7 @@ void lcd_status_screen() { #endif lcd_implementation_init( // to maybe revive the LCD if static electricity killed it. #if ENABLED(LCD_PROGRESS_BAR) - false + CHARSET_MENU #endif ); lcd_goto_screen(lcd_main_menu); @@ -850,7 +852,7 @@ void kill_screen(const char* lcd_msg) { static int8_t bar_percent = 0; if (lcd_clicked) { lcd_goto_previous_menu(); - lcd_set_custom_characters(false); + lcd_set_custom_characters(CHARSET_MENU); return; } bar_percent += (int8_t)encoderPosition; @@ -4469,11 +4471,7 @@ void kill_screen(const char* lcd_msg) { void lcd_init() { - lcd_implementation_init( - #if ENABLED(LCD_PROGRESS_BAR) - true - #endif - ); + lcd_implementation_init(); #if ENABLED(NEWPANEL) #if BUTTON_EXISTS(EN1) @@ -4642,7 +4640,7 @@ void lcd_update() { lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; lcd_implementation_init( // to maybe revive the LCD if static electricity killed it. #if ENABLED(LCD_PROGRESS_BAR) - currentScreen == lcd_status_screen + currentScreen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU #endif ); } diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index 760443edf..27468464a 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -218,11 +218,57 @@ static void createChar_P(const char c, const byte * const ptr) { lcd.createChar(c, temp); } +#define CHARSET_MENU 0 +#define CHARSET_INFO 1 +#define CHARSET_BOOT 2 + static void lcd_set_custom_characters( - #if ENABLED(LCD_PROGRESS_BAR) - const bool info_screen_charset = true + #if ENABLED(LCD_PROGRESS_BAR) || ENABLED(SHOW_BOOTSCREEN) + const uint8_t screen_charset=CHARSET_INFO #endif ) { + // CHARSET_BOOT + #if ENABLED(SHOW_BOOTSCREEN) + const static PROGMEM byte corner[4][8] = { { + B00000, + B00000, + B00000, + B00000, + B00001, + B00010, + B00100, + B00100 + }, { + B00000, + B00000, + B00000, + B11100, + B11100, + B01100, + B00100, + B00100 + }, { + B00100, + B00010, + B00001, + B00000, + B00000, + B00000, + B00000, + B00000 + }, { + B00100, + B01000, + B10000, + B00000, + B00000, + B00000, + B00000, + B00000 + } }; + #endif // SHOW_BOOTSCREEN + + // CHARSET_INFO const static PROGMEM byte bedTemp[8] = { B00000, B11111, @@ -290,6 +336,8 @@ static void lcd_set_custom_characters( }; #if ENABLED(SDSUPPORT) + + // CHARSET_MENU const static PROGMEM byte refresh[8] = { B00000, B00110, @@ -312,6 +360,8 @@ static void lcd_set_custom_characters( }; #if ENABLED(LCD_PROGRESS_BAR) + + // CHARSET_INFO const static PROGMEM byte progress[3][8] = { { B00000, B10000, @@ -340,43 +390,61 @@ static void lcd_set_custom_characters( B10101, B00000 } }; - #endif - #endif - createChar_P(LCD_BEDTEMP_CHAR, bedTemp); - createChar_P(LCD_DEGREE_CHAR, degree); - createChar_P(LCD_STR_THERMOMETER[0], thermometer); - createChar_P(LCD_FEEDRATE_CHAR, feedrate); - createChar_P(LCD_CLOCK_CHAR, clock); + #endif // LCD_PROGRESS_BAR - #if ENABLED(SDSUPPORT) - #if ENABLED(LCD_PROGRESS_BAR) - static bool char_mode = false; - if (info_screen_charset != char_mode) { - char_mode = info_screen_charset; - if (info_screen_charset) { // Progress bar characters for info screen - for (int16_t i = 3; i--;) createChar_P(LCD_STR_PROGRESS[i], progress[i]); - } - else { // Custom characters for submenus - createChar_P(LCD_UPLEVEL_CHAR, uplevel); - createChar_P(LCD_STR_REFRESH[0], refresh); - createChar_P(LCD_STR_FOLDER[0], folder); - } - } - #else - createChar_P(LCD_UPLEVEL_CHAR, uplevel); - createChar_P(LCD_STR_REFRESH[0], refresh); - createChar_P(LCD_STR_FOLDER[0], folder); - #endif + #endif // SDSUPPORT + #if ENABLED(SHOW_BOOTSCREEN) || ENABLED(LCD_PROGRESS_BAR) + static uint8_t char_mode = 0; + #define CHAR_COND (screen_charset != char_mode) #else - createChar_P(LCD_UPLEVEL_CHAR, uplevel); + #define CHAR_COND true #endif + + if (CHAR_COND) { + #if ENABLED(SHOW_BOOTSCREEN) || ENABLED(LCD_PROGRESS_BAR) + char_mode = screen_charset; + #if ENABLED(SHOW_BOOTSCREEN) + // Set boot screen corner characters + if (screen_charset == CHARSET_BOOT) { + for (uint8_t i = 4; i--;) + createChar_P(i, corner[i]); + } + else + #endif + #endif + { // Info Screen uses 5 special characters + createChar_P(LCD_BEDTEMP_CHAR, bedTemp); + createChar_P(LCD_DEGREE_CHAR, degree); + createChar_P(LCD_STR_THERMOMETER[0], thermometer); + createChar_P(LCD_FEEDRATE_CHAR, feedrate); + createChar_P(LCD_CLOCK_CHAR, clock); + + #if ENABLED(SDSUPPORT) + #if ENABLED(LCD_PROGRESS_BAR) + if (screen_charset == CHARSET_INFO) { // 3 Progress bar characters for info screen + for (int16_t i = 3; i--;) + createChar_P(LCD_STR_PROGRESS[i], progress[i]); + } + else + #endif + { // SD Card sub-menu special characters + createChar_P(LCD_UPLEVEL_CHAR, uplevel); + createChar_P(LCD_STR_REFRESH[0], refresh); + createChar_P(LCD_STR_FOLDER[0], folder); + } + #else + // With no SD support, only need the uplevel character + createChar_P(LCD_UPLEVEL_CHAR, uplevel); + #endif + } + } } static void lcd_implementation_init( #if ENABLED(LCD_PROGRESS_BAR) - const bool info_screen_charset = true + const uint8_t screen_charset=CHARSET_INFO #endif ) { @@ -406,7 +474,7 @@ static void lcd_implementation_init( lcd_set_custom_characters( #if ENABLED(LCD_PROGRESS_BAR) - info_screen_charset + screen_charset #endif ); @@ -458,46 +526,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) { } void lcd_bootscreen() { - const static PROGMEM byte corner[4][8] = { { - B00000, - B00000, - B00000, - B00000, - B00001, - B00010, - B00100, - B00100 - }, { - B00000, - B00000, - B00000, - B11100, - B11100, - B01100, - B00100, - B00100 - }, { - B00100, - B00010, - B00001, - B00000, - B00000, - B00000, - B00000, - B00000 - }, { - B00100, - B01000, - B10000, - B00000, - B00000, - B00000, - B00000, - B00000 - } }; - for (uint8_t i = 0; i < 4; i++) - createChar_P(i, corner[i]); - + lcd_set_custom_characters(CHARSET_BOOT); lcd.clear(); #define LCD_EXTRA_SPACE (LCD_WIDTH-8) @@ -568,11 +597,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) { safe_delay(100); - lcd_set_custom_characters( - #if ENABLED(LCD_PROGRESS_BAR) - false - #endif - ); + lcd_set_custom_characters(); } #endif // SHOW_BOOTSCREEN