Fix STATUS_MESSAGE_SCROLLING in LIGHTWEIGHT_UI (#14603)

This commit is contained in:
Marcio Teixeira 2019-07-14 08:39:03 -06:00 committed by Scott Lahteine
parent bcbd2ff21c
commit a49478cefa

View File

@ -59,6 +59,8 @@
#include "../../sd/cardreader.h" #include "../../sd/cardreader.h"
#endif #endif
#define TEXT_MODE_LCD_WIDTH 16
#define BUFFER_WIDTH 256 #define BUFFER_WIDTH 256
#define BUFFER_HEIGHT 32 #define BUFFER_HEIGHT 32
@ -619,13 +621,12 @@ void ST7920_Lite_Status_Screen::draw_status_message() {
set_ddram_address(DDRAM_LINE_4); set_ddram_address(DDRAM_LINE_4);
begin_data(); begin_data();
#if ENABLED(STATUS_MESSAGE_SCROLLING) #if ENABLED(STATUS_MESSAGE_SCROLLING)
uint8_t slen = utf8_strlen(str); uint8_t slen = utf8_strlen(str);
if (slen <= LCD_WIDTH) { if (slen <= TEXT_MODE_LCD_WIDTH) {
// String fits the LCD, so just print it // String fits the LCD, so just print it
write_str(str); write_str(str);
while (slen < LCD_WIDTH) { write_byte(' '); ++slen; } while (slen < TEXT_MODE_LCD_WIDTH) { write_byte(' '); ++slen; }
} }
else { else {
// String is larger than the available space in screen. // String is larger than the available space in screen.
@ -634,12 +635,12 @@ void ST7920_Lite_Status_Screen::draw_status_message() {
// and the string remaining length // and the string remaining length
uint8_t rlen; uint8_t rlen;
const char *stat = ui.status_and_len(rlen); const char *stat = ui.status_and_len(rlen);
write_str(stat, LCD_WIDTH); write_str(stat, TEXT_MODE_LCD_WIDTH);
// If the remaining string doesn't completely fill the screen // If the remaining string doesn't completely fill the screen
if (rlen < LCD_WIDTH) { if (rlen < TEXT_MODE_LCD_WIDTH) {
write_byte('.'); // Always at 1+ spaces left, draw a dot write_byte('.'); // Always at 1+ spaces left, draw a dot
uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters uint8_t chars = TEXT_MODE_LCD_WIDTH - rlen; // Amount of space left in characters
if (--chars) { // Draw a second dot if there's space if (--chars) { // Draw a second dot if there's space
write_byte('.'); write_byte('.');
if (--chars) write_str(str, chars); // Print a second copy of the message if (--chars) write_str(str, chars); // Print a second copy of the message
@ -651,8 +652,8 @@ void ST7920_Lite_Status_Screen::draw_status_message() {
#else #else
uint8_t slen = utf8_strlen(str); uint8_t slen = utf8_strlen(str);
write_str(str, LCD_WIDTH); write_str(str, TEXT_MODE_LCD_WIDTH);
for (; slen < LCD_WIDTH; ++slen) write_byte(' '); for (; slen < TEXT_MODE_LCD_WIDTH; ++slen) write_byte(' ');
#endif #endif
} }
@ -760,7 +761,8 @@ bool ST7920_Lite_Status_Screen::position_changed() {
bool ST7920_Lite_Status_Screen::status_changed() { bool ST7920_Lite_Status_Screen::status_changed() {
uint8_t checksum = 0; uint8_t checksum = 0;
for (const char *p = ui.status_message; *p; p++) checksum ^= *p; for (const char *p = ui.status_message; *p; p++) checksum ^= *p;
static uint8_t last_checksum = 0, changed = last_checksum != checksum; static uint8_t last_checksum = 0;
bool changed = last_checksum != checksum;
if (changed) last_checksum = checksum; if (changed) last_checksum = checksum;
return changed; return changed;
} }
@ -805,7 +807,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
} }
#if !STATUS_EXPIRE_SECONDS #if !STATUS_EXPIRE_SECONDS
#if ENABLED(STATUS_MESSAGE_SCROLLING) #if ENABLED(STATUS_MESSAGE_SCROLLING)
else else if (blink_changed())
draw_status_message(); draw_status_message();
#endif #endif
#else #else