56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#include "effects/clock.h"
|
|
#include <FastLED.h>
|
|
#include "functions.h"
|
|
#include "fonts.h"
|
|
#include "ntp.h"
|
|
|
|
void ClockEffect::loop(uint16_t ms) {
|
|
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);
|
|
}
|
|
|
|
void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPos) {
|
|
if (!invert) {
|
|
window->clear(&bg_color);
|
|
} else {
|
|
// Manually clear the needed parts
|
|
for(int y=0; y<6; y++) {
|
|
window->setPixel(3, yPos+y, &bg_color);
|
|
if (y!=1 && y!=3) {
|
|
window->setPixel(7, yPos+y, &bg_color);
|
|
}
|
|
window->setPixel(8, yPos+y, &bg_color);
|
|
window->setPixel(12, yPos+y, &bg_color);
|
|
}
|
|
fg_color = bg_color;
|
|
}
|
|
/*if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) {
|
|
window->clear(&bg_color);
|
|
return;
|
|
}*/
|
|
time_t now;
|
|
tm timeinfo;
|
|
time(&now);
|
|
localtime_r(&now, &timeinfo);
|
|
int h = timeinfo.tm_hour;
|
|
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
|
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);
|
|
int m = timeinfo.tm_min;
|
|
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);
|
|
if (timeinfo.tm_sec & 1) {
|
|
window->setPixel(7, yPos+1, &fg_color);
|
|
window->setPixel(7, yPos+3, &fg_color);
|
|
}
|
|
}
|
|
|
|
ClockEffect::~ClockEffect() {
|
|
}
|