2019-05-21 03:52:57 +00:00
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266mDNS.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include <ArduinoOTA.h>
|
2019-05-25 19:12:34 +00:00
|
|
|
|
|
|
|
#define FASTLED_INTERNAL
|
2019-05-21 03:52:57 +00:00
|
|
|
#include "FastLED.h"
|
|
|
|
#include <PubSubClient.h>
|
2019-05-25 19:11:49 +00:00
|
|
|
#include "SimpleList.h"
|
2019-05-25 21:48:55 +00:00
|
|
|
#include "ntp.h"
|
2019-05-21 03:52:57 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
CRGB leds[LED_COUNT];
|
|
|
|
WiFiClient wifi;
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_OFFSET, NTP_INTERVAL);
|
|
|
|
|
2019-05-23 19:18:15 +00:00
|
|
|
#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;
|
|
|
|
|
2019-05-25 19:11:49 +00:00
|
|
|
class Effect {
|
|
|
|
protected:
|
|
|
|
Window window = {0, 0, LED_WIDTH, LED_HEIGHT}; // Use a full screen window per default.
|
|
|
|
public:
|
|
|
|
virtual void loop() = 0;
|
|
|
|
boolean supports_window = false;
|
|
|
|
virtual boolean can_be_shown_with_clock() { return false; };
|
|
|
|
virtual boolean clock_as_mask() { return false; };
|
|
|
|
void setWindow(Window win) {
|
|
|
|
window = win;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-21 03:52:57 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "sprites.h"
|
2019-05-22 04:52:41 +00:00
|
|
|
#include "animations.h"
|
|
|
|
#include "tools.h"
|
2019-05-25 19:11:49 +00:00
|
|
|
|
|
|
|
SimpleList<Effect*>* cycle_effects;
|
|
|
|
|
2019-05-22 04:52:41 +00:00
|
|
|
#include "effects.h"
|
2019-05-21 03:52:57 +00:00
|
|
|
|
2019-05-25 19:11:49 +00:00
|
|
|
#define NUM_EFFECTS 11
|
2019-05-23 19:18:15 +00:00
|
|
|
//EffectEntry effects[NUM_EFFECTS];
|
|
|
|
Sinematrix3 sinematrix3;
|
|
|
|
BigClock big_clock;
|
|
|
|
Clock clock;
|
|
|
|
Bell bell;
|
|
|
|
Static off(CRGB(0x000000));
|
2019-05-25 18:30:27 +00:00
|
|
|
Animation anim_koopa(&animation_koopa, CRGB(0x000000), 0, 0);
|
|
|
|
Animation anim_couple_rain(&animation_couple_rain, CRGB(0x000000), -8, -16);
|
2019-05-24 03:13:35 +00:00
|
|
|
SingleDynamic single_dynamic;
|
|
|
|
MultiDynamic multi_dynamic;
|
2019-05-24 04:25:22 +00:00
|
|
|
MatrixEffect matrix;
|
2019-05-25 19:11:49 +00:00
|
|
|
CycleEffect effect_cycle;
|
2019-05-23 19:18:15 +00:00
|
|
|
|
|
|
|
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},
|
2019-05-24 03:13:35 +00:00
|
|
|
{"couple_rain", (Effect *)&anim_couple_rain},
|
|
|
|
{"single_dynamic", (Effect *)&single_dynamic},
|
2019-05-24 04:25:22 +00:00
|
|
|
{"multi_dynamic", (Effect *)&multi_dynamic},
|
|
|
|
{"matrix", (Effect *)&matrix},
|
2019-05-25 19:11:49 +00:00
|
|
|
{"cycle", (Effect *)&effect_cycle},
|
2019-05-23 19:18:15 +00:00
|
|
|
};
|
|
|
|
|
2019-05-25 19:11:49 +00:00
|
|
|
void setup_cycle_effects() {
|
|
|
|
LOGln("Core * Setting up cycle_effects");
|
|
|
|
cycle_effects = new SimpleList<Effect*>();
|
|
|
|
cycle_effects->add(&sinematrix3);
|
|
|
|
cycle_effects->add(&single_dynamic);
|
|
|
|
cycle_effects->add(&multi_dynamic);
|
|
|
|
cycle_effects->add(&matrix);
|
|
|
|
}
|
|
|
|
|
2019-05-23 19:18:15 +00:00
|
|
|
|
2019-05-21 03:52:57 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(74880);
|
|
|
|
Serial.println("Core * Starting");
|
2019-05-25 19:11:49 +00:00
|
|
|
setup_cycle_effects();
|
2019-05-21 03:52:57 +00:00
|
|
|
wifi_setup();
|
|
|
|
ota_setup();
|
|
|
|
fastled_setup();
|
2019-05-25 21:48:55 +00:00
|
|
|
ntpClient.begin();
|
2019-05-21 03:52:57 +00:00
|
|
|
mqtt_setup();
|
|
|
|
Serial.println("Core * Setup complete");
|
2019-05-23 19:18:15 +00:00
|
|
|
}
|
2019-05-21 03:52:57 +00:00
|
|
|
|
2019-05-23 19:18:15 +00:00
|
|
|
Effect* current_effect = &clock;
|
2019-05-21 03:52:57 +00:00
|
|
|
|
|
|
|
#include "mqtt.h"
|
|
|
|
|
|
|
|
uint8_t starting_up = OTA_STARTUP_DELAY;
|
2019-05-23 19:18:15 +00:00
|
|
|
int loop_timeouts = 0;
|
|
|
|
long loop_started_at = 0;
|
2019-05-21 03:52:57 +00:00
|
|
|
|
|
|
|
void loop() {
|
2019-05-23 19:18:15 +00:00
|
|
|
loop_started_at = millis();
|
2019-05-21 03:52:57 +00:00
|
|
|
ota_loop();
|
|
|
|
|
|
|
|
if (starting_up > 0) {
|
|
|
|
EVERY_N_SECONDS(1) {
|
2019-05-23 19:18:15 +00:00
|
|
|
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
|
2019-05-21 03:52:57 +00:00
|
|
|
starting_up--;
|
|
|
|
clear();
|
|
|
|
for (int i=0; i<starting_up; i++) {
|
|
|
|
leds[XYsafe(i, 0)] = CRGB(0xff0000);
|
|
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-25 21:48:55 +00:00
|
|
|
ntpClient.update();
|
2019-05-21 03:52:57 +00:00
|
|
|
mqtt_loop();
|
|
|
|
|
|
|
|
EVERY_N_MILLISECONDS(1000 / FPS) {
|
2019-05-23 19:18:15 +00:00
|
|
|
Serial.println("Core * loop running");
|
2019-05-21 03:52:57 +00:00
|
|
|
current_effect->loop();
|
2019-05-23 20:14:15 +00:00
|
|
|
|
|
|
|
if (current_effect->can_be_shown_with_clock()) {
|
|
|
|
clock.loop(current_effect->clock_as_mask(), CRGB(0xFFFFFF), CRGB(0x000000));
|
|
|
|
}
|
|
|
|
|
2019-05-21 03:52:57 +00:00
|
|
|
FastLED.show();
|
|
|
|
}
|
2019-05-23 19:18:15 +00:00
|
|
|
|
|
|
|
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--;
|
|
|
|
}
|
2019-05-21 03:52:57 +00:00
|
|
|
}
|