Integrated Changes from Original repository
This commit is contained in:
+211
-193
@@ -53,14 +53,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;
|
||||
@@ -123,6 +123,9 @@ NeoAnimationFX<NEOMETHOD> strip(neoStrip);
|
||||
// https://github.com/kitesurfer1404/WS2812FX
|
||||
#include "WS2812FX.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef RGBW
|
||||
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
||||
#else
|
||||
@@ -137,10 +140,10 @@ NeoAnimationFX<NEOMETHOD> strip(neoStrip);
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
|
||||
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
|
||||
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||
// on a live circuit...if you must, connect GND first.
|
||||
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
|
||||
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||
// on a live circuit...if you must, connect GND first.
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -252,7 +255,9 @@ void saveConfigCallback () {
|
||||
// ***************************************************************************
|
||||
// Include: Color modes
|
||||
// ***************************************************************************
|
||||
#include "colormodes.h"
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
#include "colormodes.h"
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
// MAIN
|
||||
@@ -270,9 +275,6 @@ void setup() {
|
||||
pinMode(BUTTON, INPUT_PULLUP);
|
||||
#endif
|
||||
|
||||
DBG_OUTPUT_PORT.println("");
|
||||
DBG_OUTPUT_PORT.println("Starting....");
|
||||
|
||||
#ifdef ENABLE_BUTTON_GY33
|
||||
pinMode(BUTTON_GY33, INPUT_PULLUP);
|
||||
for (int i=0; i<256; i++) {
|
||||
@@ -289,6 +291,9 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
}
|
||||
#endif
|
||||
|
||||
DBG_OUTPUT_PORT.println("");
|
||||
DBG_OUTPUT_PORT.println("Starting....");
|
||||
|
||||
// start ticker with 0.5 because we start in AP mode and try to connect
|
||||
ticker.attach(0.5, tick);
|
||||
|
||||
@@ -583,7 +588,7 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
// ***************************************************************************
|
||||
server.on("/set_brightness", []() {
|
||||
getArgs();
|
||||
mode = BRIGHTNESS;
|
||||
mode = BRIGHTNESS;
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK %") + String(brightness)).c_str());
|
||||
#endif
|
||||
@@ -639,7 +644,6 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
});
|
||||
|
||||
server.on("/get_color", []() {
|
||||
//String rgbcolor = String(main_color.white, HEX) + String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX);
|
||||
char rgbcolor[9];
|
||||
snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
server.send(200, "text/plain", rgbcolor );
|
||||
@@ -652,7 +656,9 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
});
|
||||
|
||||
server.on("/off", []() {
|
||||
exit_func = true;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
mode = OFF;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
@@ -671,8 +677,12 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
});
|
||||
|
||||
server.on("/all", []() {
|
||||
exit_func = true;
|
||||
mode = ALL;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
//mode = ALL;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
@@ -689,138 +699,140 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/wipe", []() {
|
||||
exit_func = true;
|
||||
mode = WIPE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/rainbow", []() {
|
||||
exit_func = true;
|
||||
mode = RAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/rainbowCycle", []() {
|
||||
exit_func = true;
|
||||
mode = RAINBOWCYCLE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchase", []() {
|
||||
exit_func = true;
|
||||
mode = THEATERCHASE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/twinkleRandom", []() {
|
||||
exit_func = true;
|
||||
mode = TWINKLERANDOM;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
server.on("/wipe", []() {
|
||||
exit_func = true;
|
||||
mode = WIPE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchaseRainbow", []() {
|
||||
exit_func = true;
|
||||
mode = THEATERCHASERAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/tv", []() {
|
||||
exit_func = true;
|
||||
mode = TV;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
server.on("/rainbow", []() {
|
||||
exit_func = true;
|
||||
mode = RAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/rainbowCycle", []() {
|
||||
exit_func = true;
|
||||
mode = RAINBOWCYCLE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchase", []() {
|
||||
exit_func = true;
|
||||
mode = THEATERCHASE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/twinkleRandom", []() {
|
||||
exit_func = true;
|
||||
mode = TWINKLERANDOM;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchaseRainbow", []() {
|
||||
exit_func = true;
|
||||
mode = THEATERCHASERAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/tv", []() {
|
||||
exit_func = true;
|
||||
mode = TV;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
#endif
|
||||
|
||||
server.on("/get_modes", []() {
|
||||
getModesJSON();
|
||||
@@ -875,13 +887,16 @@ DBG_OUTPUT_PORT.println("Starting....");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
#ifdef ENABLE_BUTTON
|
||||
button();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BUTTON_GY33
|
||||
button_gy33();
|
||||
#endif
|
||||
|
||||
server.handleClient();
|
||||
webSocket.loop();
|
||||
|
||||
@@ -921,73 +936,77 @@ 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.white, 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,0);
|
||||
// strip.setMode(FX_MODE_STATIC);
|
||||
if(strip.isRunning()) strip.stop(); //should clear memory
|
||||
// mode = HOLD;
|
||||
}
|
||||
if (mode == ALL) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_STATIC);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == SETCOLOR) {
|
||||
strip.setColor(main_color.white, 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;
|
||||
}
|
||||
if (mode == WIPE) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_COLOR_WIPE);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == RAINBOW) {
|
||||
strip.setMode(FX_MODE_RAINBOW);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == RAINBOWCYCLE) {
|
||||
strip.setMode(FX_MODE_RAINBOW_CYCLE);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == THEATERCHASE) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_THEATER_CHASE);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == TWINKLERANDOM) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_TWINKLE_RANDOM);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == THEATERCHASERAINBOW) {
|
||||
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW);
|
||||
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);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == RAINBOW) {
|
||||
strip.setMode(FX_MODE_RAINBOW);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == RAINBOWCYCLE) {
|
||||
strip.setMode(FX_MODE_RAINBOW_CYCLE);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == THEATERCHASE) {
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_THEATER_CHASE);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == TWINKLERANDOM) {
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_TWINKLE_RANDOM);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == THEATERCHASERAINBOW) {
|
||||
strip.setMode(FX_MODE_THEATER_CHASE_RAINBOW);
|
||||
mode = HOLD;
|
||||
}
|
||||
#endif
|
||||
if (mode == HOLD || mode == CUSTOM) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
if (exit_func) {
|
||||
exit_func = false;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (exit_func) {
|
||||
exit_func = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
if (mode == TV) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
tv();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1014,5 +1033,4 @@ void loop() {
|
||||
EEPROM.commit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,328 @@
|
||||
#ifndef NeoAnimationFX_h
|
||||
#define NeoAnimationFX_h
|
||||
|
||||
#include <NeoPixelBrightnessBus.h>
|
||||
|
||||
#define DEFAULT_BRIGHTNESS 50
|
||||
#define DEFAULT_MODE 0
|
||||
#define DEFAULT_SPEED 1000
|
||||
#define DEFAULT_COLOR 0x00FF0000
|
||||
|
||||
#define SPEED_MIN 10
|
||||
#define SPEED_MAX 65535
|
||||
|
||||
#define BRIGHTNESS_MIN 0
|
||||
#define BRIGHTNESS_MAX 255
|
||||
|
||||
/* each segment uses 34 bytes of SRAM memory, so if you're application fails because of
|
||||
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
|
||||
#define MAX_NUM_SEGMENTS 10
|
||||
#define NUM_COLORS 4 /* number of colors per segment */
|
||||
#define SEGMENT _segments[_segment_index]
|
||||
#define SEGMENT_RUNTIME _segment_runtimes[_segment_index]
|
||||
#define SEGMENT_LENGTH (SEGMENT.stop - SEGMENT.start + 1)
|
||||
#define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes))
|
||||
|
||||
// some common colors
|
||||
#define RED 0x00FF0000
|
||||
#define GREEN 0x0000FF00
|
||||
#define BLUE 0x000000FF
|
||||
#define WHITE 0x00FFFFFF
|
||||
#define BLACK 0x00000000
|
||||
#define YELLOW 0x00FFFF00
|
||||
#define CYAN 0x0000FFFF
|
||||
#define MAGENTA 0x00FF00FF
|
||||
#define PURPLE 0x00400080
|
||||
#define ORANGE 0x00FF3000
|
||||
#define ULTRAWHITE 0xFFFFFFFF
|
||||
|
||||
#define MODE_COUNT 58
|
||||
|
||||
#define FX_MODE_STATIC 0
|
||||
#define FX_MODE_BLINK 1
|
||||
#define FX_MODE_BREATH 2
|
||||
#define FX_MODE_COLOR_WIPE 3
|
||||
#define FX_MODE_COLOR_WIPE_INV 4
|
||||
#define FX_MODE_COLOR_WIPE_REV 5
|
||||
#define FX_MODE_COLOR_WIPE_REV_INV 6
|
||||
#define FX_MODE_COLOR_WIPE_RANDOM 7
|
||||
#define FX_MODE_RANDOM_COLOR 8
|
||||
#define FX_MODE_SINGLE_DYNAMIC 9
|
||||
#define FX_MODE_MULTI_DYNAMIC 10
|
||||
#define FX_MODE_RAINBOW 11
|
||||
#define FX_MODE_RAINBOW_CYCLE 12
|
||||
#define FX_MODE_SCAN 13
|
||||
#define FX_MODE_DUAL_SCAN 14
|
||||
#define FX_MODE_FADE 15
|
||||
#define FX_MODE_THEATER_CHASE 16
|
||||
#define FX_MODE_THEATER_CHASE_RAINBOW 17
|
||||
#define FX_MODE_RUNNING_LIGHTS 18
|
||||
#define FX_MODE_TWINKLE 19
|
||||
#define FX_MODE_TWINKLE_RANDOM 20
|
||||
#define FX_MODE_TWINKLE_FADE 21
|
||||
#define FX_MODE_TWINKLE_FADE_RANDOM 22
|
||||
#define FX_MODE_SPARKLE 23
|
||||
#define FX_MODE_FLASH_SPARKLE 24
|
||||
#define FX_MODE_HYPER_SPARKLE 25
|
||||
#define FX_MODE_STROBE 26
|
||||
#define FX_MODE_STROBE_RAINBOW 27
|
||||
#define FX_MODE_MULTI_STROBE 28
|
||||
#define FX_MODE_BLINK_RAINBOW 29
|
||||
#define FX_MODE_CHASE_WHITE 30
|
||||
#define FX_MODE_CHASE_COLOR 31
|
||||
#define FX_MODE_CHASE_RANDOM 32
|
||||
#define FX_MODE_CHASE_RAINBOW 33
|
||||
#define FX_MODE_CHASE_FLASH 34
|
||||
#define FX_MODE_CHASE_FLASH_RANDOM 35
|
||||
#define FX_MODE_CHASE_RAINBOW_WHITE 36
|
||||
#define FX_MODE_CHASE_BLACKOUT 37
|
||||
#define FX_MODE_CHASE_BLACKOUT_RAINBOW 38
|
||||
#define FX_MODE_COLOR_SWEEP_RANDOM 39
|
||||
#define FX_MODE_RUNNING_COLOR 40
|
||||
#define FX_MODE_RUNNING_RED_BLUE 41
|
||||
#define FX_MODE_RUNNING_RANDOM 42
|
||||
#define FX_MODE_LARSON_SCANNER 43
|
||||
#define FX_MODE_COMET 44
|
||||
#define FX_MODE_FIREWORKS 45
|
||||
#define FX_MODE_FIREWORKS_RANDOM 46
|
||||
#define FX_MODE_MERRY_CHRISTMAS 47
|
||||
#define FX_MODE_FIRE_FLICKER 48
|
||||
#define FX_MODE_FIRE_FLICKER_SOFT 49
|
||||
#define FX_MODE_FIRE_FLICKER_INTENSE 50
|
||||
#define FX_MODE_CIRCUS_COMBUSTUS 51
|
||||
#define FX_MODE_HALLOWEEN 52
|
||||
#define FX_MODE_BICOLOR_CHASE 53
|
||||
#define FX_MODE_TRICOLOR_CHASE 54
|
||||
#define FX_MODE_ICU 55
|
||||
#define FX_MODE_CUSTOM 56
|
||||
#define FX_MODE_METEOR_RAIN 57
|
||||
|
||||
#define MAX_PIXEL_CT 3000
|
||||
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, Neo800KbpsMethod> NeoPBBGRB800; // Use this for WS2812
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, Neo400KbpsMethod> NeoPBBGRB400;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> NeoPBBGRBU800;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart400KbpsMethod> NeoPBBGRBU400;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> NeoPBBGRBD800;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Dma400KbpsMethod> NeoPBBGRBD400;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> NeoPBBGRBBB800;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266BitBang400KbpsMethod> NeoPBBGRBBB400;
|
||||
typedef NeoPixelBrightnessBus<NeoGrbFeature, NeoWs2813Method> NeoPBBGRBws2813;
|
||||
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> NeoPBBRGB800;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, Neo400KbpsMethod> NeoPBBRGB400;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266Uart800KbpsMethod> NeoPBBRGBU800;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> NeoPBBRGBU400;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266Dma800KbpsMethod> NeoPBBRGBD800;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> NeoPBBRGBD400;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266BitBang800KbpsMethod> NeoPBBRGBBB800;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoEsp8266BitBang400KbpsMethod> NeoPBBRGBBB400;
|
||||
typedef NeoPixelBrightnessBus<NeoRgbFeature, NeoWs2813Method> NeoPBBRGBws2813;
|
||||
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, Neo800KbpsMethod> NeoPBBBRG800;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, Neo400KbpsMethod> NeoPBBBRG400;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart800KbpsMethod> NeoPBBBRGU800;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart400KbpsMethod> NeoPBBBRGU400;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Dma800KbpsMethod> NeoPBBBRGD800;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Dma400KbpsMethod> NeoPBBBRGD400;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266BitBang800KbpsMethod> NeoPBBBRGBB800;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266BitBang400KbpsMethod> NeoPBBBRGBB400;
|
||||
typedef NeoPixelBrightnessBus<NeoBrgFeature, NeoWs2813Method> NeoPBBBRGws2813;
|
||||
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, Neo800KbpsMethod> NeoPBBRBG800;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, Neo400KbpsMethod> NeoPBBRBG400;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266Uart800KbpsMethod> NeoPBBRBGU800;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266Uart400KbpsMethod> NeoPBBRBGU400;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266Dma800KbpsMethod> NeoPBBRBGD800;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266Dma400KbpsMethod> NeoPBBRBGD400;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266BitBang800KbpsMethod> NeoPBBRBGBB800;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoEsp8266BitBang400KbpsMethod> NeoPBBRBGBB400;
|
||||
typedef NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2813Method> NeoPBBRBGws2813;
|
||||
|
||||
//typedef NeoPixelBrightnessBus <NeoRgbwFeature, Neo800KbpsMethod> NeoPBBRGBW800; // Not supported yet
|
||||
|
||||
template<typename T_PIXEL_METHOD> class NeoAnimationFX {
|
||||
typedef uint16_t (NeoAnimationFX::*mode_ptr)(void);
|
||||
|
||||
public:
|
||||
|
||||
// segment parameters
|
||||
|
||||
/* set default values c way
|
||||
struct segment_struct {
|
||||
uint8_t mode;
|
||||
RgbColor color;
|
||||
uint16_t speed;
|
||||
uint16_t start;
|
||||
uint16_t stop;
|
||||
bool reverse;
|
||||
} segment_default = { FX_MODE_STATIC, (RgbColor) HtmlColor(DEFAULT_COLOR), DEFAULT_SPEED, 0, 7, false};
|
||||
|
||||
typedef struct segment_struct segment; */
|
||||
|
||||
typedef struct Segment {
|
||||
uint8_t mode;
|
||||
RgbColor colors[NUM_COLORS];
|
||||
uint16_t speed;
|
||||
uint16_t start;
|
||||
uint16_t stop;
|
||||
bool reverse;
|
||||
// set default values c++ way
|
||||
Segment():
|
||||
mode(FX_MODE_STATIC),
|
||||
colors({(RgbColor) HtmlColor(DEFAULT_COLOR), (RgbColor) HtmlColor(BLACK), (RgbColor) HtmlColor(GREEN)}),
|
||||
speed(DEFAULT_SPEED),
|
||||
start(0),
|
||||
stop(7),
|
||||
reverse(false) {}
|
||||
} segment;
|
||||
|
||||
// segment runtime parameters
|
||||
typedef struct Segment_runtime {
|
||||
uint32_t counter_mode_step;
|
||||
uint32_t counter_mode_call;
|
||||
unsigned long next_time;
|
||||
uint16_t aux_param;
|
||||
} segment_runtime;
|
||||
|
||||
NeoAnimationFX(T_PIXEL_METHOD& pixelStrip) :
|
||||
_strip(pixelStrip) {
|
||||
_mode[FX_MODE_STATIC] = &NeoAnimationFX::mode_static;
|
||||
_mode[FX_MODE_BLINK] = &NeoAnimationFX::mode_blink;
|
||||
_mode[FX_MODE_COLOR_WIPE] = &NeoAnimationFX::mode_color_wipe;
|
||||
_mode[FX_MODE_COLOR_WIPE_INV] = &NeoAnimationFX::mode_color_wipe_inv;
|
||||
_mode[FX_MODE_COLOR_WIPE_REV] = &NeoAnimationFX::mode_color_wipe_rev;
|
||||
_mode[FX_MODE_COLOR_WIPE_REV_INV] = &NeoAnimationFX::mode_color_wipe_rev_inv;
|
||||
_mode[FX_MODE_COLOR_WIPE_RANDOM] = &NeoAnimationFX::mode_color_wipe_random;
|
||||
_mode[FX_MODE_RANDOM_COLOR] = &NeoAnimationFX::mode_random_color;
|
||||
_mode[FX_MODE_SINGLE_DYNAMIC] = &NeoAnimationFX::mode_single_dynamic;
|
||||
_mode[FX_MODE_MULTI_DYNAMIC] = &NeoAnimationFX::mode_multi_dynamic;
|
||||
_mode[FX_MODE_RAINBOW] = &NeoAnimationFX::mode_rainbow;
|
||||
_mode[FX_MODE_RAINBOW_CYCLE] = &NeoAnimationFX::mode_rainbow_cycle;
|
||||
_mode[FX_MODE_SCAN] = &NeoAnimationFX::mode_scan;
|
||||
_mode[FX_MODE_DUAL_SCAN] = &NeoAnimationFX::mode_dual_scan;
|
||||
_mode[FX_MODE_FADE] = &NeoAnimationFX::mode_fade;
|
||||
_mode[FX_MODE_THEATER_CHASE] = &NeoAnimationFX::mode_theater_chase;
|
||||
_mode[FX_MODE_THEATER_CHASE_RAINBOW] = &NeoAnimationFX::mode_theater_chase_rainbow;
|
||||
_mode[FX_MODE_TWINKLE] = &NeoAnimationFX::mode_twinkle;
|
||||
_mode[FX_MODE_TWINKLE_RANDOM] = &NeoAnimationFX::mode_twinkle_random;
|
||||
_mode[FX_MODE_TWINKLE_FADE] = &NeoAnimationFX::mode_twinkle_fade;
|
||||
_mode[FX_MODE_TWINKLE_FADE_RANDOM] = &NeoAnimationFX::mode_twinkle_fade_random;
|
||||
_mode[FX_MODE_SPARKLE] = &NeoAnimationFX::mode_sparkle;
|
||||
_mode[FX_MODE_FLASH_SPARKLE] = &NeoAnimationFX::mode_flash_sparkle;
|
||||
_mode[FX_MODE_HYPER_SPARKLE] = &NeoAnimationFX::mode_hyper_sparkle;
|
||||
_mode[FX_MODE_STROBE] = &NeoAnimationFX::mode_strobe;
|
||||
_mode[FX_MODE_STROBE_RAINBOW] = &NeoAnimationFX::mode_strobe_rainbow;
|
||||
_mode[FX_MODE_MULTI_STROBE] = &NeoAnimationFX::mode_multi_strobe;
|
||||
_mode[FX_MODE_BLINK_RAINBOW] = &NeoAnimationFX::mode_blink_rainbow;
|
||||
_mode[FX_MODE_CHASE_WHITE] = &NeoAnimationFX::mode_chase_white;
|
||||
_mode[FX_MODE_CHASE_COLOR] = &NeoAnimationFX::mode_chase_color;
|
||||
_mode[FX_MODE_CHASE_RANDOM] = &NeoAnimationFX::mode_chase_random;
|
||||
_mode[FX_MODE_CHASE_RAINBOW] = &NeoAnimationFX::mode_chase_rainbow;
|
||||
_mode[FX_MODE_CHASE_FLASH] = &NeoAnimationFX::mode_chase_flash;
|
||||
_mode[FX_MODE_CHASE_FLASH_RANDOM] = &NeoAnimationFX::mode_chase_flash_random;
|
||||
_mode[FX_MODE_CHASE_RAINBOW_WHITE] = &NeoAnimationFX::mode_chase_rainbow_white;
|
||||
_mode[FX_MODE_CHASE_BLACKOUT] = &NeoAnimationFX::mode_chase_blackout;
|
||||
_mode[FX_MODE_CHASE_BLACKOUT_RAINBOW] = &NeoAnimationFX::mode_chase_blackout_rainbow;
|
||||
_mode[FX_MODE_COLOR_SWEEP_RANDOM] = &NeoAnimationFX::mode_color_sweep_random;
|
||||
_mode[FX_MODE_RUNNING_COLOR] = &NeoAnimationFX::mode_running_color;
|
||||
_mode[FX_MODE_RUNNING_RED_BLUE] = &NeoAnimationFX::mode_running_red_blue;
|
||||
_mode[FX_MODE_RUNNING_RANDOM] = &NeoAnimationFX::mode_running_random;
|
||||
_mode[FX_MODE_LARSON_SCANNER] = &NeoAnimationFX::mode_larson_scanner;
|
||||
_mode[FX_MODE_COMET] = &NeoAnimationFX::mode_comet;
|
||||
_mode[FX_MODE_FIREWORKS] = &NeoAnimationFX::mode_fireworks;
|
||||
_mode[FX_MODE_FIREWORKS_RANDOM] = &NeoAnimationFX::mode_fireworks_random;
|
||||
_mode[FX_MODE_MERRY_CHRISTMAS] = &NeoAnimationFX::mode_merry_christmas;
|
||||
_mode[FX_MODE_HALLOWEEN] = &NeoAnimationFX::mode_halloween;
|
||||
_mode[FX_MODE_FIRE_FLICKER] = &NeoAnimationFX::mode_fire_flicker;
|
||||
_mode[FX_MODE_FIRE_FLICKER_SOFT] = &NeoAnimationFX::mode_fire_flicker_soft;
|
||||
_mode[FX_MODE_FIRE_FLICKER_INTENSE] = &NeoAnimationFX::mode_fire_flicker_intense;
|
||||
_mode[FX_MODE_CIRCUS_COMBUSTUS] = &NeoAnimationFX::mode_circus_combustus;
|
||||
_mode[FX_MODE_BICOLOR_CHASE] = &NeoAnimationFX::mode_bicolor_chase;
|
||||
_mode[FX_MODE_TRICOLOR_CHASE] = &NeoAnimationFX::mode_tricolor_chase;
|
||||
// if flash memory is constrained (I'm looking at you Arduino Nano), replace modes
|
||||
// that use a lot of flash with mode_static (reduces flash footprint by about 3600 bytes)
|
||||
#ifdef REDUCED_MODES
|
||||
_mode[FX_MODE_BREATH] = &NeoAnimationFX::mode_static;
|
||||
_mode[FX_MODE_RUNNING_LIGHTS] = &NeoAnimationFX::mode_static;
|
||||
_mode[FX_MODE_ICU] = &NeoAnimationFX::mode_static;
|
||||
#else
|
||||
_mode[FX_MODE_BREATH] = &NeoAnimationFX::mode_breath;
|
||||
_mode[FX_MODE_RUNNING_LIGHTS] = &NeoAnimationFX::mode_running_lights;
|
||||
_mode[FX_MODE_ICU] = &NeoAnimationFX::mode_icu;
|
||||
#endif
|
||||
_mode[FX_MODE_CUSTOM] = &NeoAnimationFX::mode_custom;
|
||||
_mode[FX_MODE_METEOR_RAIN] = &NeoAnimationFX::mode_meteor_rain;
|
||||
|
||||
_name[FX_MODE_STATIC] = F("Static");
|
||||
_name[FX_MODE_BLINK] = F("Blink");
|
||||
_name[FX_MODE_BREATH] = F("Breath");
|
||||
_name[FX_MODE_COLOR_WIPE] = F("Color Wipe");
|
||||
_name[FX_MODE_COLOR_WIPE_INV ] = F("Color Wipe Inverse");
|
||||
_name[FX_MODE_COLOR_WIPE_REV] = F("Color Wipe Reverse");
|
||||
_name[FX_MODE_COLOR_WIPE_REV_INV] = F("Color Wipe Reverse Inverse");
|
||||
_name[FX_MODE_COLOR_WIPE_RANDOM] = F("Color Wipe Random");
|
||||
_name[FX_MODE_RANDOM_COLOR] = F("Random Color");
|
||||
_name[FX_MODE_SINGLE_DYNAMIC] = F("Single Dynamic");
|
||||
_name[FX_MODE_MULTI_DYNAMIC] = F("Multi Dynamic");
|
||||
_name[FX_MODE_RAINBOW] = F("Rainbow");
|
||||
_name[FX_MODE_RAINBOW_CYCLE] = F("Rainbow Cycle");
|
||||
_name[FX_MODE_SCAN] = F("Scan");
|
||||
_name[FX_MODE_DUAL_SCAN] = F("Dual Scan");
|
||||
_name[FX_MODE_FADE] = F("Fade");
|
||||
_name[FX_MODE_THEATER_CHASE] = F("Theater Chase");
|
||||
_name[FX_MODE_THEATER_CHASE_RAINBOW] = F("Theater Chase Rainbow");
|
||||
_name[FX_MODE_RUNNING_LIGHTS] = F("Running Lights");
|
||||
_name[FX_MODE_TWINKLE] = F("Twinkle");
|
||||
_name[FX_MODE_TWINKLE_RANDOM] = F("Twinkle Random");
|
||||
_name[FX_MODE_TWINKLE_FADE] = F("Twinkle Fade");
|
||||
_name[FX_MODE_TWINKLE_FADE_RANDOM] = F("Twinkle Fade Random");
|
||||
_name[FX_MODE_SPARKLE] = F("Sparkle");
|
||||
_name[FX_MODE_FLASH_SPARKLE] = F("Flash Sparkle");
|
||||
_name[FX_MODE_HYPER_SPARKLE] = F("Hyper Sparkle");
|
||||
_name[FX_MODE_STROBE] = F("Strobe");
|
||||
_name[FX_MODE_STROBE_RAINBOW] = F("Strobe Rainbow");
|
||||
_name[FX_MODE_MULTI_STROBE] = F("Multi Strobe");
|
||||
_name[FX_MODE_BLINK_RAINBOW] = F("Blink Rainbow");
|
||||
_name[FX_MODE_CHASE_WHITE] = F("Chase White");
|
||||
_name[FX_MODE_CHASE_COLOR] = F("Chase Color");
|
||||
_name[FX_MODE_CHASE_RANDOM] = F("Chase Random");
|
||||
_name[FX_MODE_CHASE_RAINBOW] = F("Chase Rainbow");
|
||||
_name[FX_MODE_CHASE_FLASH] = F("Chase Flash");
|
||||
_name[FX_MODE_CHASE_FLASH_RANDOM] = F("Chase Flash Random");
|
||||
_name[FX_MODE_CHASE_RAINBOW_WHITE] = F("Chase Rainbow White");
|
||||
_name[FX_MODE_CHASE_BLACKOUT] = F("Chase Blackout");
|
||||
_name[FX_MODE_CHASE_BLACKOUT_RAINBOW] = F("Chase Blackout Rainbow");
|
||||
_name[FX_MODE_COLOR_SWEEP_RANDOM] = F("Color Sweep Random");
|
||||
_name[FX_MODE_RUNNING_COLOR] = F("Running Color");
|
||||
_name[FX_MODE_RUNNING_RED_BLUE] = F("Running Red Blue");
|
||||
_name[FX_MODE_RUNNING_RANDOM] = F("Running Random");
|
||||
_name[FX_MODE_LARSON_SCANNER] = F("Larson Scanner");
|
||||
_name[FX_MODE_COMET] = F("Comet");
|
||||
_name[FX_MODE_FIREWORKS] = F("Fireworks");
|
||||
_name[FX_MODE_FIREWORKS_RANDOM] = F("Fireworks Random");
|
||||
_name[FX_MODE_MERRY_CHRISTMAS] = F("Merry Christmas");
|
||||
_name[FX_MODE_HALLOWEEN] = F("Halloween");
|
||||
_name[FX_MODE_FIRE_FLICKER] = F("Fire Flicker");
|
||||
_name[FX_MODE_FIRE_FLICKER_SOFT] = F("Fire Flicker (soft)");
|
||||
_name[FX_MODE_FIRE_FLICKER_INTENSE] = F("Fire Flicker (intense)");
|
||||
_name[FX_MODE_CIRCUS_COMBUSTUS] = F("Circus Combustus");
|
||||
_name[FX_MODE_BICOLOR_CHASE] = F("Bicolor Chase");
|
||||
_name[FX_MODE_TRICOLOR_CHASE] = F("Tricolor Chase");
|
||||
_name[FX_MODE_ICU] = F("ICU");
|
||||
_name[FX_MODE_CUSTOM] = F("Custom");
|
||||
_name[FX_MODE_METEOR_RAIN] = F("Meteor Rain");
|
||||
|
||||
_brightness = DEFAULT_BRIGHTNESS;
|
||||
_running = false;
|
||||
_num_segments = 1;
|
||||
_segments[0].mode = DEFAULT_MODE;
|
||||
_segments[0].colors[0] = (RgbColor) HtmlColor(DEFAULT_COLOR);
|
||||
_segments[0].start = 0;
|
||||
(_strip.PixelCount() >= MAX_PIXEL_CT) ? _segments[0].stop = MAX_PIXEL_CT : _segments[0].stop = _strip.PixelCount() ;
|
||||
_segments[0].speed = DEFAULT_SPEED;
|
||||
RESET_RUNTIME;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,97 +0,0 @@
|
||||
<!--
|
||||
FSWebServer - Example Index Page
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the ESP8266WebServer library for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>ESP Monitor</title>
|
||||
<script type="text/javascript" src="graphs.js"></script>
|
||||
<script type="text/javascript">
|
||||
var heap,temp,digi;
|
||||
var reloadPeriod = 1000;
|
||||
var running = false;
|
||||
|
||||
function loadValues(){
|
||||
if(!running) return;
|
||||
var xh = new XMLHttpRequest();
|
||||
xh.onreadystatechange = function(){
|
||||
if (xh.readyState == 4){
|
||||
if(xh.status == 200) {
|
||||
var res = JSON.parse(xh.responseText);
|
||||
heap.add(res.heap);
|
||||
temp.add(res.analog);
|
||||
digi.add(res.gpio);
|
||||
if(running) setTimeout(loadValues, reloadPeriod);
|
||||
} else running = false;
|
||||
}
|
||||
};
|
||||
xh.open("GET", "/status", true);
|
||||
xh.send(null);
|
||||
};
|
||||
|
||||
function run(){
|
||||
if(!running){
|
||||
running = true;
|
||||
loadValues();
|
||||
}
|
||||
}
|
||||
|
||||
function onBodyLoad(){
|
||||
var refreshInput = document.getElementById("refresh-rate");
|
||||
refreshInput.value = reloadPeriod;
|
||||
refreshInput.onchange = function(e){
|
||||
var value = parseInt(e.target.value);
|
||||
reloadPeriod = (value > 0)?value:0;
|
||||
e.target.value = reloadPeriod;
|
||||
}
|
||||
var stopButton = document.getElementById("stop-button");
|
||||
stopButton.onclick = function(e){
|
||||
running = false;
|
||||
}
|
||||
var startButton = document.getElementById("start-button");
|
||||
startButton.onclick = function(e){
|
||||
run();
|
||||
}
|
||||
|
||||
// Example with 10K thermistor
|
||||
//function calcThermistor(v) {
|
||||
// var t = Math.log(((10230000 / v) - 10000));
|
||||
// t = (1/(0.001129148+(0.000234125*t)+(0.0000000876741*t*t*t)))-273.15;
|
||||
// return (t>120)?0:Math.round(t*10)/10;
|
||||
//}
|
||||
//temp = createGraph(document.getElementById("analog"), "Temperature", 100, 128, 10, 40, false, "cyan", calcThermistor);
|
||||
|
||||
temp = createGraph(document.getElementById("analog"), "Analog Input", 100, 128, 0, 1023, false, "cyan");
|
||||
heap = createGraph(document.getElementById("heap"), "Current Heap", 100, 125, 0, 30000, true, "orange");
|
||||
digi = createDigiGraph(document.getElementById("digital"), "GPIO", 100, 146, [0, 4, 5, 16], "gold");
|
||||
run();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body id="index" style="margin:0; padding:0;" onload="onBodyLoad()">
|
||||
<div id="controls" style="display: block; border: 1px solid rgb(68, 68, 68); padding: 5px; margin: 5px; width: 362px; background-color: rgb(238, 238, 238);">
|
||||
<label>Period (ms):</label>
|
||||
<input type="number" id="refresh-rate"/>
|
||||
<input type="button" id="start-button" value="Start"/>
|
||||
<input type="button" id="stop-button" value="Stop"/>
|
||||
</div>
|
||||
<div id="heap"></div>
|
||||
<div id="analog"></div>
|
||||
<div id="digital"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,4 @@
|
||||
//#define USE_NEOANIMATIONFX // Uses NeoAnimationFX, PIN is ignored & set to RX/GPIO3, see: https://github.com/debsahu/NeoAnimationFX
|
||||
//#define USE_NEOANIMATIONFX // Uses NeoAnimationFX, PIN is ignored & set to RX/GPIO3 or UART method: D4/GPIO2, see: https://github.com/debsahu/NeoAnimationFX
|
||||
#define USE_WS2812FX // Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
|
||||
// Neopixel
|
||||
@@ -9,7 +9,7 @@
|
||||
#define BUTTON_GY33 12 // Input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
||||
#define RGBW
|
||||
|
||||
const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
||||
const char HOSTNAME[] = "McLightingRGBW01"; // Friedly hostname
|
||||
|
||||
#define HTTP_OTA // If defined, enable Added ESP8266HTTPUpdateServer
|
||||
//#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
||||
@@ -19,7 +19,7 @@ const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||
//#define ENABLE_BUTTON_GY33 //
|
||||
//#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."
|
||||
@@ -88,17 +88,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, AUTO };
|
||||
#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 mode = RAINBOW; // Standard mode that is active when software starts
|
||||
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
|
||||
@@ -127,7 +132,6 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
||||
#endif
|
||||
|
||||
// Button handling
|
||||
|
||||
#ifdef ENABLE_BUTTON || ENABLE_BUTTON_GY33
|
||||
boolean buttonState = false;
|
||||
#endif
|
||||
|
||||
@@ -33,13 +33,12 @@ void getArgs() {
|
||||
if (server.arg("m") != "") {
|
||||
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1);
|
||||
}
|
||||
|
||||
|
||||
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.white = constrain(main_color.white, 0, 255);
|
||||
main_color.red = constrain(main_color.red, 0, 255);
|
||||
@@ -88,6 +87,7 @@ void handleSetMainColor(uint8_t * mypayload) {
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
mode = SETCOLOR;
|
||||
}
|
||||
|
||||
void handleSetAllMode(uint8_t * mypayload) {
|
||||
@@ -99,13 +99,16 @@ void handleSetAllMode(uint8_t * mypayload) {
|
||||
main_color.green = ((rgb >> 8) & 0xFF);
|
||||
main_color.blue = ((rgb ) & 0xFF);
|
||||
|
||||
for (int i = 0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, main_color.red, main_color.green, main_color.blue, main_color.white);
|
||||
}
|
||||
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: W: [%u] R: [%u] G: [%u] B: [%u]\n", main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
exit_func = true;
|
||||
mode = ALL;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
}
|
||||
|
||||
void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
@@ -136,7 +139,9 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 0) {
|
||||
strip.setPixelColor(led, ledstates[led].red, ledstates[led].green, ledstates[led].blue, ledstates[led].white);
|
||||
strip.show();
|
||||
}
|
||||
exit_func = true;
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
exit_func = true;
|
||||
#endif
|
||||
mode = CUSTOM;
|
||||
}
|
||||
|
||||
@@ -218,82 +223,82 @@ void setModeByStateString(String saved_state_string) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
}
|
||||
|
||||
void handleSetNamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
|
||||
if (str_mode.startsWith("=off")) {
|
||||
mode = OFF;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = false;
|
||||
#endif
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void handleSetNamedMode(String str_mode) {
|
||||
exit_func = true;
|
||||
|
||||
if (str_mode.startsWith("=off")) {
|
||||
mode = OFF;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = false;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=all")) {
|
||||
ws2812fx_mode = FX_MODE_STATIC;
|
||||
mode = SET_MODE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=wipe")) {
|
||||
mode = WIPE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbow")) {
|
||||
mode = RAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbowCycle")) {
|
||||
mode = RAINBOWCYCLE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchase")) {
|
||||
mode = THEATERCHASE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=twinkleRandom")) {
|
||||
mode = TWINKLERANDOM;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
||||
mode = THEATERCHASERAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=tv")) {
|
||||
mode = TV;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (str_mode.startsWith("=all")) {
|
||||
mode = ALL;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=wipe")) {
|
||||
mode = WIPE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbow")) {
|
||||
mode = RAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=rainbowCycle")) {
|
||||
mode = RAINBOWCYCLE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchase")) {
|
||||
mode = THEATERCHASE;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=twinkleRandom")) {
|
||||
mode = TWINKLERANDOM;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=theaterchaseRainbow")) {
|
||||
mode = THEATERCHASERAINBOW;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
if (str_mode.startsWith("=tv")) {
|
||||
mode = TV;
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleSetWS2812FXMode(uint8_t * mypayload) {
|
||||
mode = HOLD;
|
||||
uint8_t ws2812fx_mode = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
ws2812fx_mode = constrain(ws2812fx_mode, 0, 255);
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(ws2812fx_mode);
|
||||
strip.start();
|
||||
mode = SET_MODE;
|
||||
uint8_t ws2812fx_mode_tmp = (uint8_t) strtol((const char *) &mypayload[1], NULL, 10);
|
||||
ws2812fx_mode = constrain(ws2812fx_mode_tmp, 0, strip.getModeCount() - 1);
|
||||
}
|
||||
|
||||
char* listStatusJSON() {
|
||||
char json[255];
|
||||
|
||||
char modeName[30];
|
||||
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, %d]}",
|
||||
mode, strip.getMode(), modeName, ws2812fx_speed, brightness, main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
uint8_t tmp_mode = (mode == SET_MODE) ? (uint8_t) ws2812fx_mode : strip.getMode();
|
||||
|
||||
strncpy_P(modeName, (PGM_P)strip.getModeName(tmp_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, tmp_mode, modeName, ws2812fx_speed, brightness, main_color.red, main_color.green, main_color.blue);
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -525,28 +530,30 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
#endif
|
||||
}
|
||||
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
// we get mode data
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
|
||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||
webSocket.sendTXT(num, "OK");
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
// we get mode data
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
|
||||
handleSetNamedMode(str_mode);
|
||||
|
||||
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||
webSocket.sendTXT(num, "OK");
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
@@ -619,13 +626,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||
}
|
||||
}
|
||||
|
||||
void checkForRequests() {
|
||||
webSocket.loop();
|
||||
server.handleClient();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.loop();
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
void checkForRequests() {
|
||||
webSocket.loop();
|
||||
server.handleClient();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.loop();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -746,7 +755,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;
|
||||
@@ -949,24 +959,26 @@ void checkForRequests() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
handleSetNamedMode(str_mode);
|
||||
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||
// = ==> Activate named mode
|
||||
if (payload[0] == '=') {
|
||||
String str_mode = String((char *) &payload[0]);
|
||||
handleSetNamedMode(str_mode);
|
||||
DBG_OUTPUT_PORT.printf("MQTT: Activate named mode [%s]\n", payload);
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ") + String((char *)payload)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// $ ==> Get status Info.
|
||||
if (payload[0] == '$') {
|
||||
@@ -1440,14 +1452,14 @@ bool writeStateFS(){
|
||||
DynamicJsonBuffer jsonBuffer(JSON_OBJECT_SIZE(7));
|
||||
// StaticJsonBuffer<JSON_OBJECT_SIZE(7)> jsonBuffer;
|
||||
JsonObject& json = jsonBuffer.createObject();
|
||||
json["mode"] = static_cast<int>(mode);
|
||||
json["mode"] = static_cast<int>(mode);
|
||||
json["strip_mode"] = (int) strip.getMode();
|
||||
json["brightness"] = brightness;
|
||||
json["speed"] = ws2812fx_speed;
|
||||
json["white"] = main_color.white;
|
||||
json["red"] = main_color.red;
|
||||
json["green"] = main_color.green;
|
||||
json["blue"] = main_color.blue;
|
||||
json["speed"] = ws2812fx_speed;
|
||||
json["white"] = main_color.white;
|
||||
json["red"] = main_color.red;
|
||||
json["green"] = main_color.green;
|
||||
json["blue"] = main_color.blue;
|
||||
|
||||
// SPIFFS.remove("/state.json") ? DBG_OUTPUT_PORT.println("removed file") : DBG_OUTPUT_PORT.println("failed removing file");
|
||||
File configFile = SPIFFS.open("/stripstate.json", "w");
|
||||
@@ -1487,9 +1499,9 @@ bool readStateFS() {
|
||||
json.printTo(DBG_OUTPUT_PORT);
|
||||
if (json.success()) {
|
||||
mode = static_cast<MODE>((int) json["mode"]);
|
||||
ws2812fx_mode = json["strip_mode"];
|
||||
brightness = json["brightness"];
|
||||
ws2812fx_speed = json["speed"];
|
||||
ws2812fx_mode = json["strip_mode"];
|
||||
brightness = json["brightness"];
|
||||
ws2812fx_speed = json["speed"];
|
||||
main_color.white = json["white"];
|
||||
main_color.red = json["red"];
|
||||
main_color.green = json["green"];
|
||||
@@ -1516,4 +1528,3 @@ bool readStateFS() {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user