diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 7cbd312569d04..ac529f3f34dd3 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -154,14 +154,31 @@ void MarlinUI::draw_kill_screen() { lcd_put_u8str_P((const char*)GET_TEXT_F(MSG_HALTED)); } +// +// Status Message +// void MarlinUI::draw_status_message(const bool blink) { - set_font(DWIN_FONT_STAT); set_dwin_text_solid(true); set_dwin_text_fg(Color_White); set_dwin_text_bg(Color_Bg_Black); lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1); + constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH); + + uint8_t status_changed = []{ + static uint8_t old_hash = 0; + uint8_t hash = 0x00; + for (uint8_t i = 0; i < MAX_MESSAGE_LENGTH; i++) { + const char c = ui.status_message[i]; + if (!c) break; + hash = ((hash << 1) | (hash >> 7)) ^ c; + } + const bool hash_changed = hash != old_hash; + old_hash = hash; + return hash_changed || !ui.did_first_redraw; + }; + #if ENABLED(STATUS_MESSAGE_SCROLLING) static bool last_blink = false; @@ -169,33 +186,37 @@ void MarlinUI::draw_status_message(const bool blink) { uint8_t slen = utf8_strlen(status_message); // If the string fits into the LCD, just print it and do not scroll it - if (slen <= (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)) { + if (slen <= max_status_chars) { + + if (status_changed()) { - // The string isn't scrolling and may not fill the screen - lcd_put_u8str(status_message); + // The string isn't scrolling and may not fill the screen + lcd_put_u8str(status_message); - // Fill the rest with spaces - while (slen < (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)) { lcd_put_wchar(' '); ++slen; } + // Fill the rest with spaces + while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; } + } } else { - // String is larger than the available space in screen. + // String is larger than the available line space // Get a pointer to the next valid UTF8 character // and the string remaining length uint8_t rlen; const char *stat = status_and_len(rlen); - lcd_put_u8str_max(stat, (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)); + lcd_put_u8str_max(stat, max_status_chars); - // If the remaining string doesn't completely fill the screen - if (rlen < (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)) { + // If the string doesn't completely fill the line... + if (rlen < max_status_chars) { lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot - uint8_t chars = ((LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)) - rlen; // Amount of space left in characters + uint8_t chars = max_status_chars - rlen; // Amount of space left in characters if (--chars) { // Draw a second dot if there's space lcd_put_wchar('.'); if (--chars) lcd_put_u8str_max(status_message, chars); // Print a second copy of the message } } + if (last_blink != blink) { last_blink = blink; advance_status_scroll(); @@ -206,17 +227,17 @@ void MarlinUI::draw_status_message(const bool blink) { UNUSED(blink); - // Get the UTF8 character count of the string - uint8_t slen = utf8_strlen(status_message); + if (status_changed()) { + // Get the UTF8 character count of the string + uint8_t slen = utf8_strlen(status_message); - // Just print the string to the LCD - lcd_put_u8str_max(status_message, (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)); + // Just print the string to the LCD + lcd_put_u8str_max(status_message, max_status_chars); - // Fill the rest with spaces if there are missing spaces - while (slen < (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH)) { - lcd_put_wchar(' '); - ++slen; + // Fill the rest with spaces if there are missing spaces + while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; } } + #endif } diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp index 05ae1d56b3af4..2b3058ba7db82 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp @@ -358,18 +358,7 @@ void MarlinUI::draw_status_screen() { // // Status Message // - static uint8_t old_hash = 0; - uint8_t hash = 0x00; - for (uint8_t i = 0; i < MAX_MESSAGE_LENGTH; i++) { - const char c = ui.status_message[i]; - if (!c) break; - hash = ((hash << 1) | (hash >> 7)) ^ c; - } - - if (!ui.did_first_redraw || hash != old_hash) { - draw_status_message(blink); - old_hash = hash; - } + draw_status_message(blink); ui.did_first_redraw = true; }