diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 2534b43a2..cf0c368b2 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -306,9 +306,9 @@ const char menu_20x_space[] PROGMEM = " "; const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d"; -const char menu_fmt_float31[] PROGMEM = "%-12.12s%+8.1f"; +const char menu_fmt_float31[] PROGMEM = "%-12.12S%+8.1f"; -const char menu_fmt_float13[] PROGMEM = "%c%.12S:%s%+06.3f"; +const char menu_fmt_float13[] PROGMEM = "%-15.15S%+5.3f"; const char menu_fmt_float13off[] PROGMEM = "%c%.12S:%s%"; @@ -348,39 +348,36 @@ void menu_draw_P(char chr, const char* str, int16_t val) } } -//! Draw up to 10 chars of text, ':' and float number in format from +0.0 to +12345.0. The increased range is necessary +//! @brief Draw up to 10 chars of text and a float number in format from +0.0 to +12345.0. The increased range is necessary //! for displaying large values of extruder positions, which caused text overflow in the previous implementation. +//! //! @param chr first character to print on the line -//! @param str string label to print, will be appended with ':' automatically inside the function +//! @param str string label to print //! @param val value to print aligned to the right side of the display //! //! Implementation comments: -//! The text needs to be prerendered into the prerendered[] to enable left alignment of text str including the colon behind it. -//! If we didn't want the colon behind it, the whole operation would have been solved with a single vsprintf call, -//! but such line would look different compared to every other similar menu item -//! So it is almost the same amount of code like before, but with added string prerendering -void menu_draw_float31(char chr, const char* str, float val) +//! The text needs to come with a colon ":", this function does not append it anymore. +//! That resulted in a much shorter implementation (234628B -> 234476B) +//! There are similar functions around which may be shortened in a similar way +void menu_draw_float31(const char* str, float val) { - uint8_t txtlen = strlen_P(str); - if( txtlen > 10 )txtlen = 10; - char prerendered[21]; - strcpy_P(prerendered, menu_20x_space); - prerendered[0] = chr; // start with the initial byte/space for menu navigation - strncpy_P(prerendered+1, str, 10); // render the text and limit it to max 10 characters - prerendered[txtlen+1] = ':'; // put the colon behind it - prerendered[txtlen+2] = 0; // terminate the string to be used inside the printf - lcd_printf_P(menu_fmt_float31, prerendered, val); + lcd_printf_P(menu_fmt_float31, str, val); } -//draw up to 12 chars of text, ':' and float number in format +1.234 -void menu_draw_float13(char chr, const char* str, float val) +//! @brief Draw up to 12 chars of text and a float number in format +1.234 +//! +//! @param chr first character to print on the line +//! @param str string label to print +//! @param val value to print aligned to the right side of the display +//! +//! Implementation comments: +//! This function uses similar optimization principles as menu_draw_float31 +//! (i.e. str must include a ':' at its end) +//! FLASH usage dropped 234476B -> 234392B +//! Moreover, this function gets inlined in the final code, so removing it doesn't really help ;) +void menu_draw_float13(const char* str, float val) { - int text_len = strlen_P(str); - if (text_len > 12) text_len = 12; - char spaces[21]; - strcpy_P(spaces, menu_20x_space); - spaces[12 - text_len] = 0; - lcd_printf_P(menu_fmt_float13, chr, str, spaces, val); + lcd_printf_P(menu_fmt_float13, str, val); } template diff --git a/Firmware/menu.h b/Firmware/menu.h index 7ddfe3f24..9800550b9 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -97,11 +97,12 @@ extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode); extern const char menu_fmt_int3[]; extern const char menu_fmt_float31[]; +extern const char menu_fmt_float13[]; -extern void menu_draw_float31(char chr, const char* str, float val); +extern void menu_draw_float31(const char* str, float val); -extern void menu_draw_float13(char chr, const char* str, float val); +extern void menu_draw_float13(const char* str, float val); #define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_P(str, pval, minval, maxval)) return; } while (0) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp old mode 100644 new mode 100755 index 205c562d5..47d97d9de --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3079,7 +3079,7 @@ static void _lcd_move(const char *name, int axis, int min, int max) if (lcd_draw_update) { lcd_set_cursor(0, 1); - menu_draw_float31(' ', name, current_position[axis]); + menu_draw_float31(name, current_position[axis]); } if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious); if (LCD_CLICKED) menu_back(); @@ -3104,7 +3104,9 @@ static void lcd_move_e() if (lcd_draw_update) { lcd_set_cursor(0, 1); - menu_draw_float31(' ', PSTR("Extruder"), current_position[E_AXIS]); + // Note: the colon behind the text is necessary to greatly shorten + // the implementation of menu_draw_float31 + menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]); } if (LCD_CLICKED) menu_back(); } @@ -3224,14 +3226,16 @@ void EEPROM_read_B(int pos, int* value) } +// Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten +// the implementation of menu_draw_float31 static void lcd_move_x() { - _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); + _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS); } static void lcd_move_y() { - _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); + _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); } static void lcd_move_z() { - _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); + _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); } @@ -3304,7 +3308,7 @@ static void _lcd_babystep(int axis, const char *msg) if (lcd_draw_update) { lcd_set_cursor(0, 1); - menu_draw_float13(' ', msg, _md->babystepMemMM[axis]); + menu_draw_float13(msg, _md->babystepMemMM[axis]); } if (LCD_CLICKED || menu_leaving) { @@ -3320,7 +3324,7 @@ static void _lcd_babystep(int axis, const char *msg) static void lcd_babystep_z() { - _lcd_babystep(Z_AXIS, (_i("Adjusting Z")));////MSG_BABYSTEPPING_Z c=20 + _lcd_babystep(Z_AXIS, (_i("Adjusting Z:")));////MSG_BABYSTEPPING_Z c=20 Beware: must include the ':' as its last character } diff --git a/lang/lang_en.txt b/lang/lang_en.txt old mode 100644 new mode 100755 index 3de507cb9..73a67ce72 --- a/lang/lang_en.txt +++ b/lang/lang_en.txt @@ -17,7 +17,7 @@ ">Cancel" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" +"Adjusting Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_cz.txt b/lang/lang_en_cz.txt old mode 100644 new mode 100755 index 9db15b026..66b5e4eb5 --- a/lang/lang_en_cz.txt +++ b/lang/lang_en_cz.txt @@ -23,8 +23,8 @@ ">Zrusit" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Dostavovani Z" +"Adjusting Z:" +"Dostavovani Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_de.txt b/lang/lang_en_de.txt old mode 100644 new mode 100755 index 66995f4e4..9f11328f1 --- a/lang/lang_en_de.txt +++ b/lang/lang_en_de.txt @@ -23,8 +23,8 @@ ">Abbruch" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Z wurde eingestellt" +"Adjusting Z:" +"Z Einstellung:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_es.txt b/lang/lang_en_es.txt old mode 100644 new mode 100755 index 05757313c..10bdbdd30 --- a/lang/lang_en_es.txt +++ b/lang/lang_en_es.txt @@ -23,8 +23,8 @@ ">Cancelar" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Ajustar Z" +"Adjusting Z:" +"Ajustar Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_fr.txt b/lang/lang_en_fr.txt old mode 100644 new mode 100755 index 9dd3d489f..5136e4605 --- a/lang/lang_en_fr.txt +++ b/lang/lang_en_fr.txt @@ -23,8 +23,8 @@ ">Annuler" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Ajustement de Z" +"Adjusting Z:" +"Ajust. de Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_it.txt b/lang/lang_en_it.txt old mode 100644 new mode 100755 index 45bddac73..2adc45c23 --- a/lang/lang_en_it.txt +++ b/lang/lang_en_it.txt @@ -23,8 +23,8 @@ ">Annulla" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Compensazione Z" +"Adjusting Z:" +"Compensaz. Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct " diff --git a/lang/lang_en_pl.txt b/lang/lang_en_pl.txt old mode 100644 new mode 100755 index d0937dd86..e4fadbc81 --- a/lang/lang_en_pl.txt +++ b/lang/lang_en_pl.txt @@ -23,8 +23,8 @@ ">Anuluj" #MSG_BABYSTEPPING_Z c=20 -"Adjusting Z" -"Dostrajanie Z" +"Adjusting Z:" +"Dostrajanie Z:" #MSG_SELFTEST_CHECK_ALLCORRECT c=20 "All correct "