NewYear: SecondsBar when days > 0

This commit is contained in:
Patrick Haßel 2023-01-02 10:31:25 +01:00
parent 897972059b
commit f5550c96f4

View File

@ -56,10 +56,10 @@ class NewYear : public Mode<NewYear> {
} }
void drawCountdown(const tm &time) { void drawCountdown(const tm &time) {
size_t days = getDayCountForYear(time.tm_year) - time.tm_yday - 1; int days = getDayCountForYear(time.tm_year) - time.tm_yday - 1;
size_t hours = (24 - time.tm_hour - (time.tm_min > 0 || time.tm_sec > 0 ? 1 : 0)); int hours = (24 - time.tm_hour - (time.tm_min > 0 || time.tm_sec > 0 ? 1 : 0));
size_t minutes = (60 - time.tm_min - (time.tm_sec > 0 ? 1 : 0)) % 60; int minutes = (60 - time.tm_min - (time.tm_sec > 0 ? 1 : 0)) % 60;
size_t seconds = (60 - time.tm_sec) % 60; int seconds = (60 - time.tm_sec) % 60;
uint8_t x = 0; uint8_t x = 0;
@ -75,10 +75,12 @@ class NewYear : public Mode<NewYear> {
if (days <= 0) { if (days <= 0) {
display->print(&x, 1, 10, COLOR_WHITE); display->print(&x, 1, 10, COLOR_WHITE);
draw2Digit(seconds, &x); draw2Digit(seconds, &x);
} else {
drawSecondsBar(seconds);
} }
} }
void drawDay(size_t days, uint8_t *x) { void drawDay(int days, uint8_t *x) {
if (days > 100) { if (days > 100) {
display->print(x, 1, days / 100, COLOR_WHITE); display->print(x, 1, days / 100, COLOR_WHITE);
} else { } else {
@ -96,7 +98,7 @@ class NewYear : public Mode<NewYear> {
display->print(x, 1, days % 10, COLOR_WHITE); display->print(x, 1, days % 10, COLOR_WHITE);
} }
void drawHour(size_t days, size_t hours, uint8_t *x) { void drawHour(int days, int hours, uint8_t *x) {
if (days > 0 || hours >= 10) { if (days > 0 || hours >= 10) {
display->print(x, 1, hours / 10, COLOR_WHITE); display->print(x, 1, hours / 10, COLOR_WHITE);
} else { } else {
@ -106,12 +108,22 @@ class NewYear : public Mode<NewYear> {
display->print(x, 1, hours % 10, COLOR_WHITE); display->print(x, 1, hours % 10, COLOR_WHITE);
} }
void draw2Digit(size_t value, uint8_t *x) { void draw2Digit(int value, uint8_t *x) {
display->print(x, 1, value / 10, COLOR_WHITE); display->print(x, 1, value / 10, COLOR_WHITE);
(*x)++; (*x)++;
display->print(x, 1, value % 10, COLOR_WHITE); display->print(x, 1, value % 10, COLOR_WHITE);
} }
void drawSecondsBar(int seconds) {
for (int pos = 0; pos < 30; pos++) {
if (pos <= seconds - 30) {
display->set(pos + 1, 7, 0, 255, 0);
} else if (pos <= seconds) {
display->set(pos + 1, 7, 255, 0, 0);
}
}
}
static int getDayCountForYear(int year) { static int getDayCountForYear(int year) {
bool leapYear = year % 4 == 0 && (year % 400 == 0 || year % 100 != 0); bool leapYear = year % 4 == 0 && (year % 400 == 0 || year % 100 != 0);
if (leapYear) { if (leapYear) {