Optimize LCD string/char printing

master
Scott Lahteine 8 years ago
parent 445d8215e4
commit f20b2b21eb

@ -189,29 +189,32 @@ static void lcd_setFont(char font_nr) {
} }
} }
char lcd_print(char c) { void lcd_print(char c) {
if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
u8g.setFont(FONT_SPECIAL_NAME);
u8g.print(c);
lcd_setFont(currentfont);
}
else charset_mapper(c);
}
char lcd_print_and_count(char c) {
if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) { if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
u8g.setFont(FONT_SPECIAL_NAME); u8g.setFont(FONT_SPECIAL_NAME);
u8g.print(c); u8g.print(c);
lcd_setFont(currentfont); lcd_setFont(currentfont);
return 1; return 1;
} else {
return charset_mapper(c);
} }
else return charset_mapper(c);
} }
char lcd_print(const char* str) { void lcd_print(const char* str) {
int i = 0; for (uint8_t i = 0; char c = str[i]; ++i) lcd_print(c);
char c, n = 0;
while ((c = str[i++])) n += lcd_print(c);
return n;
} }
// Needed for Arduino < 1.0.0 /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
char lcd_printPGM(const char* str) { void lcd_printPGM(const char* str) {
char c, n = 0; for (; char c = pgm_read_byte(str); ++str) lcd_print(c);
while ((c = pgm_read_byte(str++))) n += lcd_print(c);
return n;
} }
// Initialize or re-initializw the LCD // Initialize or re-initializw the LCD
@ -337,11 +340,11 @@ FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink)
lcd_printPGM(pstr); lcd_printPGM(pstr);
else { else {
if (!axis_homed[axis]) if (!axis_homed[axis])
lcd_printPGM(PSTR("?")); u8g.print('?');
else { else {
#if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING) #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
if (!axis_known_position[axis]) if (!axis_known_position[axis])
lcd_printPGM(PSTR(" ")); u8g.print(' ');
else else
#endif #endif
lcd_printPGM(pstr); lcd_printPGM(pstr);
@ -421,7 +424,7 @@ static void lcd_implementation_status_screen() {
int per = ((fanSpeeds[0] + 1) * 100) / 256; int per = ((fanSpeeds[0] + 1) * 100) / 256;
if (per) { if (per) {
lcd_print(itostr3(per)); lcd_print(itostr3(per));
lcd_print('%'); u8g.print('%');
} }
#endif #endif
@ -463,7 +466,7 @@ static void lcd_implementation_status_screen() {
lcd_setFont(FONT_STATUSMENU); lcd_setFont(FONT_STATUSMENU);
u8g.setPrintPos(12, 49); u8g.setPrintPos(12, 49);
lcd_print(itostr3(feedrate_percentage)); lcd_print(itostr3(feedrate_percentage));
lcd_print('%'); u8g.print('%');
// Status line // Status line
#if ENABLED(USE_SMALL_INFOFONT) #if ENABLED(USE_SMALL_INFOFONT)
@ -482,7 +485,7 @@ static void lcd_implementation_status_screen() {
lcd_print(ftostr12ns(filament_width_meas)); lcd_print(ftostr12ns(filament_width_meas));
lcd_printPGM(PSTR(" factor:")); lcd_printPGM(PSTR(" factor:"));
lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM])); lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
lcd_print('%'); u8g.print('%');
} }
#endif #endif
} }
@ -514,17 +517,17 @@ static void lcd_implementation_status_screen() {
if (center && !valstr) { if (center && !valstr) {
int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2; int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
while (--pad >= 0) { lcd_print(' '); n--; } while (--pad >= 0) { u8g.print(' '); n--; }
} }
while (n > 0 && (c = pgm_read_byte(pstr))) { while (n > 0 && (c = pgm_read_byte(pstr))) {
n -= lcd_print(c); n -= lcd_print_and_count(c);
pstr++; pstr++;
} }
if (valstr) while (n > 0 && (c = *valstr)) { if (valstr) while (n > 0 && (c = *valstr)) {
n -= lcd_print(c); n -= lcd_print_and_count(c);
valstr++; valstr++;
} }
while (n-- > 0) lcd_print(' '); while (n-- > 0) u8g.print(' ');
} }
#endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
@ -539,13 +542,13 @@ static void lcd_implementation_status_screen() {
lcd_implementation_mark_as_selected(row, isSelected); lcd_implementation_mark_as_selected(row, isSelected);
while (c = pgm_read_byte(pstr)) { while (c = pgm_read_byte(pstr)) {
n -= lcd_print(c); n -= lcd_print_and_count(c);
pstr++; pstr++;
} }
while (n--) lcd_print(' '); while (n--) u8g.print(' ');
u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT)); u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
lcd_print(post_char); lcd_print(post_char);
lcd_print(' '); u8g.print(' ');
} }
// Macros for specific types of menu items // Macros for specific types of menu items
@ -563,11 +566,11 @@ static void lcd_implementation_status_screen() {
lcd_implementation_mark_as_selected(row, isSelected); lcd_implementation_mark_as_selected(row, isSelected);
while (c = pgm_read_byte(pstr)) { while (c = pgm_read_byte(pstr)) {
n -= lcd_print(c); n -= lcd_print_and_count(c);
pstr++; pstr++;
} }
lcd_print(':'); u8g.print(':');
while (n--) lcd_print(' '); while (n--) u8g.print(' ');
u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, (row + 1) * (DOG_CHAR_HEIGHT)); u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, (row + 1) * (DOG_CHAR_HEIGHT));
if (pgm) lcd_printPGM(data); else lcd_print((char*)data); if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
} }
@ -621,7 +624,7 @@ static void lcd_implementation_status_screen() {
u8g.setPrintPos(0, rowHeight + kHalfChar); u8g.setPrintPos(0, rowHeight + kHalfChar);
lcd_printPGM(pstr); lcd_printPGM(pstr);
if (value != NULL) { if (value != NULL) {
lcd_print(':'); u8g.print(':');
u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, rows * rowHeight + kHalfChar); u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, rows * rowHeight + kHalfChar);
lcd_print(value); lcd_print(value);
} }
@ -643,10 +646,10 @@ static void lcd_implementation_status_screen() {
if (isDir) lcd_print(LCD_STR_FOLDER[0]); if (isDir) lcd_print(LCD_STR_FOLDER[0]);
while ((c = *filename)) { while ((c = *filename)) {
n -= lcd_print(c); n -= lcd_print_and_count(c);
filename++; filename++;
} }
while (n--) lcd_print(' '); while (n--) u8g.print(' ');
} }
#define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false) #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)

@ -375,20 +375,15 @@ static void lcd_implementation_init(
static void lcd_implementation_clear() { lcd.clear(); } static void lcd_implementation_clear() { lcd.clear(); }
/* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */ /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
char lcd_printPGM(const char* str) { void lcd_printPGM(const char *str) {
char c, n = 0; for (; char c = pgm_read_byte(str); ++str) charset_mapper(c);
while ((c = pgm_read_byte(str++))) n += charset_mapper(c);
return n;
} }
char lcd_print(const char* str) { void lcd_print(const char* str) {
char c, n = 0; for (uint8_t i = 0; char c = str[i]; ++i) charset_mapper(c);
unsigned char i = 0;
while ((c = str[i++])) n += charset_mapper(c);
return n;
} }
unsigned lcd_print(char c) { return charset_mapper(c); } void lcd_print(char c) { charset_mapper(c); }
#if ENABLED(SHOW_BOOTSCREEN) #if ENABLED(SHOW_BOOTSCREEN)
@ -556,11 +551,11 @@ FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink)
lcd_printPGM(pstr); lcd_printPGM(pstr);
else { else {
if (!axis_homed[axis]) if (!axis_homed[axis])
lcd_printPGM(PSTR("?")); lcd.print('?');
else { else {
#if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING) #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
if (!axis_known_position[axis]) if (!axis_known_position[axis])
lcd_printPGM(PSTR(" ")); lcd.print(' ');
else else
#endif #endif
lcd_printPGM(pstr); lcd_printPGM(pstr);
@ -694,7 +689,7 @@ static void lcd_implementation_status_screen() {
_draw_axis_label(X_AXIS, PSTR(MSG_X), blink); _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
lcd.print(ftostr4sign(current_position[X_AXIS])); lcd.print(ftostr4sign(current_position[X_AXIS]));
lcd_printPGM(PSTR(" ")); lcd.print(' ');
_draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink); _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
lcd.print(ftostr4sign(current_position[Y_AXIS])); lcd.print(ftostr4sign(current_position[Y_AXIS]));
@ -803,11 +798,11 @@ static void lcd_implementation_status_screen() {
while (--pad >= 0) { lcd.print(' '); n--; } while (--pad >= 0) { lcd.print(' '); n--; }
} }
while (n > 0 && (c = pgm_read_byte(pstr))) { while (n > 0 && (c = pgm_read_byte(pstr))) {
n -= lcd_print(c); n -= charset_mapper(c);
pstr++; pstr++;
} }
if (valstr) while (n > 0 && (c = *valstr)) { if (valstr) while (n > 0 && (c = *valstr)) {
n -= lcd_print(c); n -= charset_mapper(c);
valstr++; valstr++;
} }
while (n-- > 0) lcd.print(' '); while (n-- > 0) lcd.print(' ');
@ -821,7 +816,7 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(0, row); lcd.setCursor(0, row);
lcd.print(sel ? pre_char : ' '); lcd.print(sel ? pre_char : ' ');
while ((c = pgm_read_byte(pstr)) && n > 0) { while ((c = pgm_read_byte(pstr)) && n > 0) {
n -= lcd_print(c); n -= charset_mapper(c);
pstr++; pstr++;
} }
while (n--) lcd.print(' '); while (n--) lcd.print(' ');
@ -834,7 +829,7 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(0, row); lcd.setCursor(0, row);
lcd.print(sel ? pre_char : ' '); lcd.print(sel ? pre_char : ' ');
while ((c = pgm_read_byte(pstr)) && n > 0) { while ((c = pgm_read_byte(pstr)) && n > 0) {
n -= lcd_print(c); n -= charset_mapper(c);
pstr++; pstr++;
} }
lcd.print(':'); lcd.print(':');
@ -847,7 +842,7 @@ static void lcd_implementation_status_screen() {
lcd.setCursor(0, row); lcd.setCursor(0, row);
lcd.print(sel ? pre_char : ' '); lcd.print(sel ? pre_char : ' ');
while ((c = pgm_read_byte(pstr)) && n > 0) { while ((c = pgm_read_byte(pstr)) && n > 0) {
n -= lcd_print(c); n -= charset_mapper(c);
pstr++; pstr++;
} }
lcd.print(':'); lcd.print(':');
@ -899,7 +894,7 @@ static void lcd_implementation_status_screen() {
longFilename[n] = '\0'; longFilename[n] = '\0';
} }
while ((c = *filename) && n > 0) { while ((c = *filename) && n > 0) {
n -= lcd_print(c); n -= charset_mapper(c);
filename++; filename++;
} }
while (n--) lcd.print(' '); while (n--) lcd.print(' ');

Loading…
Cancel
Save