Lots of changes:

* More animations with generalized code to display them.
  * The hostname will now include a unique id of the ESP.
  * Effect can now be restricted to a smaller "window".
  * Clock is now BigClock, SmallClock is now Clock.
  * Clock shows the time as well as the sinematrix effect. Closes #8.
  * If the loop takes too long too often, the ESP will automatically be rebooted. Closes #12.
  * The text drawing methods are now much more generalized. #5.
This commit is contained in:
2019-05-23 21:18:15 +02:00
parent deb3a753c8
commit 0e82f94846
8 changed files with 350 additions and 91 deletions

View File

@ -12,6 +12,21 @@ WiFiClient wifi;
WiFiUDP ntpUDP;
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL);
#ifdef DEBUG
#define LOG(x) Serial.print(x);
#define LOGln(x) Serial.println(x);
#else
#define LOG(x) ""
#define LOGln(x) ""
#endif
typedef struct {
uint8_t x;
uint8_t y;
uint8_t w;
uint8_t h;
} Window;
#include "functions.h"
#include "text.h"
#include "sprites.h"
@ -19,6 +34,27 @@ NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL);
#include "tools.h"
#include "effects.h"
#define NUM_EFFECTS 7
//EffectEntry effects[NUM_EFFECTS];
Sinematrix3 sinematrix3;
BigClock big_clock;
Clock clock;
Bell bell;
Static off(CRGB(0x000000));
Animation anim_koopa(&koopa, CRGB(0x000000), 0, 0);
Animation anim_couple_rain(&couple_rain, CRGB(0x000000), -8, -16);
EffectEntry effects[NUM_EFFECTS] = {
{"sinematrix3", (Effect *)&sinematrix3},
{"big_clock", (Effect *)&big_clock},
{"clock", (Effect *)&clock},
{"bell", (Effect *)&bell},
{"off", (Effect *)&off},
{"koopa", (Effect *)&anim_koopa},
{"couple_rain", (Effect *)&anim_couple_rain}
};
void setup() {
// put your setup code here, to run once:
Serial.begin(74880);
@ -29,36 +65,25 @@ void setup() {
ntp_setup();
mqtt_setup();
Serial.println("Core * Setup complete");
clock.setEffects(&effects[0]);
}
Sinematrix3 effect_sinematrix3;
Clock effect_clock;
SmallClock effect_small_clock;
Bell effect_bell;
Static effect_off(CRGB(0x000000));
Animation effect_koopa(&koopa);
Effect* current_effect = &effect_small_clock;
#define NUM_EFFECTS 6
EffectEntry effects[NUM_EFFECTS] = {
{"bell", &effect_bell},
{"sinematrix3", &effect_sinematrix3},
{"clock", &effect_clock},
{"small_clock", &effect_small_clock},
{"koopa", &effect_koopa},
{"off", &effect_off}
};
Effect* current_effect = &clock;
#include "mqtt.h"
uint8_t starting_up = OTA_STARTUP_DELAY;
int loop_timeouts = 0;
long loop_started_at = 0;
void loop() {
// put your main code here, to run repeatedly:
loop_started_at = millis();
ota_loop();
if (starting_up > 0) {
EVERY_N_SECONDS(1) {
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
starting_up--;
clear();
for (int i=0; i<starting_up; i++) {
@ -73,7 +98,21 @@ void loop() {
mqtt_loop();
EVERY_N_MILLISECONDS(1000 / FPS) {
Serial.println("Core * loop running");
//Serial.printf("Core * current_effect: %p\n", (void *)&current_effect);
current_effect->loop();
FastLED.show();
}
if (MONITOR_LOOP_TIMES && millis()-loop_started_at>=MONITOR_LOOP_TIME_THRESHOLD) {
LOG("Core * Loop took "); LOG(millis()-loop_started_at); LOGln("ms.");
loop_timeouts++;
LOG("Core * Timeout counter is now "); LOGln(loop_timeouts);
if (loop_timeouts >= MONITOR_LOOP_TIME_COUNT_MAX) {
ESP.restart();
}
} else if (loop_timeouts > 0) {
loop_timeouts--;
}
}