Merge branch 'master' of https://git.schle.nz/fabian/pitrix
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;
|
||||
}
|
@ -28,6 +28,7 @@
|
||||
Effect* current_effect;
|
||||
|
||||
ClockEffect effect_clock;
|
||||
TimerEffect effect_timer;
|
||||
|
||||
// We're using 0 instead of false to get a better visual difference between true and false.
|
||||
const EffectEntry effects[] = {
|
||||
|
@ -50,6 +50,10 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) {
|
||||
LOGln("Set weather_temperatures[%d] to value %d", id, val);
|
||||
}
|
||||
return;
|
||||
} else if (topic.equals(MQTT_TOPIC_TIMER)) {
|
||||
timer = payload.toInt();
|
||||
LOGln("Set timer to %lu.", timer);
|
||||
return;
|
||||
}
|
||||
|
||||
topic.remove(0, strlen(MQTT_TOPIC)); // Strip MQTT_TOPIC from the beginning
|
||||
@ -102,6 +106,7 @@ boolean mqtt_connect() {
|
||||
mqtt_client.publish(MQTT_TOPIC "status", buffer, true);
|
||||
mqtt_client.subscribe(MQTT_TOPIC "+");
|
||||
mqtt_client.subscribe(MQTT_TOPIC_WEATHER "#");
|
||||
mqtt_client.subscribe(MQTT_TOPIC_TIMER);
|
||||
}
|
||||
return mqtt_client.connected();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ uint8_t baseHue = 0; // defined as extern in prototypes.h
|
||||
char hostname[30]; // defined as extern in prototypes.h
|
||||
uint16_t frame = 0; // defined as extern in prototypes.h
|
||||
unsigned long _last_effect_loop_finished_at = 0;
|
||||
unsigned long timer = 0;
|
||||
#ifdef RECORDER_ENABLE
|
||||
Recorder* recorder;
|
||||
#endif
|
||||
@ -113,6 +114,9 @@ void loop() {
|
||||
if (current_effect->can_be_shown_with_clock()) {
|
||||
effect_clock.loop_with_invert(current_effect->clock_as_mask());
|
||||
}
|
||||
|
||||
effect_timer.loop(last_loop_ago);
|
||||
|
||||
FastLED.show();
|
||||
|
||||
http_server_send_framedata();
|
||||
|
Reference in New Issue
Block a user