2019-05-29 22:49:54 +00:00
|
|
|
#include "Effect.h"
|
|
|
|
#include "effect_big_clock.h"
|
2019-06-11 17:48:09 +00:00
|
|
|
#include "fonts.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "ntp.h"
|
|
|
|
|
2019-09-04 03:59:30 +00:00
|
|
|
void BigClockEffect::loop() {
|
|
|
|
window->clear();
|
|
|
|
uint8_t h = ntpClient.getHours();
|
2019-09-25 16:12:34 +00:00
|
|
|
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);
|
2019-09-25 17:31:07 +00:00
|
|
|
|
2019-09-04 03:59:30 +00:00
|
|
|
uint8_t m = ntpClient.getMinutes();
|
2019-09-25 16:12:34 +00:00
|
|
|
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);
|
2019-09-25 17:31:07 +00:00
|
|
|
|
2019-09-04 03:59:30 +00:00
|
|
|
uint8_t s = ntpClient.getSeconds();
|
|
|
|
if (s & 1) {
|
|
|
|
window->setPixel(3, 10, &_color_font);
|
|
|
|
window->setPixel(3, 12, &_color_font);
|
|
|
|
}
|
2019-09-25 17:31:07 +00:00
|
|
|
|
2019-09-04 03:59:30 +00:00
|
|
|
_draw_seconds();
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 03:59:30 +00:00
|
|
|
void BigClockEffect::_draw_seconds() {
|
|
|
|
uint8_t seconds = ntpClient.getSeconds();
|
|
|
|
for (int i=1; i<=seconds; i++) {
|
2019-09-25 16:13:11 +00:00
|
|
|
_draw_border_pixel(i, 0, &_color_seconds);
|
2019-09-04 03:59:30 +00:00
|
|
|
}
|
|
|
|
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
|
|
|
if (millis > 0) {
|
2019-09-25 17:31:07 +00:00
|
|
|
//uint16_t position = ((60 - (60 - seconds) * millis) << 8) / 1000;
|
2019-09-25 16:13:11 +00:00
|
|
|
//uint8_t position = 60 - ((60 - seconds) * millis / 1000);
|
2019-09-25 17:31:07 +00:00
|
|
|
//percent = seconds00 - (59-seconds)ff
|
|
|
|
uint16_t position = ((seconds<<8) + (((60 - seconds)<<8) * millis / 1000));
|
2019-09-25 16:13:11 +00:00
|
|
|
_draw_border_pixel(position>>8, position&0xFF, &_color_seconds);
|
2019-09-04 03:59:30 +00:00
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:13:11 +00:00
|
|
|
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
|
|
|
|
accum88 x, y;
|
2019-09-04 03:59:30 +00:00
|
|
|
if (i<=8) {
|
2019-09-25 16:13:11 +00:00
|
|
|
x = (7 + i)<<8 | part;
|
2019-09-04 03:59:30 +00:00
|
|
|
y = 0;
|
|
|
|
} else if (i<=23) {
|
2019-09-25 16:13:11 +00:00
|
|
|
x = 15 << 8;
|
2019-09-25 17:31:07 +00:00
|
|
|
y = (i - 10) << 8 | (255 - part);
|
2019-09-04 03:59:30 +00:00
|
|
|
} else if (i<= 38) {
|
2019-09-25 17:31:07 +00:00
|
|
|
x = (15 - 1 - i + 23) << 8 | (255 - part);
|
2019-09-25 16:13:11 +00:00
|
|
|
y = 15 << 8;
|
2019-09-04 03:59:30 +00:00
|
|
|
} else if (i <= 53) {
|
|
|
|
x = 0;
|
2019-09-25 16:13:11 +00:00
|
|
|
y = (15 - i + 38) << 8 | part;
|
2019-09-04 03:59:30 +00:00
|
|
|
} else {
|
2019-09-25 16:13:11 +00:00
|
|
|
x = (i - 53) << 8 | part;
|
2019-09-04 03:59:30 +00:00
|
|
|
y = 0;
|
|
|
|
}
|
2019-09-25 16:13:11 +00:00
|
|
|
window->setSubPixel(x, y, color);
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|