Replace noob code with pro code for assembling string

%02d pads an integer with leading zeros up to 2 digits. Amazing!
This commit is contained in:
pkkrusty 2022-02-04 19:22:29 +00:00 committed by GitHub
parent abee978080
commit 5e20756922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -996,41 +996,8 @@ void TM1637ShowTime()
} }
char tm[9]; char tm[9];
if (hr < 10) snprintf_P(tm, sizeof(tm), PSTR("%c%d%02d%02d"), z, hr, mn, sc);
{
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);
}
}
if (TM1637 == TM1637Data.display_type) if (TM1637 == TM1637Data.display_type)
{ {
uint8_t rawBytes[1]; uint8_t rawBytes[1];