Added a TimeEffect to show a countdown to a time given via MQTT.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
37
src/effect_timer.cpp
Normal file
37
src/effect_timer.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "effect_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);
|
||||
unsigned long now = ntpClient.getEpochTime() - NTP_OFFSET;
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user