91 lines
2.0 KiB
C++
91 lines
2.0 KiB
C++
#include <Arduino.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266mDNS.h>
|
|
#include <ArduinoOTA.h>
|
|
#include <SimpleList.h>
|
|
|
|
#include "ntp.h"
|
|
#include "config.h"
|
|
#include "animations.h"
|
|
#include "wifi.h"
|
|
#include "ota.h"
|
|
#include "my_fastled.h"
|
|
#include "EffectEntry.h"
|
|
#include "my_mqtt.h"
|
|
#include "functions.h"
|
|
#include "text.h"
|
|
#include "effects.h"
|
|
|
|
uint8_t starting_up = OTA_STARTUP_DELAY;
|
|
int loop_timeouts = 0;
|
|
long loop_started_at = 0;
|
|
uint8_t baseHue = 0; // defined as extern in prototypes.h
|
|
|
|
void setup() {
|
|
Serial.begin(74880);
|
|
LOGln("Core * Starting");
|
|
setup_effects();
|
|
wifi_setup();
|
|
ota_setup();
|
|
fastled_setup();
|
|
ntpClient.begin();
|
|
mqtt_setup();
|
|
LOGln("Core * Setup complete");
|
|
|
|
current_effect->start();
|
|
}
|
|
|
|
void loop() {
|
|
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++) {
|
|
leds[XYsafe(i, 0)] = CRGB(0xff0000);
|
|
}
|
|
FastLED.show();
|
|
}
|
|
return;
|
|
}
|
|
|
|
ntpClient.update();
|
|
mqtt_loop();
|
|
|
|
EVERY_N_MILLISECONDS(100) {
|
|
baseHue++;
|
|
}
|
|
|
|
EVERY_N_MILLISECONDS(1000 / FPS) {
|
|
//LOGln("Core * loop running");
|
|
current_effect->loop();
|
|
//LOGln("Core * loop ran");
|
|
|
|
if (current_effect->can_be_shown_with_clock()) {
|
|
effect_clock.loop(current_effect->clock_as_mask(), CRGB(0xFFFFFF), CRGB(0x000000));
|
|
}
|
|
FastLED.show();
|
|
}
|
|
|
|
EVERY_N_SECONDS(5) {
|
|
if (REPORT_FREE_HEAP) {
|
|
mqtt_publish("free_heap", ESP.getFreeHeap());
|
|
}
|
|
}
|
|
|
|
|
|
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--;
|
|
}
|
|
}
|