Browse Source

Fix LCD printing of progmem strings

Scott Lahteine 8 years ago
parent
commit
8d69394ae1
2 changed files with 12 additions and 16 deletions
  1. 6
    8
      Marlin/ultralcd_impl_DOGM.h
  2. 6
    8
      Marlin/ultralcd_impl_HD44780.h

+ 6
- 8
Marlin/ultralcd_impl_DOGM.h View File

239
  * On DOGM all strings go through a filter for utf
239
  * On DOGM all strings go through a filter for utf
240
  * But only use lcd_print_utf and lcd_printPGM_utf for translated text
240
  * But only use lcd_print_utf and lcd_printPGM_utf for translated text
241
  */
241
  */
242
-void lcd_print(const char* const str) { for (uint8_t i = 0; char c = str[i]; ++i) lcd_print(c); }
243
-void lcd_printPGM(const char* str) { for (; char c = pgm_read_byte(str); ++str) lcd_print(c); }
242
+void lcd_print(const char *str) { while (*str) lcd_print(*str++); }
243
+void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd_print(c), ++str; }
244
 
244
 
245
-void lcd_print_utf(const char* const str, const uint8_t maxLength=LCD_WIDTH) {
245
+void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
246
   char c;
246
   char c;
247
-  for (uint8_t i = 0, n = maxLength; n && (c = str[i]); ++i)
248
-    n -= charset_mapper(c);
247
+  while (n && (c = *str)) n -= charset_mapper(c), ++str;
249
 }
248
 }
250
 
249
 
251
-void lcd_printPGM_utf(const char* str, const uint8_t maxLength=LCD_WIDTH) {
250
+void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
252
   char c;
251
   char c;
253
-  for (uint8_t i = 0, n = maxLength; n && (c = str[i]); ++i)
254
-    n -= charset_mapper(c);
252
+  while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
255
 }
253
 }
256
 
254
 
257
 // Initialize or re-initialize the LCD
255
 // Initialize or re-initialize the LCD

+ 6
- 8
Marlin/ultralcd_impl_HD44780.h View File

382
 
382
 
383
 void lcd_print(const char c) { charset_mapper(c); }
383
 void lcd_print(const char c) { charset_mapper(c); }
384
 
384
 
385
-void lcd_print(const char * const str) { for (uint8_t i = 0; char c = str[i]; ++i) lcd.print(c); }
386
-void lcd_printPGM(const char* str) { for (; char c = pgm_read_byte(str); ++str) lcd.print(c); }
385
+void lcd_print(const char *str) { while (*str) lcd.print(*str++); }
386
+void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd.print(c), ++str; }
387
 
387
 
388
-void lcd_print_utf(const char * const str, const uint8_t maxLength=LCD_WIDTH) {
388
+void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
389
   char c;
389
   char c;
390
-  for (uint8_t i = 0, n = maxLength; n && (c = str[i]); ++i)
391
-    n -= charset_mapper(c);
390
+  while (n && (c = *str)) n -= charset_mapper(c), ++str;
392
 }
391
 }
393
 
392
 
394
-void lcd_printPGM_utf(const char* str, const uint8_t maxLength=LCD_WIDTH) {
393
+void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
395
   char c;
394
   char c;
396
-  for (uint8_t i = 0, n = maxLength; n && (c = str[i]); ++i)
397
-    n -= charset_mapper(c);
395
+  while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
398
 }
396
 }
399
 
397
 
400
 #if ENABLED(SHOW_BOOTSCREEN)
398
 #if ENABLED(SHOW_BOOTSCREEN)

Loading…
Cancel
Save