NewYear: SubSecondsBar when days <= 0

This commit is contained in:
Patrick Haßel 2023-01-02 12:16:34 +01:00
parent f5550c96f4
commit f9ebb1093d

View File

@ -1,7 +1,7 @@
#ifndef NEWYEAR_H #ifndef NEWYEAR_H
#define NEWYEAR_H #define NEWYEAR_H
#define MAX_FIREWORKS 10 #define MAX_FIREWORKS 10
#include "mode/Mode.h" #include "mode/Mode.h"
#include "Firework.h" #include "Firework.h"
@ -20,6 +20,10 @@ class NewYear : public Mode<NewYear> {
} }
} }
int lastSecond = -1;
unsigned long lastSecondMillis = 0;
void step(Timer *timer, uint32_t counter, uint32_t currentCount) { void step(Timer *timer, uint32_t counter, uint32_t currentCount) {
tm info{}; tm info{};
time_t now; time_t now;
@ -57,6 +61,7 @@ class NewYear : public Mode<NewYear> {
void drawCountdown(const tm &time) { void drawCountdown(const tm &time) {
int days = getDayCountForYear(time.tm_year) - time.tm_yday - 1; 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 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 minutes = (60 - time.tm_min - (time.tm_sec > 0 ? 1 : 0)) % 60;
int seconds = (60 - time.tm_sec) % 60; int seconds = (60 - time.tm_sec) % 60;
@ -75,6 +80,7 @@ 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);
drawSubSecondsBar(time.tm_sec);
} else { } else {
drawSecondsBar(seconds); drawSecondsBar(seconds);
} }
@ -124,6 +130,20 @@ class NewYear : public Mode<NewYear> {
} }
} }
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) { 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) {