NewYear: SubSecondsBar when days <= 0
This commit is contained in:
parent
f5550c96f4
commit
f9ebb1093d
@ -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) {
|
||||
tm info{};
|
||||
time_t now;
|
||||
@ -57,6 +61,7 @@ class NewYear : public Mode<NewYear> {
|
||||
|
||||
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<NewYear> {
|
||||
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<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) {
|
||||
bool leapYear = year % 4 == 0 && (year % 400 == 0 || year % 100 != 0);
|
||||
if (leapYear) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user