Fixed publish_current_state()
This commit is contained in:
parent
e9143b6ca8
commit
5676b5d63c
@ -2,6 +2,7 @@
|
|||||||
#include "my_fastled.h"
|
#include "my_fastled.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "corner.h"
|
#include "corner.h"
|
||||||
@ -26,6 +27,8 @@ enum AnimationMode {
|
|||||||
AM_STATIC
|
AM_STATIC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern std::map<AnimationMode, const char*> animation_mode_names;
|
||||||
|
|
||||||
extern AnimationMode mode;
|
extern AnimationMode mode;
|
||||||
extern AnimationMode temp_mode;
|
extern AnimationMode temp_mode;
|
||||||
extern unsigned long temp_mode_until;
|
extern unsigned long temp_mode_until;
|
||||||
|
@ -15,6 +15,7 @@ class State {
|
|||||||
void set(String key, String value);
|
void set(String key, String value);
|
||||||
void commit();
|
void commit();
|
||||||
static void publish_current_state();
|
static void publish_current_state();
|
||||||
|
static AnimationMode get_active_mode();
|
||||||
|
|
||||||
void parse_state(String state);
|
void parse_state(String state);
|
||||||
void parse_mode(String mode);
|
void parse_mode(String mode);
|
||||||
|
16
src/main.cpp
16
src/main.cpp
@ -211,6 +211,8 @@ void setup() {
|
|||||||
for(Corner* corner : corners) {
|
for(Corner* corner : corners) {
|
||||||
corner->set_color(CRGB::Black);
|
corner->set_color(CRGB::Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
State::publish_current_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -234,19 +236,7 @@ void loop() {
|
|||||||
if (speedup > 0 && (millis() - last_loop > (20 / speedup) || last_loop > millis())) {
|
if (speedup > 0 && (millis() - last_loop > (20 / speedup) || last_loop > millis())) {
|
||||||
looping = false;
|
looping = false;
|
||||||
|
|
||||||
AnimationMode active_mode = mode;
|
AnimationMode active_mode = State::get_active_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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active_mode == AM_CORNERS || active_mode == AM_FIRST_CORNER) {
|
if (active_mode == AM_CORNERS || active_mode == AM_FIRST_CORNER) {
|
||||||
for(Corner* corner: corners) {
|
for(Corner* corner: corners) {
|
||||||
|
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;
|
StaticJsonDocument<512> json;
|
||||||
json["state"] = (mode==AM_OFF) ? "OFF" : "ON";
|
json["state"] = (mode==AM_OFF) ? "OFF" : "ON";
|
||||||
json["brightness"] = FastLED.getBrightness();
|
json["brightness"] = FastLED.getBrightness();
|
||||||
json["effect"] = mode;
|
json["effect"] = animation_mode_names[get_active_mode()];
|
||||||
JsonObject rgb = json.createNestedObject("rgb");
|
JsonObject rgb = json.createNestedObject("rgb");
|
||||||
rgb["r"] = color.r;
|
rgb["r"] = color.r;
|
||||||
rgb["g"] = color.g;
|
rgb["g"] = color.g;
|
||||||
rgb["b"] = color.b;
|
rgb["b"] = color.b;
|
||||||
String result = "";
|
String result = "";
|
||||||
serializeJson(json, result);
|
serializeJson(json, result);
|
||||||
|
LOGln("Reporting current state: %s", result.c_str());
|
||||||
mqtt_publish_current_state(result);
|
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