From fbc3fdb490bd91573bea966ca71d25be2fb885f3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 17 Jul 2018 15:00:42 -0500 Subject: [PATCH] LCD strlen functions like 2.0.x --- Marlin/status_screen_DOGM.h | 6 +++--- Marlin/status_screen_lite_ST7920.h | 6 +++--- Marlin/ultralcd.cpp | 4 ++-- Marlin/ultralcd.h | 4 ++-- Marlin/ultralcd_impl_DOGM.h | 8 ++++---- Marlin/ultralcd_impl_HD44780.h | 16 ++++++++-------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Marlin/status_screen_DOGM.h b/Marlin/status_screen_DOGM.h index 038351cc8..98678807b 100644 --- a/Marlin/status_screen_DOGM.h +++ b/Marlin/status_screen_DOGM.h @@ -126,7 +126,7 @@ inline void lcd_implementation_status_message(const bool blink) { static bool last_blink = false; // Get the UTF8 character count of the string - uint8_t slen = lcd_strlen(lcd_status_message); + uint8_t slen = utf8_strlen(lcd_status_message); // If the string fits into the LCD, just print it and do not scroll it if (slen <= LCD_WIDTH) { @@ -147,7 +147,7 @@ inline void lcd_implementation_status_message(const bool blink) { const char *stat = lcd_status_message + status_scroll_offset; // Get the string remaining length - const uint8_t rlen = lcd_strlen(stat); + const uint8_t rlen = utf8_strlen(stat); // If we have enough characters to display if (rlen >= LCD_WIDTH) { @@ -183,7 +183,7 @@ inline void lcd_implementation_status_message(const bool blink) { UNUSED(blink); // Get the UTF8 character count of the string - uint8_t slen = lcd_strlen(lcd_status_message); + uint8_t slen = utf8_strlen(lcd_status_message); // Just print the string to the LCD lcd_print_utf(lcd_status_message, LCD_WIDTH); diff --git a/Marlin/status_screen_lite_ST7920.h b/Marlin/status_screen_lite_ST7920.h index 2acb6a973..144591da7 100644 --- a/Marlin/status_screen_lite_ST7920.h +++ b/Marlin/status_screen_lite_ST7920.h @@ -618,7 +618,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) { const uint8_t lcd_len = 16; #if ENABLED(STATUS_MESSAGE_SCROLLING) - uint8_t slen = lcd_strlen(str); + uint8_t slen = utf8_strlen(str); // If the string fits into the LCD, just print it and do not scroll it if (slen <= lcd_len) { @@ -639,7 +639,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) { const char *stat = str + status_scroll_offset; // Get the string remaining length - const uint8_t rlen = lcd_strlen(stat); + const uint8_t rlen = utf8_strlen(stat); // If we have enough characters to display if (rlen >= lcd_len) { @@ -670,7 +670,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) { } #else // Get the UTF8 character count of the string - uint8_t slen = lcd_strlen(str); + uint8_t slen = utf8_strlen(str); // Just print the string to the LCD write_str(str, lcd_len); diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 4b61d4963..509cc5547 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -5050,7 +5050,7 @@ void lcd_init() { #endif } -int16_t lcd_strlen(const char* s) { +int16_t utf8_strlen(const char* s) { int16_t i = 0, j = 0; while (s[i]) { if (START_OF_UTF8_CHAR(s[i])) j++; @@ -5059,7 +5059,7 @@ int16_t lcd_strlen(const char* s) { return j; } -int16_t lcd_strlen_P(const char* s) { +int16_t utf8_strlen_P(const char* s) { int16_t j = 0; while (pgm_read_byte(s)) { if (START_OF_UTF8_CHAR(pgm_read_byte(s))) j++; diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index e03efceba..d6bc79968 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -41,8 +41,8 @@ #include "Marlin.h" - int16_t lcd_strlen(const char* s); - int16_t lcd_strlen_P(const char* s); + int16_t utf8_strlen(const char* s); + int16_t utf8_strlen_P(const char* s); bool lcd_hasstatus(); void lcd_setstatus(const char* message, const bool persist=false); void lcd_setstatusPGM(const char* message, const int8_t level=0); diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h index c5fd1999c..2b89a28d2 100644 --- a/Marlin/ultralcd_impl_DOGM.h +++ b/Marlin/ultralcd_impl_DOGM.h @@ -468,7 +468,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop int8_t n = LCD_WIDTH - (START_COL); if (center && !valstr) { - int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; + int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; while (--pad >= 0) { u8g.print(' '); n--; } } while (n > 0 && (c = pgm_read_byte(pstr))) { @@ -514,7 +514,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop if (!PAGE_CONTAINS(row_y1, row_y2)) return; - const uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data))); + const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data)); uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen; while (char c = pgm_read_byte(pstr)) { @@ -535,8 +535,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop #define DRAW_BOOL_SETTING(sel, row, pstr, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) { - const uint8_t labellen = lcd_strlen_P(pstr), - vallen = lcd_strlen(value); + const uint8_t labellen = utf8_strlen_P(pstr), + vallen = utf8_strlen(value); uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1; diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index e2be71332..7081b2198 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -491,7 +491,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) { // Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line void lcd_scroll(const int16_t col, const int16_t line, const char* const text, const int16_t len, const int16_t time) { - uint8_t slen = lcd_strlen_P(text); + uint8_t slen = utf8_strlen_P(text); if (slen < len) { // Fits into, lcd.setCursor(col, line); @@ -926,7 +926,7 @@ static void lcd_implementation_status_screen() { static bool last_blink = false; // Get the UTF8 character count of the string - uint8_t slen = lcd_strlen(lcd_status_message); + uint8_t slen = utf8_strlen(lcd_status_message); // If the string fits into the LCD, just print it and do not scroll it if (slen <= LCD_WIDTH) { @@ -947,7 +947,7 @@ static void lcd_implementation_status_screen() { const char *stat = lcd_status_message + status_scroll_offset; // Get the string remaining length - const uint8_t rlen = lcd_strlen(stat); + const uint8_t rlen = utf8_strlen(stat); // If we have enough characters to display if (rlen >= LCD_WIDTH) { @@ -984,7 +984,7 @@ static void lcd_implementation_status_screen() { UNUSED(blink); // Get the UTF8 character count of the string - uint8_t slen = lcd_strlen(lcd_status_message); + uint8_t slen = utf8_strlen(lcd_status_message); // Just print the string to the LCD lcd_print_utf(lcd_status_message, LCD_WIDTH); @@ -1019,8 +1019,8 @@ static void lcd_implementation_status_screen() { int8_t n = LCD_WIDTH; lcd.setCursor(0, row); if (center && !valstr) { - int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; while (--pad >= 0) { lcd.write(' '); n--; } + int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; } while (n > 0 && (c = pgm_read_byte(pstr))) { n -= charset_mapper(c); @@ -1048,9 +1048,9 @@ static void lcd_implementation_status_screen() { static void lcd_implementation_drawmenu_setting_edit_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) { char c; - uint8_t n = LCD_WIDTH - 2 - lcd_strlen(data); lcd.setCursor(0, row); lcd.print(sel ? pre_char : ' '); + uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data); while ((c = pgm_read_byte(pstr)) && n > 0) { n -= charset_mapper(c); pstr++; @@ -1061,9 +1061,9 @@ static void lcd_implementation_status_screen() { } static void lcd_implementation_drawmenu_setting_edit_generic_P(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) { char c; - uint8_t n = LCD_WIDTH - 2 - lcd_strlen_P(data); lcd.setCursor(0, row); lcd.print(sel ? pre_char : ' '); + uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data); while ((c = pgm_read_byte(pstr)) && n > 0) { n -= charset_mapper(c); pstr++; @@ -1081,10 +1081,10 @@ static void lcd_implementation_status_screen() { lcd_printPGM_utf(pstr); if (value != NULL) { lcd.write(':'); - const uint8_t valrow = (lcd_strlen_P(pstr) + 1 + lcd_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit lcd.setCursor((LCD_WIDTH - 1) - (lcd_strlen(value) + 1), valrow); // Right-justified, padded by spaces lcd.write(' '); // overwrite char if value gets shorter lcd_print(value); + const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + utf8_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit } }