39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#include "effects/timer.h"
|
|
#include <FastLED.h>
|
|
#include "functions.h"
|
|
#include "fonts.h"
|
|
#include "ntp.h"
|
|
|
|
void TimerEffect::loop(uint16_t ms) {
|
|
if (timer==0) return;
|
|
|
|
CRGB bg_color(0x000000);
|
|
CRGB fg_color(0xCCCCCC);
|
|
time_t now;
|
|
time(&now);
|
|
long diff = timer - now;
|
|
window->clear(&bg_color);
|
|
if (diff < 0 && (now & 1)==0) return;
|
|
if (diff < 0) diff = 0;
|
|
int hours = diff / 3600;
|
|
int minutes = diff / 60;
|
|
int seconds = diff % 60;
|
|
if (minutes > 99) {
|
|
seconds = minutes % 60;
|
|
minutes = hours;
|
|
}
|
|
//void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false);
|
|
window->drawChar(&font_numbers3x5, 0<<8, 0<<8, '0' + (minutes / 10), &fg_color);
|
|
window->drawChar(&font_numbers3x5, 4<<8, 0<<8, '0' + (minutes % 10), &fg_color);
|
|
window->drawChar(&font_numbers3x5, 9<<8, 0<<8, '0' + (seconds / 10), &fg_color);
|
|
window->drawChar(&font_numbers3x5, 13<<8, 0<<8, '0' + (seconds % 10), &fg_color);
|
|
if (now & 1) {
|
|
window->setPixel(7, 1, &fg_color);
|
|
window->setPixel(7, 3, &fg_color);
|
|
}
|
|
}
|
|
|
|
TimerEffect::~TimerEffect() {
|
|
delete window;
|
|
}
|