pitrix/src/effect_big_clock.cpp

90 lines
2.2 KiB
C++

#include "Effect.h"
#include "effect_big_clock.h"
#include "fonts.h"
#include "ntp.h"
void BigClockEffect::loop(uint16_t ms) {
window->clear();
uint8_t h = ntpClient.getHours();
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 = ntpClient.getMinutes();
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 = ntpClient.getSeconds();
if (s & 1) {
window->setPixel(3, 10, &_color_font);
window->setPixel(3, 12, &_color_font);
}
_draw_seconds();
}
void BigClockEffect::_draw_seconds() {
uint8_t seconds = ntpClient.getSeconds();
for (int i=1; i<=seconds; i++) {
_draw_border_pixel(i, 0, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
}
uint16_t millis = ntpClient.getEpochMillis() % 1000;
/*
// Enable this to have the next pixel move smoothly to its position
if (millis > 0) {
uint8_t part = 60 - ((60 - seconds) * millis / 1000);
_draw_border_pixel(part, &_color_seconds);
}
*/
uint8_t offset = 5 - ((millis % 1000) / 200);
uint8_t part = scale8(millis % 200, 200);
uint8_t number_to_show = (60 - seconds - offset) / 5 + 1;
for(uint8_t i = 0; i<number_to_show; i++) {
uint8_t pos = seconds + offset + i*5;
_draw_border_pixel(pos, part, (seconds + i + 1)%5==0 ? &_color_seconds_light : &_color_seconds_dark);
}
}
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
/*uint8_t x, y;
if (i<=8) {
x = 7 + i;
y = 0;
} else if (i<=23) {
x = 15;
y = i - 8;
} else if (i<= 38) {
x = 15 - i + 23;
y = 15;
} else if (i <= 53) {
x = 0;
y = 15 - i + 38;
} else if (i <= 60) {
x = i - 53;
y = 0;
} else {
return;
}
window->setPixel(x, y, color);*/
accum88 x, y;
if (i<=8) {
x = ((7+i)<<8) + part;
y = 0;
} else if (i<=23) {
x = 15<<8;
y = ((i-8)<<8) + part;
} else if (i<=38) {
x = ((38-i)<<8) - part;
y = 15<<8;
} else if (i<=53) {
x = 0;
y = ((53-i)<<8) - part;
} else if (i<=60) {
x = ((i-53)<<8) + part;
y = 0;
} else {
return;
}
window->setSubPixel(x, y, color);
}