Compare commits
3 Commits
db76255a2c
...
d9708d9159
Author | SHA1 | Date | |
---|---|---|---|
d9708d9159 | |||
5676b5d63c | |||
e9143b6ca8 |
@ -1,14 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
class Corner;
|
||||
|
||||
#include "my_fastled.h"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "edge.h"
|
||||
#include "node.h"
|
||||
|
||||
class Corner {
|
||||
public:
|
||||
Edge* e1;
|
||||
Edge* e2;
|
||||
Corner(Edge* e1, Edge* e2);
|
||||
Node* node;
|
||||
uint8_t number;
|
||||
Corner(Node* node, uint8_t number);
|
||||
std::list<uint16_t> _leds;
|
||||
std::vector<Corner*> _long_neighbours {};
|
||||
std::vector<Corner*> _short_neighbours {};
|
||||
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class Edge {
|
||||
public:
|
||||
Edge* neighbour = nullptr;
|
||||
};
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
class Node;
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "edge.h"
|
||||
#include "corner.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
@ -20,7 +22,6 @@ class Node {
|
||||
Coords coords;
|
||||
uint8_t direction;
|
||||
Node* neighbours[CORNERS_PER_PART];
|
||||
Edge* edges[CORNERS_PER_PART];
|
||||
Corner* _corners[CORNERS_PER_PART];
|
||||
Node(uint16_t number, Coords c, uint8_t direction);
|
||||
Node* create_neighbour(uint8_t edge);
|
||||
|
@ -2,15 +2,14 @@
|
||||
#include "my_fastled.h"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "config.h"
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
#include "corner.h"
|
||||
|
||||
class Node;
|
||||
|
||||
extern std::vector<Node*> nodes;
|
||||
extern std::list<Edge*> edges;
|
||||
extern std::vector<Corner*> corners;
|
||||
|
||||
extern CRGB leds[LED_COUNT];
|
||||
@ -28,6 +27,8 @@ enum AnimationMode {
|
||||
AM_STATIC
|
||||
};
|
||||
|
||||
extern std::map<AnimationMode, const char*> animation_mode_names;
|
||||
|
||||
extern AnimationMode mode;
|
||||
extern AnimationMode temp_mode;
|
||||
extern unsigned long temp_mode_until;
|
||||
|
@ -15,6 +15,7 @@ class State {
|
||||
void set(String key, String value);
|
||||
void commit();
|
||||
static void publish_current_state();
|
||||
static AnimationMode get_active_mode();
|
||||
|
||||
void parse_state(String state);
|
||||
void parse_mode(String mode);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "prototypes.h"
|
||||
#include "tools.h"
|
||||
|
||||
Corner::Corner(Edge* new_e1, Edge* new_e2): e1(new_e1), e2(new_e2) {
|
||||
Corner::Corner(Node* no, uint8_t nu): node(no), number(nu) {
|
||||
|
||||
}
|
||||
|
||||
|
67
src/main.cpp
67
src/main.cpp
@ -5,7 +5,6 @@
|
||||
#include "config.h"
|
||||
#include "tools.h"
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
#include "corner.h"
|
||||
#include "prototypes.h"
|
||||
#include "mqtt.h"
|
||||
@ -13,7 +12,6 @@
|
||||
#include "syslog.h"
|
||||
|
||||
std::vector<Node*> nodes;
|
||||
std::list<Edge*> edges;
|
||||
std::vector<Corner*> corners;
|
||||
|
||||
CRGB leds[LED_COUNT];
|
||||
@ -44,24 +42,12 @@ void setup_layout() {
|
||||
nodes.push_back(current_node);
|
||||
}
|
||||
|
||||
for(Node* node: nodes) {
|
||||
for(Edge* edge: node->edges) {
|
||||
auto e = std::find(edges.begin(), edges.end(), edge);
|
||||
if (e == edges.end()) {
|
||||
edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
LOGln("Node %p:", node);
|
||||
for(Node* n : node->neighbours) {
|
||||
LOGln(" %p", n);
|
||||
}
|
||||
}
|
||||
|
||||
bool verbose = false;
|
||||
for (Node* n1 : nodes) {
|
||||
LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y);
|
||||
if (verbose) LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y);
|
||||
for(int edge=0; edge<CORNERS_PER_PART; edge++) {
|
||||
Coords c = n1->coords_at_direction(edge);
|
||||
LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y);
|
||||
if (verbose) LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y);
|
||||
|
||||
Node* found = nullptr;
|
||||
for(Node* n2 : nodes) {
|
||||
@ -74,7 +60,7 @@ void setup_layout() {
|
||||
}
|
||||
}
|
||||
if (found != nullptr) {
|
||||
LOGln(" Found node #%d", found->_number);
|
||||
if (verbose) LOGln(" Found node #%d", found->_number);
|
||||
uint8_t inverse_dir = (n1->direction + 2*edge + 3) % 6;
|
||||
int8_t e = (inverse_dir - found->direction) % 6;
|
||||
if (e < 0) e+=6;
|
||||
@ -85,30 +71,39 @@ void setup_layout() {
|
||||
int8_t e2 = (e - 1) % CORNERS_PER_PART;
|
||||
if (e2<0) e2+=CORNERS_PER_PART;
|
||||
|
||||
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2);
|
||||
if (verbose) LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2);
|
||||
n1->_corners[edge]->_short_neighbours.push_back(found->_corners[e2]);
|
||||
|
||||
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e);
|
||||
if (verbose) LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e);
|
||||
n1->_corners[e1]->_short_neighbours.push_back(found->_corners[e]);
|
||||
} else {
|
||||
LOGln(" No match.");
|
||||
if (verbose) LOGln(" No match.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Corner* corner: corners) {
|
||||
LOGln("Corner %p:", corner);
|
||||
for(auto c: corner->_long_neighbours) {
|
||||
LOGln(" Long: %p", c);
|
||||
for (Node* node : nodes) {
|
||||
LOGln("Node #%d:", node->_number);
|
||||
for(Corner* corner : node->_corners) {
|
||||
LOGln(" Corner #%d,%d:", node->_number, corner->number);
|
||||
for (auto c: corner->_long_neighbours) {
|
||||
LOGln(" Long neighbour: #%d,%d", c->node->_number, c->number);
|
||||
}
|
||||
for (auto c: corner->_short_neighbours) {
|
||||
LOGln(" Short neighbour: #%d,%d", c->node->_number, c->number);
|
||||
}
|
||||
}
|
||||
for (int i=0; i<CORNERS_PER_PART; i++) {
|
||||
if (node->neighbours[i]==nullptr) {
|
||||
LOGln(" Neighbour %d: NULL", i);
|
||||
} else {
|
||||
LOGln(" Neighbour %d: #%d", i, node->neighbours[i]->_number);
|
||||
}
|
||||
for(auto c: corner->_short_neighbours) {
|
||||
LOGln(" Short: %p", c);
|
||||
}
|
||||
}
|
||||
|
||||
LOGln("Counts:");
|
||||
LOGln("Nodes: %3d", nodes.size());
|
||||
LOGln("Edges: %3d", edges.size());
|
||||
LOGln("Corners: %3d", corners.size());
|
||||
}
|
||||
|
||||
@ -213,6 +208,8 @@ void setup() {
|
||||
for(Corner* corner : corners) {
|
||||
corner->set_color(CRGB::Black);
|
||||
}
|
||||
|
||||
State::publish_current_state();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -236,19 +233,7 @@ void loop() {
|
||||
if (speedup > 0 && (millis() - last_loop > (20 / speedup) || last_loop > millis())) {
|
||||
looping = false;
|
||||
|
||||
AnimationMode active_mode = mode;
|
||||
if (temp_mode_until > 0) {
|
||||
if (temp_mode_until>millis()) {
|
||||
active_mode = temp_mode;
|
||||
} else {
|
||||
temp_mode_until = 0;
|
||||
if (return_to_brightness != -1) {
|
||||
FastLED.setBrightness(return_to_brightness);
|
||||
return_to_brightness = -1;
|
||||
}
|
||||
State::publish_current_state();
|
||||
}
|
||||
}
|
||||
AnimationMode active_mode = State::get_active_mode();
|
||||
|
||||
if (active_mode == AM_CORNERS || active_mode == AM_FIRST_CORNER) {
|
||||
for(Corner* corner: corners) {
|
||||
|
@ -9,12 +9,12 @@ Node::Node(uint16_t number, Coords c, uint8_t _dir) {
|
||||
|
||||
LOGln("Created Node #%d at coordinates %d,%d with direction %d.", _number, coords.x, coords.y, direction);
|
||||
for(int i=0; i<CORNERS_PER_PART; i++) {
|
||||
edges[i] = new Edge();
|
||||
neighbours[i] = nullptr;
|
||||
}
|
||||
|
||||
Corner* last_corner = nullptr;
|
||||
for(int i=0; i<CORNERS_PER_PART; i++) {
|
||||
Corner* c = new Corner(edges[i], edges[(i+1) % CORNERS_PER_PART]);
|
||||
Corner* c = new Corner(this, i);
|
||||
for(int j=0; j<LEDS_PER_CORNER; j++) {
|
||||
c->add_led(number * CORNERS_PER_PART * LEDS_PER_CORNER + i * LEDS_PER_CORNER + j);
|
||||
}
|
||||
@ -42,9 +42,6 @@ Node* Node::create_neighbour(uint8_t edge) {
|
||||
node->neighbours[0] = this;
|
||||
neighbours[edge] = node;
|
||||
|
||||
node->edges[0]->neighbour = this->edges[edge];
|
||||
this->edges[edge]->neighbour = node->edges[0];
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
13
src/prototypes.cpp
Normal file
13
src/prototypes.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "prototypes.h"
|
||||
|
||||
std::map<AnimationMode, const char*> animation_mode_names {
|
||||
{AM_CORNERS, "corners"},
|
||||
{AM_FLASH, "flash"},
|
||||
{AM_FIRST_CORNER, "first_corner"},
|
||||
{AM_NODES, "nodes"},
|
||||
{AM_FIRST_NODE, "first_node"},
|
||||
{AM_OFF, "off"},
|
||||
{AM_ERROR, "error"},
|
||||
{AM_NONE, "NONE"},
|
||||
{AM_STATIC, "static"}
|
||||
};
|
@ -106,12 +106,30 @@ void State::publish_current_state() {
|
||||
StaticJsonDocument<512> json;
|
||||
json["state"] = (mode==AM_OFF) ? "OFF" : "ON";
|
||||
json["brightness"] = FastLED.getBrightness();
|
||||
json["effect"] = mode;
|
||||
json["effect"] = animation_mode_names[get_active_mode()];
|
||||
JsonObject rgb = json.createNestedObject("rgb");
|
||||
rgb["r"] = color.r;
|
||||
rgb["g"] = color.g;
|
||||
rgb["b"] = color.b;
|
||||
String result = "";
|
||||
serializeJson(json, result);
|
||||
LOGln("Reporting current state: %s", result.c_str());
|
||||
mqtt_publish_current_state(result);
|
||||
}
|
||||
|
||||
AnimationMode State::get_active_mode() {
|
||||
AnimationMode active_mode = mode;
|
||||
if (temp_mode_until > 0) {
|
||||
if (temp_mode_until>millis()) {
|
||||
active_mode = temp_mode;
|
||||
} else {
|
||||
temp_mode_until = 0;
|
||||
if (return_to_brightness != -1) {
|
||||
FastLED.setBrightness(return_to_brightness);
|
||||
return_to_brightness = -1;
|
||||
}
|
||||
State::publish_current_state();
|
||||
}
|
||||
}
|
||||
return active_mode;
|
||||
}
|
Loading…
Reference in New Issue
Block a user