From f9ebb1093d523d463375b5d292d138818ae8de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 2 Jan 2023 12:16:34 +0100 Subject: [PATCH] NewYear: SubSecondsBar when days <= 0 --- src/mode/NewYear/NewYear.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mode/NewYear/NewYear.h b/src/mode/NewYear/NewYear.h index 24ec5b2..b8fd622 100644 --- a/src/mode/NewYear/NewYear.h +++ b/src/mode/NewYear/NewYear.h @@ -1,7 +1,7 @@ #ifndef NEWYEAR_H #define NEWYEAR_H -#define MAX_FIREWORKS 10 +#define MAX_FIREWORKS 10 #include "mode/Mode.h" #include "Firework.h" @@ -20,6 +20,10 @@ class NewYear : public Mode { } } + int lastSecond = -1; + + unsigned long lastSecondMillis = 0; + void step(Timer *timer, uint32_t counter, uint32_t currentCount) { tm info{}; time_t now; @@ -57,6 +61,7 @@ class NewYear : public Mode { void drawCountdown(const tm &time) { int days = getDayCountForYear(time.tm_year) - time.tm_yday - 1; + int hours = (24 - time.tm_hour - (time.tm_min > 0 || time.tm_sec > 0 ? 1 : 0)); int minutes = (60 - time.tm_min - (time.tm_sec > 0 ? 1 : 0)) % 60; int seconds = (60 - time.tm_sec) % 60; @@ -75,6 +80,7 @@ class NewYear : public Mode { if (days <= 0) { display->print(&x, 1, 10, COLOR_WHITE); draw2Digit(seconds, &x); + drawSubSecondsBar(time.tm_sec); } else { drawSecondsBar(seconds); } @@ -124,6 +130,20 @@ class NewYear : public Mode { } } + void drawSubSecondsBar(const int second) { + if (lastSecond < 0 || lastSecond != second) { + lastSecond = second; + lastSecondMillis = millis(); + } + unsigned long mils = millis() - lastSecondMillis; + int level = (int) round(32 * mils / 1000.0); + for (int pos = 0; pos < 32; pos++) { + if (pos < 32 - level) { + display->set(pos, 7, 0, 255, 0); + } + } + } + static int getDayCountForYear(int year) { bool leapYear = year % 4 == 0 && (year % 400 == 0 || year % 100 != 0); if (leapYear) {