legacy animations optional
* Added Legacy animations as an option * Removed ALL mode, replaced with ws2812fx_mode = FX_MODE_STATIC; mode = SET_MODE; * When mode == SET_MODE, set speed, color, etc automatically, needs a new MODE prevMode
This commit is contained in:
parent
ed5e4783be
commit
420909fb20
3 changed files with 350 additions and 310 deletions
|
@ -26,14 +26,14 @@
|
|||
|
||||
//SPIFFS Save
|
||||
#if !defined(ENABLE_HOMEASSISTANT) and defined(ENABLE_STATE_SAVE_SPIFFS)
|
||||
#include <ArduinoJson.h> //
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
#endif
|
||||
|
||||
// MQTT
|
||||
#ifdef ENABLE_MQTT
|
||||
#include <PubSubClient.h>
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
#endif
|
||||
|
||||
WiFiClient espClient;
|
||||
|
@ -220,7 +220,9 @@ void saveConfigCallback () {
|
|||
// ***************************************************************************
|
||||
// Include: Color modes
|
||||
// ***************************************************************************
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
#include "colormodes.h"
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
// MAIN
|
||||
|
@ -599,7 +601,9 @@ void setup() {
|
|||
});
|
||||
|
||||
server.on("/off", []() {
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
mode = OFF;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
|
@ -618,8 +622,12 @@ void setup() {
|
|||
});
|
||||
|
||||
server.on("/all", []() {
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
mode = ALL;
|
||||
#endif
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
//mode = ALL;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
|
@ -636,6 +644,7 @@ void setup() {
|
|||
#endif
|
||||
});
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
server.on("/wipe", []() {
|
||||
exit_func = true;
|
||||
mode = WIPE;
|
||||
|
@ -768,6 +777,7 @@ void setup() {
|
|||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
#endif
|
||||
|
||||
server.on("/get_modes", []() {
|
||||
getModesJSON();
|
||||
|
@ -862,33 +872,28 @@ void loop() {
|
|||
// Simple statemachine that handles the different modes
|
||||
if (mode == SET_MODE) {
|
||||
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(ws2812fx_mode);
|
||||
mode = SETSPEED;
|
||||
prevmode = SET_MODE;
|
||||
mode = SETCOLOR;
|
||||
}
|
||||
if (mode == OFF) {
|
||||
// strip.setColor(0,0,0);
|
||||
// strip.setMode(FX_MODE_STATIC);
|
||||
if(strip.isRunning()) strip.stop(); //should clear memory
|
||||
// mode = HOLD;
|
||||
}
|
||||
if (mode == ALL) {
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_STATIC);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == SETCOLOR) {
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
mode = HOLD;
|
||||
mode = (prevmode == SET_MODE) ? SETSPEED : HOLD;
|
||||
}
|
||||
if (mode == SETSPEED) {
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
mode = BRIGHTNESS;
|
||||
mode = (prevmode == SET_MODE) ? BRIGHTNESS : HOLD;
|
||||
}
|
||||
if (mode == BRIGHTNESS) {
|
||||
strip.setBrightness(brightness);
|
||||
if (prevmode == SET_MODE) prevmode == HOLD;
|
||||
mode = HOLD;
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (mode == WIPE) {
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_COLOR_WIPE);
|
||||
|
@ -916,19 +921,28 @@ void loop() {
|
|||
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW);
|
||||
mode = HOLD;
|
||||
}
|
||||
#endif
|
||||
if (mode == HOLD || mode == CUSTOM) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (exit_func) {
|
||||
exit_func = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (mode == TV) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
tv();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only for modes with WS2812FX functionality
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (mode != TV && mode != CUSTOM) {
|
||||
#else
|
||||
if (mode != CUSTOM) {
|
||||
#endif
|
||||
strip.service();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
|
|||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||
|
||||
#define ENABLE_LEGACY_ANIMATIONS
|
||||
|
||||
#if defined(USE_NEOANIMATIONFX) and defined(USE_WS2812FX)
|
||||
#error "Cant have both NeoAnimationFX and WS2812FX enabled. Choose either one."
|
||||
|
@ -85,17 +85,22 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||
#define DBG_OUTPUT_PORT Serial // Set debug output port
|
||||
|
||||
// List of all color modes
|
||||
enum MODE { SET_MODE, HOLD, OFF, ALL, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
enum MODE { SET_MODE, HOLD, OFF, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
MODE mode = RAINBOW; // Standard mode that is active when software starts
|
||||
bool exit_func = false; // Global helper variable to get out of the color modes when mode changes
|
||||
#else
|
||||
enum MODE { SET_MODE, HOLD, OFF, SETCOLOR, SETSPEED, BRIGHTNESS, CUSTOM };
|
||||
MODE mode = SET_MODE; // Standard mode that is active when software starts
|
||||
#endif
|
||||
|
||||
MODE prevmode = mode;
|
||||
|
||||
int ws2812fx_speed = 196; // Global variable for storing the delay between color changes --> smaller == faster
|
||||
int brightness = 196; // Global variable for storing the brightness (255 == 100%)
|
||||
|
||||
int ws2812fx_mode = 0; // Helper variable to set WS2812FX modes
|
||||
|
||||
bool exit_func = false; // Global helper variable to get out of the color modes when mode changes
|
||||
|
||||
bool shouldSaveConfig = false; // For WiFiManger custom config
|
||||
|
||||
struct ledstate // Data structure to store a state of a single led
|
||||
|
|
|
@ -33,11 +33,10 @@ void getArgs() {
|
|||
}
|
||||
|
||||
if (server.arg("c").toInt() > 0) {
|
||||
brightness = (int) server.arg("c").toInt() * 2.55;
|
||||
} else {
|
||||
brightness = server.arg("p").toInt();
|
||||
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
||||
} else if (server.arg("p").toInt() > 0) {
|
||||
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
||||
}
|
||||
brightness = constrain(brightness, 0, 255);
|
||||
|
||||
main_color.red = constrain(main_color.red, 0, 255);
|
||||
main_color.green = constrain(main_color.green, 0, 255);
|
||||
|
@ -81,7 +80,8 @@ void handleSetMainColor(uint8_t * mypayload) {
|
|||
main_color.red = ((rgb >> 16) & 0xFF);
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb >> 0) & 0xFF);
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
// strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
mode = SETCOLOR;
|
||||
}
|
||||
|
||||
void handleSetAllMode(uint8_t * mypayload) {
|
||||
|
@ -92,13 +92,16 @@ void handleSetAllMode(uint8_t * mypayload) {
|
|||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb >> 0) & 0xFF);
|
||||
|
||||
for (int i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, main_color.red, main_color.green, main_color.blue);
|
||||
}
|
||||
strip.show();
|
||||
// for (int i = 0; i < strip.numPixels(); i++) {
|
||||
// strip.setPixelColor(i, main_color.red, main_color.green, main_color.blue);
|
||||
// }
|
||||
// strip.show();
|
||||
DBG_OUTPUT_PORT.printf("WS: Set all leds to main color: [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
mode = ALL;
|
||||
#endif
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
}
|
||||
|
||||
void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
|
@ -126,7 +129,9 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
|||
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue);
|
||||
strip.show();
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
mode = CUSTOM;
|
||||
}
|
||||
|
||||
|
@ -205,6 +210,7 @@ void setModeByStateString(String saved_state_string) {
|
|||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void handleSetNamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
|
||||
|
@ -215,7 +221,8 @@ void handleSetNamedMode(String str_mode) {
|
|||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=all")) {
|
||||
mode = ALL;
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
|
@ -263,6 +270,7 @@ void handleSetNamedMode(String str_mode) {
|
|||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
mode = HOLD;
|
||||
|
@ -277,10 +285,16 @@ char* listStatusJSON() {
|
|||
char json[255];
|
||||
|
||||
char modeName[30];
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
|
||||
// if (mode == SET_MODE) {
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName((uint8_t) ws2812fx_mode), sizeof(modeName)); // copy from progmem
|
||||
snprintf(json, sizeof(json), "{\"mode\":%d, \"ws2812fx_mode\":%d, \"ws2812fx_mode_name\":\"%s\", \"speed\":%d, \"brightness\":%d, \"color\":[%d, %d, %d]}",
|
||||
mode, strip.getMode(), modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
|
||||
mode, ws2812fx_mode, modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
|
||||
// }else {
|
||||
// strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem
|
||||
// snprintf(json, sizeof(json), "{\"mode\":%d, \"ws2812fx_mode\":%d, \"ws2812fx_mode_name\":\"%s\", \"speed\":%d, \"brightness\":%d, \"color\":[%d, %d, %d]}",
|
||||
// mode, strip.getMode(), modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
|
||||
// }
|
||||
return json;
|
||||
}
|
||||
|
||||
|
@ -510,6 +524,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
// we get mode data
|
||||
|
@ -532,6 +547,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
|
@ -604,6 +620,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void checkForRequests() {
|
||||
webSocket.loop();
|
||||
server.handleClient();
|
||||
|
@ -611,6 +628,7 @@ void checkForRequests() {
|
|||
mqtt_client.loop();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
|
@ -731,7 +749,8 @@ void checkForRequests() {
|
|||
const char* state_in = root["state"];
|
||||
if (strcmp(state_in, on_cmd) == 0 and !(animation_on)) {
|
||||
stateOn = true;
|
||||
mode = ALL;
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
}
|
||||
else if (strcmp(state_in, off_cmd) == 0) {
|
||||
stateOn = false;
|
||||
|
@ -934,6 +953,7 @@ void checkForRequests() {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
@ -952,6 +972,7 @@ void checkForRequests() {
|
|||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
|
|
Loading…
Reference in a new issue