diff --git a/Marlin/src/core/mstring.h b/Marlin/src/core/mstring.h index 7662f0f1a6ecc..819c1ab74f6f3 100644 --- a/Marlin/src/core/mstring.h +++ b/Marlin/src/core/mstring.h @@ -136,7 +136,7 @@ class MString { MString& setn(FSTR_P const f, int len) { return setn_P(FTOP(f), len); } // set(repchr_t('-', 10)) - MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); memset(str, s.asc, c); str[c] = '\0'; debug(F("")); return *this; } + MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); if (c >= 0) { if (c > 0) memset(str, s.asc, c); str[c] = '\0'; } debug(F("repchr_t")); return *this; } // set(spaces_t(10)) MString& set(const spaces_t &s) { repchr_t r(' ', s.count); return set(r); } diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index bcbf2f07aa459..74a60fa4087b7 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -309,10 +309,10 @@ typedef struct WFloat { float value; char width; char prec; typedef struct PFloat { float value; char prec; PFloat(float v, char p) : value(v), prec(p) {} } p_float_t; -typedef struct RepChr { char asc; uint8_t count; +typedef struct RepChr { char asc; int8_t count; RepChr(char a, uint8_t c) : asc(a), count(c) {} } repchr_t; -typedef struct Spaces { uint8_t count; +typedef struct Spaces { int8_t count; Spaces(uint8_t c) : count(c) {} } spaces_t; diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index ad9e382661624..e294d9c3df9b3 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -479,16 +479,16 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const // Prepare strings for progress display #if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS) static MarlinUI::progress_t progress = 0; - static MString<12> progressString; + static MString<13> progressString; #endif #if HAS_EXTRA_PROGRESS #if HAS_TIME_DISPLAY static void prepare_time_string(const duration_t &time, char prefix) { - char str[10]; + char str[13]; const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars - progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces + progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces } #endif #if ENABLED(SHOW_PROGRESS_PERCENT) diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp index 2039d99635812..4eb031e5385ab 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp @@ -662,39 +662,36 @@ bool ST7920_Lite_Status_Screen::indicators_changed() { // Process progress strings #if HAS_PRINT_PROGRESS - static char screenstr[8]; + static MString<8> screenstr; #if HAS_TIME_DISPLAY char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) { - static char str[6]; - memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts, not doing right-justification to save cycles - screenstr[0] = prefix; - TERN_(HOTENDS == 1, screenstr[1] = 0x07;) // add bullet • separator when there is space - int str_length = time.toDigital(str); - memcpy(&screenstr[TERN(HOTENDS == 1, 2, 1)], str, str_length); //memcpy because we can't have terminator - return screenstr; + static char time_str[6]; + (void)time.toDigital(time_str); // Up to 5 chars + screenstr = prefix; + if (HOTENDS == 1) screenstr += char(0x07); // Add bullet • separator when there is space + screenstr += time_str; + screenstr += Spaces(3); + return &screenstr; } #endif void ST7920_Lite_Status_Screen::draw_progress_string(uint8_t addr, const char *str) { set_ddram_address(addr); begin_data(); - write_str(str, TERN(HOTENDS == 1, 8, 6)); + write_str(str, HOTENDS == 1 ? 8 : 6); } - #define PPOS (DDRAM_LINE_3 + TERN(HOTENDS == 1, 4, 5)) // progress string position, in 16-bit words + constexpr uint8_t PPOS = (DDRAM_LINE_3 + (HOTENDS == 1 ? 4 : 5)); // Progress string position, in 16-bit words #if ENABLED(SHOW_PROGRESS_PERCENT) void MarlinUI::drawPercent() { lightUI.drawPercent(); } void ST7920_Lite_Status_Screen::drawPercent() { - #define LSHIFT TERN(HOTENDS == 1, 0, 1) const uint8_t progress = ui.get_progress_percent(); - memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts - if (progress){ - memcpy(&screenstr[2 - LSHIFT], \ - TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)), \ - TERN(PRINT_PROGRESS_SHOW_DECIMALS, 4, 3)); - screenstr[(TERN(PRINT_PROGRESS_SHOW_DECIMALS, 6, 5) - LSHIFT)] = '%'; + if (progress) { + screenstr += Spaces(1 + (HOTENDS == 1)); + screenstr += TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)); + screenstr += "% "; draw_progress_string(PPOS, screenstr); } } diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 60fb298dfcde7..4c5dec47616c3 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1035,9 +1035,13 @@ void MarlinUI::init() { uint8_t abs_diff = ABS(encoderDiff); #if ENCODER_PULSES_PER_STEP > 1 - static int8_t lastEncoderDiff; - TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen()); - lastEncoderDiff = encoderDiff; + #if HAS_TOUCH_SLEEP + static int8_t lastEncoderDiff; + if (lastEncoderDiff != encoderDiff) { + wakeup_screen(); + lastEncoderDiff = encoderDiff; + } + #endif #endif const bool encoderPastThreshold = (abs_diff >= epps);