pitrix/src/effect_pixelclock.cpp

41 lines
984 B
C++
Raw Normal View History

2019-06-15 12:18:35 +00:00
#include "effect_pixelclock.h"
#include "ntp.h"
PixelClockEffect::PixelClockEffect() {
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
2019-06-15 12:18:35 +00:00
_color_seconds = new CRGB(0x00FF00);
_color_minutes = new CRGB(0xFFFF00);
}
PixelClockEffect::~PixelClockEffect() {
2019-06-15 12:18:35 +00:00
delete _color_seconds;
delete _color_minutes;
2019-06-19 20:23:49 +00:00
delete window;
2019-06-15 12:18:35 +00:00
}
void PixelClockEffect::loop(uint16_t ms) {
2019-06-15 12:18:35 +00:00
uint8_t x, y; // Temporary variables for calculating positions
window->clear();
time_t now;
tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
2019-06-15 12:18:35 +00:00
// Seconds
uint8_t seconds = timeinfo.tm_sec;
2019-06-15 12:18:35 +00:00
for (uint8_t s=0; s<60; s++) {
x = window->width - 1 - s/10;
y = window->height - 1 - (s % 10);
if (s<seconds) window->setPixel(x, y, _color_seconds);
2019-06-15 12:18:35 +00:00
}
uint8_t minutes = timeinfo.tm_min;
2019-06-15 12:18:35 +00:00
for (uint8_t m=0; m<60; m++) {
x = 6 - m/10;
y = window->height - 1 - (m % 10);
if (m<minutes) window->setPixel(x, y, _color_minutes);
2019-06-15 12:18:35 +00:00
}
}
bool PixelClockEffect::can_be_shown_with_clock() { return true; }