Added MQTT and WiFi support.

This commit is contained in:
2021-01-08 05:54:55 +01:00
parent fa888bcfab
commit bfc5f1dffe
9 changed files with 167 additions and 11 deletions

View File

@ -7,6 +7,7 @@
#include "edge.h"
#include "corner.h"
#include "prototypes.h"
#include "mqtt.h"
std::vector<Node*> nodes;
std::list<Edge*> edges;
@ -15,6 +16,8 @@ std::vector<Corner*> corners;
CRGB leds[LED_COUNT];
AnimationMode mode = AM_CORNERS;
AnimationMode temp_mode;
unsigned long temp_mode_until;
unsigned long last_loop = 0;
@ -76,7 +79,7 @@ void setup_fastled() {
set_all_leds(CRGB::Black);
}
void setup_wifi() {
void setup_rng() {
LOGln("Starting WiFi scan for RNG initialization...");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
@ -97,11 +100,15 @@ void setup() {
setup_layout();
setup_fastled();
setup_wifi();
#ifdef TEST_MODE
LOGln("TEST_MODE is active!");
#else
setup_rng();
wifi_setup();
mqtt_setup();
#endif
}
void loop() {
@ -119,13 +126,23 @@ void loop() {
}
#else
// Normal mode
mqtt_loop();
EVERY_N_MILLISECONDS(20 / SPEEDUP) {
looping = false;
if (mode == AM_CORNERS || mode == AM_FIRST_CORNER) {
AnimationMode active_mode = mode;
if (temp_mode_until > 0) {
if (temp_mode_until>millis()) {
active_mode = temp_mode;
} else {
temp_mode_until = 0;
}
}
if (active_mode == AM_CORNERS || active_mode == AM_FIRST_CORNER) {
for(Corner* corner: corners) {
corner->step();
if (mode == AM_FIRST_CORNER) {
if (active_mode == AM_FIRST_CORNER) {
corner->infect(512, 512);
} else {
corner->infect(300, 600);
@ -135,13 +152,13 @@ void loop() {
}
if (random8(128)==0) {
if (mode == AM_FIRST_CORNER) {
if (active_mode == AM_FIRST_CORNER) {
corners[0]->blend_to(CHSV(random8(), 255, 255));
} else {
corners[random16(corners.size())]->blend_to(CHSV(random8(), 255, 255));
}
}
} else if (mode == AM_NODES || mode == AM_FIRST_NODE) {
} else if (active_mode == AM_NODES || active_mode == AM_FIRST_NODE) {
for(Node* node : nodes) {
node->step();
node->infect(512);
@ -149,13 +166,13 @@ void loop() {
}
if (random8(128)==0) {
if (mode == AM_FIRST_NODE) {
if (active_mode == AM_FIRST_NODE) {
nodes[0]->blend_to(CHSV(random8(), 255, 255));
} else {
nodes[random8(nodes.size())]->blend_to(CHSV(random8(), 255, 255));
}
}
} else if (mode == AM_FLASH) {
} else if (active_mode == AM_FLASH) {
for (Node* node : nodes) {
node->step();
node->infect(512);