2019-05-29 22:49:54 +00:00
|
|
|
#include "effect_clock.h"
|
|
|
|
#include <FastLED.h>
|
|
|
|
#include "functions.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-25 16:11:52 +00:00
|
|
|
NightClockEffect::NightClockEffect() {
|
|
|
|
window = Window::getFullWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NightClockEffect::loop() {
|
|
|
|
uint16_t minutes = minutes16();
|
|
|
|
//uint8_t y = minutes % ((window->height - 5) * 2 - 2);
|
|
|
|
//if (y > window->height - 5) y = 2*window->height - 2*y;
|
|
|
|
uint8_t y = minutes % 10;
|
|
|
|
ClockEffect::loop(false, CRGB(0x880000), CRGB(0x000000), y);
|
|
|
|
}
|
|
|
|
|
2019-05-29 22:49:54 +00:00
|
|
|
void ClockEffect::loop() {
|
2019-09-25 16:11:52 +00:00
|
|
|
loop_with_invert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClockEffect::loop_with_invert(bool invert) {
|
|
|
|
// Clear the first line to have a bit of space to the other stuff on screen
|
|
|
|
CRGB bg_color(0x000000);
|
|
|
|
for(int i=0; i<window->width; i++) window->setPixel(i, 0, &bg_color);
|
|
|
|
loop(invert, CRGB(0xFFFFFF), bg_color, 1);
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:11:52 +00:00
|
|
|
void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPos) {
|
2019-06-07 04:24:16 +00:00
|
|
|
if (!invert) {
|
2019-06-11 17:48:09 +00:00
|
|
|
window->clear(&bg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
} else {
|
|
|
|
// Manually clear the needed parts
|
|
|
|
for(int y=0; y<6; y++) {
|
2019-09-25 16:11:52 +00:00
|
|
|
window->setPixel(3, yPos+y, &bg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
if (y!=2 && y!=4) {
|
2019-09-25 16:11:52 +00:00
|
|
|
window->setPixel(7, yPos+y, &bg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
}
|
2019-09-25 16:11:52 +00:00
|
|
|
window->setPixel(8, yPos+y, &bg_color);
|
|
|
|
window->setPixel(12, yPos+y, &bg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
}
|
|
|
|
fg_color = bg_color;
|
|
|
|
}
|
|
|
|
if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
2019-06-11 17:48:09 +00:00
|
|
|
window->clear(&bg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int h = ntpClient.getHours();
|
2019-06-11 17:48:09 +00:00
|
|
|
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
2019-09-25 16:11:52 +00:00
|
|
|
window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert);
|
|
|
|
window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert);
|
2019-06-07 04:24:16 +00:00
|
|
|
int m = ntpClient.getMinutes();
|
2019-09-25 16:11:52 +00:00
|
|
|
window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert);
|
|
|
|
window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert);
|
2019-06-07 04:24:16 +00:00
|
|
|
if (ntpClient.getSeconds() & 1) {
|
2019-09-25 16:11:52 +00:00
|
|
|
window->setPixel(7, yPos+1, &fg_color);
|
|
|
|
window->setPixel(7, yPos+3, &fg_color);
|
2019-06-07 04:24:16 +00:00
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|
2019-06-19 20:23:49 +00:00
|
|
|
|
|
|
|
ClockEffect::~ClockEffect() {
|
|
|
|
delete window;
|
|
|
|
}
|