From 569bbb18d0cf38fe506b1181c308c4bea581ce2a Mon Sep 17 00:00:00 2001 From: EvilGremlin <22657714+EvilGremlin@users.noreply.github.com> Date: Sat, 17 Dec 2022 07:45:55 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20DOGM=20time=20overflow,=20?= =?UTF-8?q?alignment=20(#25103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 2 +- Marlin/src/libs/duration_t.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index d0910c44ba5d..cba58f5c02f9 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -449,7 +449,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const static char bufferc[13]; static void prepare_time_string(const duration_t &time, char prefix) { - char str[9]; + char str[13]; memset(&bufferc[2], 0x20, 5); // partialy fill with spaces to avoid artifacts and terminator bufferc[0] = prefix; bufferc[1] = ':'; diff --git a/Marlin/src/libs/duration_t.h b/Marlin/src/libs/duration_t.h index df2c9cd099c1..69a648441feb 100644 --- a/Marlin/src/libs/duration_t.h +++ b/Marlin/src/libs/duration_t.h @@ -151,7 +151,9 @@ struct duration_t { * 123456789 (strlen) * 12'34 * 99:59 - * 11d 12:33 + * 123:45 + * 1d 12:33 + * 9999d 12:33 */ uint8_t toDigital(char *buffer, bool with_days=false) const { const uint16_t h = uint16_t(this->hour()), @@ -159,7 +161,7 @@ struct duration_t { if (with_days) { const uint16_t d = this->day(); sprintf_P(buffer, PSTR("%hud %02hu:%02hu"), d, h % 24, m); // 1d 23:45 - return d >= 10 ? 9 : 8; + return strlen_P(buffer); } else if (!h) { const uint16_t s = uint16_t(this->second() % 60UL);