From 6172eff331e3a47fbf187b8c7f9cac08c8fdf611 Mon Sep 17 00:00:00 2001 From: pkkrusty <79770016+pkkrusty@users.noreply.github.com> Date: Thu, 3 Feb 2022 21:20:43 +0000 Subject: [PATCH 1/3] Add seconds to MAX7219 DisplayClock command As extra digits are available, may as well use them to allow more accuracy. Also changed the colon/dot to remain illuminated since the seconds fulfill the heartbeat function, and colon/dot serves as just a separator. TM1637 and TM1638 code is unchanged. --- tasmota/xdsp_15_tm1637.ino | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tasmota/xdsp_15_tm1637.ino b/tasmota/xdsp_15_tm1637.ino index 05b269e9e..f69cbcfc3 100644 --- a/tasmota/xdsp_15_tm1637.ino +++ b/tasmota/xdsp_15_tm1637.ino @@ -979,6 +979,7 @@ void TM1637ShowTime() { uint8_t hr = RtcTime.hour; uint8_t mn = RtcTime.minute; + uint8_t sc = RtcTime.second; // uint8_t hr = 1; // uint8_t mn = 0; char z = ' '; @@ -998,16 +999,36 @@ void TM1637ShowTime() if (hr < 10) { if (mn < 10) - snprintf(tm, sizeof(tm), PSTR("%c%d0%d"), z, hr, mn); + { + if (sc < 10) + snprintf(tm, sizeof(tm), PSTR("%c%d0%d0%d"), z, hr, mn, sc); + else + snprintf(tm, sizeof(tm), PSTR("%c%d0%d%d"), z, hr, mn, sc); + } else - snprintf(tm, sizeof(tm), PSTR("%c%d%d"), z, hr, mn); + { + if (sc < 10) + snprintf(tm, sizeof(tm), PSTR("%c%d%d0%d"), z, hr, mn, sc); + else + snprintf(tm, sizeof(tm), PSTR("%c%d%d%d"), z, hr, mn, sc); + } } else { if (mn < 10) - snprintf(tm, sizeof(tm), PSTR("%d0%d"), hr, mn); + { + if (sc < 10) + snprintf(tm, sizeof(tm), PSTR("%d0%d0%d"), hr, mn, sc); + else + snprintf(tm, sizeof(tm), PSTR("%d0%d%d"), hr, mn, sc); + } else - snprintf(tm, sizeof(tm), PSTR("%d%d"), hr, mn); + { + if (sc < 10) + snprintf(tm, sizeof(tm), PSTR("%d%d0%d"), hr, mn, sc); + else + snprintf(tm, sizeof(tm), PSTR("%d%d%d"), hr, mn, sc); + } } if (TM1637 == TM1637Data.display_type) @@ -1035,7 +1056,8 @@ void TM1637ShowTime() { for (uint32_t i = 0; i < 4; i++) { - if ((millis() % 1000) > 500 && (i == 1)) + //if ((millis() % 1000) > 500 && (i == 3)) + if ((i == 1) || (i == 3)) displayMAX7219ASCIIwDot(i, tm[i]); else displayMAX7219ASCII(i, tm[i]); From abee97808036f7513788f883948c5500cc09ae44 Mon Sep 17 00:00:00 2001 From: pkkrusty <79770016+pkkrusty@users.noreply.github.com> Date: Fri, 4 Feb 2022 12:19:42 +0000 Subject: [PATCH 2/3] Forgot to change the length of tm variable --- tasmota/xdsp_15_tm1637.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdsp_15_tm1637.ino b/tasmota/xdsp_15_tm1637.ino index f69cbcfc3..744cf043d 100644 --- a/tasmota/xdsp_15_tm1637.ino +++ b/tasmota/xdsp_15_tm1637.ino @@ -995,7 +995,7 @@ void TM1637ShowTime() hr = 12; } - char tm[5]; + char tm[9]; if (hr < 10) { if (mn < 10) From 5e207569228a45668a9ef25703b504c6b748e765 Mon Sep 17 00:00:00 2001 From: pkkrusty <79770016+pkkrusty@users.noreply.github.com> Date: Fri, 4 Feb 2022 19:22:29 +0000 Subject: [PATCH 3/3] Replace noob code with pro code for assembling string %02d pads an integer with leading zeros up to 2 digits. Amazing! --- tasmota/xdsp_15_tm1637.ino | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/tasmota/xdsp_15_tm1637.ino b/tasmota/xdsp_15_tm1637.ino index 744cf043d..f0497f901 100644 --- a/tasmota/xdsp_15_tm1637.ino +++ b/tasmota/xdsp_15_tm1637.ino @@ -996,41 +996,8 @@ void TM1637ShowTime() } char tm[9]; - if (hr < 10) - { - if (mn < 10) - { - if (sc < 10) - snprintf(tm, sizeof(tm), PSTR("%c%d0%d0%d"), z, hr, mn, sc); - else - snprintf(tm, sizeof(tm), PSTR("%c%d0%d%d"), z, hr, mn, sc); - } - else - { - if (sc < 10) - snprintf(tm, sizeof(tm), PSTR("%c%d%d0%d"), z, hr, mn, sc); - else - snprintf(tm, sizeof(tm), PSTR("%c%d%d%d"), z, hr, mn, sc); - } - } - else - { - if (mn < 10) - { - if (sc < 10) - snprintf(tm, sizeof(tm), PSTR("%d0%d0%d"), hr, mn, sc); - else - snprintf(tm, sizeof(tm), PSTR("%d0%d%d"), hr, mn, sc); - } - else - { - if (sc < 10) - snprintf(tm, sizeof(tm), PSTR("%d%d0%d"), hr, mn, sc); - else - snprintf(tm, sizeof(tm), PSTR("%d%d%d"), hr, mn, sc); - } - } - + snprintf_P(tm, sizeof(tm), PSTR("%c%d%02d%02d"), z, hr, mn, sc); + if (TM1637 == TM1637Data.display_type) { uint8_t rawBytes[1];