67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#include "Effect.h"
|
|
#include "effect_big_clock.h"
|
|
#include "fonts.h"
|
|
#include <time.h>
|
|
#include "settings.h"
|
|
|
|
void BigClockEffect::loop(uint16_t ms) {
|
|
window->clear();
|
|
time_t now;
|
|
tm timeinfo;
|
|
time(&now);
|
|
localtime_r(&now, &timeinfo);
|
|
uint8_t h = timeinfo.tm_hour;
|
|
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
|
|
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
|
|
|
|
uint8_t m = timeinfo.tm_min;
|
|
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
|
|
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
|
|
|
|
uint8_t s = timeinfo.tm_sec;
|
|
if (s & 1) {
|
|
window->setPixel(3, 10, &_color_font);
|
|
window->setPixel(3, 12, &_color_font);
|
|
}
|
|
|
|
_draw_seconds(timeinfo.tm_sec);
|
|
}
|
|
|
|
void BigClockEffect::_draw_seconds(uint8_t seconds) {
|
|
for (int i=1; i<=seconds; i++) {
|
|
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
|
|
}
|
|
|
|
uint16_t mil = millis() % 1000;
|
|
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8);
|
|
uint8_t sec = seconds + 1;
|
|
while (pos < (60<<8)) {
|
|
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
|
|
pos += settings.effects.big_clock.spacing<<8;
|
|
sec++;
|
|
}
|
|
}
|
|
|
|
void BigClockEffect::_draw_border_pixel(accum88 i, CRGB* color) {
|
|
accum88 x, y;
|
|
if (i<(8<<8)) {
|
|
x = i + (7<<8);
|
|
y = 0;
|
|
} else if (i<(23<<8)) {
|
|
x = 15<<8;
|
|
y = i - (8<<8);
|
|
} else if (i<(38<<8)) {
|
|
x = (38<<8) - i;
|
|
y = 15<<8;
|
|
} else if (i<(53<<8)) {
|
|
x = 0;
|
|
y = (53<<8) - i;
|
|
} else if (i<=(60<<8)) {
|
|
x = i - (53<<8);
|
|
y = 0;
|
|
} else {
|
|
return;
|
|
}
|
|
window->setSubPixel(x, y, color);
|
|
}
|