From a18d16fb8b92c78093e25f8bb88cd0a49074678e Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Fri, 27 Sep 2019 03:38:43 -0600 Subject: [PATCH] Do not implicitly concatenate localized strings (#15383) --- Marlin/src/core/macros.h | 7 ++++ Marlin/src/gcode/bedlevel/abl/G29.cpp | 2 +- Marlin/src/gcode/motion/M290.cpp | 10 ++--- Marlin/src/lcd/menu/menu_info.cpp | 59 ++++++++++++++++----------- Marlin/src/lcd/menu/menu_media.cpp | 6 ++- Marlin/src/module/endstops.cpp | 2 +- Marlin/src/module/temperature.cpp | 13 +++--- 7 files changed, 62 insertions(+), 37 deletions(-) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index ecc51b2c70..7a21d290d6 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -61,6 +61,13 @@ // Nanoseconds per cycle #define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU) +// Macros to make sprintf_P read from PROGMEM (AVR extension) +#ifdef __AVR__ + #define S_FMT "%S" +#else + #define S_FMT "%s" +#endif + // Macros to make a string from a macro #define STRINGIFY_(M) #M #define STRINGIFY(M) STRINGIFY_(M) diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 584d3a11c6..82dc02502e 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -715,7 +715,7 @@ G29_TYPE GcodeSuite::G29() { if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), "."); #if HAS_DISPLAY - ui.status_printf_P(0, PSTR(MSG_PROBING_MESH " %i/%i"), int(pt_index), int(GRID_MAX_POINTS)); + ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), PSTR(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS)); #endif measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(xProbe, yProbe, raise_after, verbose_level); diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index 8b89ee194b..a2ac85cd0b 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -46,13 +46,13 @@ SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", probe_offset[Z_AXIS]); } - #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) - else { + else { + #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) hotend_offset[Z_AXIS][active_extruder] -= offs; SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(MSG_Z_OFFSET ": ", hotend_offset[Z_AXIS][active_extruder]); - } - #endif + SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", hotend_offset[Z_AXIS][active_extruder]); + #endif + } } #endif diff --git a/Marlin/src/lcd/menu/menu_info.cpp b/Marlin/src/lcd/menu/menu_info.cpp index 815f20ace2..86e86dbdee 100644 --- a/Marlin/src/lcd/menu/menu_info.cpp +++ b/Marlin/src/lcd/menu/menu_info.cpp @@ -34,6 +34,9 @@ #include "game/game.h" #endif +#define STATIC_PAIR(MSG, VALUE, CNTR) do{ strcpy_P(buffer, PSTR(": ")); strcpy(buffer + 2, VALUE); STATIC_ITEM(MSG, CNTR, false, buffer); }while(0) +#define STATIC_PAIR_P(MSG, PVALUE, CNTR) do{ strcpy_P(buffer, PSTR(": ")); strcpy_P(buffer + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, CNTR, false, buffer); }while(0) + #if ENABLED(PRINTCOUNTER) #include "../../module/printcounter.h" @@ -48,27 +51,27 @@ #endif ); - char buffer[21]; + char buffer[21]; // for STATIC_PAIR_P + printStatistics stats = print_job_timer.getStats(); START_SCREEN(); // 12345678901234567890 - STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, i16tostr3left(stats.totalPrints)); // Print Count: 999 - STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, i16tostr3left(stats.finishedPrints)); // Completed : 666 + STATIC_PAIR(MSG_INFO_PRINT_COUNT, i16tostr3left(stats.totalPrints), false); // Print Count: 999 + STATIC_PAIR(MSG_INFO_COMPLETED_PRINTS, i16tostr3left(stats.finishedPrints), false); // Completed : 666 duration_t elapsed = stats.printTime; elapsed.toString(buffer); - STATIC_ITEM(MSG_INFO_PRINT_TIME ":", false, false); // Total print Time: + STATIC_PAIR_P(MSG_INFO_PRINT_TIME, "", false); // Total print Time: STATIC_ITEM("> ", false, false, buffer); // > 99y 364d 23h 59m 59s + STATIC_PAIR_P(MSG_INFO_PRINT_LONGEST, "", false); // Longest job time: elapsed = stats.longestPrint; elapsed.toString(buffer); - - STATIC_ITEM(MSG_INFO_PRINT_LONGEST ":", false, false); // Longest job time: STATIC_ITEM("> ", false, false, buffer); // > 99y 364d 23h 59m 59s + STATIC_PAIR_P(MSG_INFO_PRINT_FILAMENT, "", false); // Extruded total: sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10); - STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ":", false, false); // Extruded total: STATIC_ITEM("> ", false, false, buffer); // > 125m #if SERVICE_INTERVAL_1 > 0 @@ -77,12 +80,14 @@ STATIC_ITEM(SERVICE_NAME_1 MSG_SERVICE_IN, false, false); // Service X in: STATIC_ITEM("> ", false, false, buffer); // > 7d 12h 11m 10s #endif + #if SERVICE_INTERVAL_2 > 0 elapsed = stats.nextService2; elapsed.toString(buffer); STATIC_ITEM(SERVICE_NAME_2 MSG_SERVICE_IN, false, false); STATIC_ITEM("> ", false, false, buffer); #endif + #if SERVICE_INTERVAL_3 > 0 elapsed = stats.nextService3; elapsed.toString(buffer); @@ -104,13 +109,16 @@ void menu_info_thermistors() { true #endif ); + + char buffer[21]; // for STATIC_PAIR_P + START_SCREEN(); #if EXTRUDERS #define THERMISTOR_ID TEMP_SENSOR_0 #include "../thermistornames.h" STATIC_ITEM("T0: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_0_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_0_MAXTEMP), false); #endif #if TEMP_SENSOR_1 != 0 @@ -118,8 +126,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_1 #include "../thermistornames.h" STATIC_ITEM("T1: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_1_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_1_MAXTEMP), false); #endif #if TEMP_SENSOR_2 != 0 @@ -127,8 +135,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_2 #include "../thermistornames.h" STATIC_ITEM("T2: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_2_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_2_MAXTEMP), false); #endif #if TEMP_SENSOR_3 != 0 @@ -136,8 +144,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_3 #include "../thermistornames.h" STATIC_ITEM("T3: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_3_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_3_MAXTEMP), false); #endif #if TEMP_SENSOR_4 != 0 @@ -145,8 +153,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_4 #include "../thermistornames.h" STATIC_ITEM("T4: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_4_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_4_MAXTEMP), false); #endif #if TEMP_SENSOR_5 != 0 @@ -154,8 +162,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_5 #include "../thermistornames.h" STATIC_ITEM("T5: " THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_5_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_5_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_5_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_5_MAXTEMP), false); #endif #if HAS_HEATED_BED @@ -163,8 +171,8 @@ void menu_info_thermistors() { #define THERMISTOR_ID TEMP_SENSOR_BED #include "../thermistornames.h" STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true); - STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false); - STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false); + STATIC_PAIR_P(MSG_INFO_MIN_TEMP, STRINGIFY(BED_MINTEMP), false); + STATIC_PAIR_P(MSG_INFO_MAX_TEMP, STRINGIFY(BED_MAXTEMP), false); #endif END_SCREEN(); } @@ -178,14 +186,17 @@ void menu_info_board() { true #endif ); + + char buffer[21]; // for STATIC_PAIR_P + START_SCREEN(); STATIC_ITEM(BOARD_INFO_NAME, true, true); // MyPrinterController #ifdef BOARD_WEBSITE_URL STATIC_ITEM(BOARD_WEBSITE_URL, false, false); // www.my3dprinter.com #endif - STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000 - STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0 - STATIC_ITEM(MSG_INFO_PSU ": " PSU_NAME, true); + STATIC_PAIR_P(MSG_INFO_BAUDRATE, STRINGIFY(BAUDRATE), true); // Baud: 250000 + STATIC_PAIR_P(MSG_INFO_PROTOCOL, PROTOCOL_VERSION, true); // Protocol: 1.0 + STATIC_PAIR_P(MSG_INFO_PSU, PSU_NAME, true); END_SCREEN(); } diff --git a/Marlin/src/lcd/menu/menu_media.cpp b/Marlin/src/lcd/menu/menu_media.cpp index c909606f6a..b11963b173 100644 --- a/Marlin/src/lcd/menu/menu_media.cpp +++ b/Marlin/src/lcd/menu/menu_media.cpp @@ -82,10 +82,14 @@ inline void sdcard_start_selected_file() { #if ENABLED(SD_MENU_CONFIRM_START) void menu_sd_confirm() { + char * const longest = card.longest_filename(); + char buffer[strlen(longest) + 2]; + buffer[0] = ' '; + strcpy(buffer + 1, longest); do_select_screen( PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL), sdcard_start_selected_file, ui.goto_previous_screen, - PSTR(MSG_START_PRINT " "), card.longest_filename(), PSTR("?") + PSTR(MSG_START_PRINT), buffer, PSTR("?") ); } diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 04f1ab6b17..6970a051b3 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -373,7 +373,7 @@ void Endstops::event_handler() { SERIAL_EOL(); #if HAS_SPI_LCD - ui.status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP); + ui.status_printf_P(0, PSTR(S_FMT " %c %c %c %c"), PSTR(MSG_LCD_ENDSTOPS), chrX, chrY, chrZ, chrP); #endif #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 9542aa2ed2..d637b68d7b 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2933,11 +2933,14 @@ void Temperature::isr() { #if HOTENDS && HAS_DISPLAY void Temperature::set_heating_message(const uint8_t e) { const bool heating = isHeatingHotend(e); - #if HOTENDS > 1 - ui.status_printf_P(0, heating ? PSTR("E%c " MSG_HEATING) : PSTR("E%c " MSG_COOLING), '1' + e); - #else - ui.set_status_P(heating ? PSTR("E " MSG_HEATING) : PSTR("E " MSG_COOLING)); - #endif + ui.status_printf_P(0, + #if HOTENDS > 1 + PSTR("E%c " S_FMT), '1' + e + #else + PSTR("E " S_FMT) + #endif + , heating ? PSTR(MSG_HEATING) : PSTR(MSG_COOLING) + ); } #endif