code cleanup, Bugfixes
Removed redundand code and moved it into function Minor bugfixes
This commit is contained in:
@@ -98,4 +98,3 @@ class GY33_MCU {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -24,25 +24,7 @@
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Initialize Color Sensor
|
// Initialize Color Sensor
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
byte gammatable[256];
|
|
||||||
GY33_MCU tcs;
|
GY33_MCU tcs;
|
||||||
byte gamma8[] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
|
|
||||||
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
|
|
||||||
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
|
|
||||||
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
|
|
||||||
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
|
|
||||||
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
|
||||||
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
|
|
||||||
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
|
|
||||||
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
|
|
||||||
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
|
|
||||||
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
|
|
||||||
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
|
|
||||||
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
|
|
||||||
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// OTA
|
// OTA
|
||||||
@@ -123,14 +105,11 @@ NeoAnimationFX<NEOMETHOD> strip(neoStrip);
|
|||||||
// https://github.com/kitesurfer1404/WS2812FX
|
// https://github.com/kitesurfer1404/WS2812FX
|
||||||
#include "WS2812FX.h"
|
#include "WS2812FX.h"
|
||||||
|
|
||||||
|
#ifdef RGBW
|
||||||
|
|
||||||
|
|
||||||
#ifdef RGBW
|
|
||||||
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
||||||
#else
|
#else
|
||||||
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
|
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Parameter 1 = number of pixels in strip
|
// Parameter 1 = number of pixels in strip
|
||||||
// Parameter 2 = Arduino pin number (most are valid)
|
// Parameter 2 = Arduino pin number (most are valid)
|
||||||
@@ -277,13 +256,6 @@ void setup() {
|
|||||||
|
|
||||||
#ifdef ENABLE_BUTTON_GY33
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
pinMode(BUTTON_GY33, INPUT_PULLUP);
|
pinMode(BUTTON_GY33, INPUT_PULLUP);
|
||||||
for (int i=0; i<256; i++) {
|
|
||||||
float x = i;
|
|
||||||
x /= 255;
|
|
||||||
x = pow(x, 2.5);
|
|
||||||
x *= 255;
|
|
||||||
gammatable[i] = x;
|
|
||||||
}
|
|
||||||
if (tcs.begin()) {
|
if (tcs.begin()) {
|
||||||
DBG_OUTPUT_PORT.println("Found GY-33 sensor");
|
DBG_OUTPUT_PORT.println("Found GY-33 sensor");
|
||||||
} else {
|
} else {
|
||||||
@@ -468,24 +440,24 @@ DBG_OUTPUT_PORT.println("Starting....");
|
|||||||
// Configure MQTT
|
// Configure MQTT
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
if (mqtt_host != "" && String(mqtt_port).toInt() > 0) {
|
if (mqtt_host != "" && atoi(mqtt_port) > 0) {
|
||||||
snprintf(mqtt_intopic, sizeof mqtt_intopic, "%s/in", HOSTNAME);
|
snprintf(mqtt_intopic, sizeof mqtt_intopic, "%s/in", HOSTNAME);
|
||||||
snprintf(mqtt_outtopic, sizeof mqtt_outtopic, "%s/out", HOSTNAME);
|
snprintf(mqtt_outtopic, sizeof mqtt_outtopic, "%s/out", HOSTNAME);
|
||||||
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\n", mqtt_host, String(mqtt_port).toInt());
|
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\n", mqtt_host, String(mqtt_port).toInt());
|
||||||
|
|
||||||
mqtt_client.setServer(mqtt_host, String(mqtt_port).toInt());
|
mqtt_client.setServer(mqtt_host, atoi(mqtt_port));
|
||||||
mqtt_client.setCallback(mqtt_callback);
|
mqtt_client.setCallback(mqtt_callback);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_AMQTT
|
#ifdef ENABLE_AMQTT
|
||||||
if (mqtt_host != "" && String(mqtt_port).toInt() > 0) {
|
if (mqtt_host != "" && atoi(mqtt_port) > 0) {
|
||||||
amqttClient.onConnect(onMqttConnect);
|
amqttClient.onConnect(onMqttConnect);
|
||||||
amqttClient.onDisconnect(onMqttDisconnect);
|
amqttClient.onDisconnect(onMqttDisconnect);
|
||||||
amqttClient.onMessage(onMqttMessage);
|
amqttClient.onMessage(onMqttMessage);
|
||||||
amqttClient.setServer(mqtt_host, String(mqtt_port).toInt());
|
amqttClient.setServer(mqtt_host, atoi(mqtt_port));
|
||||||
amqttClient.setCredentials(mqtt_user, mqtt_pass);
|
if (mqtt_user != "" or mqtt_pass != "") amqttClient.setCredentials(mqtt_user, mqtt_pass);
|
||||||
amqttClient.setClientId(mqtt_clientid);
|
amqttClient.setClientId(mqtt_clientid);
|
||||||
|
|
||||||
connectToMqtt();
|
connectToMqtt();
|
||||||
@@ -582,6 +554,13 @@ DBG_OUTPUT_PORT.println("Starting....");
|
|||||||
wifiManager.startConfigPortal(HOSTNAME);
|
wifiManager.startConfigPortal(HOSTNAME);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.on("/format_spiffs", []() {
|
||||||
|
DBG_OUTPUT_PORT.printf("/format_spiffs\n");
|
||||||
|
server.send(200, "text/plain", "Formatting SPIFFS ..." );
|
||||||
|
SPIFFS.format();
|
||||||
|
server.send(200, "text/plain", "Formatting SPIFFS complete" );
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Setup: SPIFFS Webserver handler
|
// Setup: SPIFFS Webserver handler
|
||||||
@@ -660,7 +639,7 @@ DBG_OUTPUT_PORT.println("Starting....");
|
|||||||
exit_func = true;
|
exit_func = true;
|
||||||
#endif
|
#endif
|
||||||
mode = OFF;
|
mode = OFF;
|
||||||
getArgs();
|
//getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
||||||
@@ -883,7 +862,9 @@ DBG_OUTPUT_PORT.println("Starting....");
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON_GY33
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
tcs.setConfig(MCU_LED_05, MCU_WHITE_ON);
|
tcs.setConfig(MCU_LED_06, MCU_WHITE_ON);
|
||||||
|
// delay(2000);
|
||||||
|
// tcs.setConfig(MCU_LED_OFF, MCU_WHITE_OFF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -959,7 +940,6 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||||
if (mode == WIPE) {
|
if (mode == WIPE) {
|
||||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
|
||||||
strip.setMode(FX_MODE_COLOR_WIPE);
|
strip.setMode(FX_MODE_COLOR_WIPE);
|
||||||
mode = HOLD;
|
mode = HOLD;
|
||||||
}
|
}
|
||||||
@@ -972,12 +952,10 @@ void loop() {
|
|||||||
mode = HOLD;
|
mode = HOLD;
|
||||||
}
|
}
|
||||||
if (mode == THEATERCHASE) {
|
if (mode == THEATERCHASE) {
|
||||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
|
||||||
strip.setMode(FX_MODE_THEATER_CHASE);
|
strip.setMode(FX_MODE_THEATER_CHASE);
|
||||||
mode = HOLD;
|
mode = HOLD;
|
||||||
}
|
}
|
||||||
if (mode == TWINKLERANDOM) {
|
if (mode == TWINKLERANDOM) {
|
||||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
|
||||||
strip.setMode(FX_MODE_TWINKLE_RANDOM);
|
strip.setMode(FX_MODE_TWINKLE_RANDOM);
|
||||||
mode = HOLD;
|
mode = HOLD;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#define NUMLEDS 194 // Number of leds in the strip
|
#define NUMLEDS 194 // Number of leds in the strip
|
||||||
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
||||||
#define BUTTON 14 // Input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
#define BUTTON 14 // Input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||||
#define BUTTON_GY33 12 // Input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
//#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
|
#define RGBW // If defined, use RGBW Strips
|
||||||
|
|
||||||
const char HOSTNAME[] = "McLightingRGBW01"; // Friedly hostname
|
const char HOSTNAME[] = "McLightingRGBW01"; // Friedly hostname
|
||||||
|
|
||||||
@@ -17,11 +17,13 @@ const char HOSTNAME[] = "McLightingRGBW01"; // Friedly hostname
|
|||||||
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
||||||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
#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 ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||||
//#define ENABLE_BUTTON_GY33 //
|
//#define ENABLE_BUTTON_GY33 // If defined, enable button handling code for GY-33 color sensor to scan color
|
||||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||||
#define ENABLE_LEGACY_ANIMATIONS
|
#define ENABLE_LEGACY_ANIMATIONS
|
||||||
#define ENABLE_STATE_SAVE_SPIFFS // If defined, saves state on SPIFFS
|
#define ENABLE_STATE_SAVE_SPIFFS // If defined, saves state on SPIFFS
|
||||||
//#define ENABLE_STATE_SAVE_EEPROM // If defined, save state on reboot
|
//#define ENABLE_STATE_SAVE_EEPROM // If defined, save state on reboot
|
||||||
|
#define ENABLE_MQTT_HOSTNAME_CHIPID // Uncomment/comment to add ESPChipID to end of MQTT hostname
|
||||||
|
#define DBG_OUTPUT_PORT Serial // Set debug output port
|
||||||
|
|
||||||
#if defined(USE_NEOANIMATIONFX) and defined(USE_WS2812FX)
|
#if defined(USE_NEOANIMATIONFX) and defined(USE_WS2812FX)
|
||||||
#error "Cant have both NeoAnimationFX and WS2812FX enabled. Choose either one."
|
#error "Cant have both NeoAnimationFX and WS2812FX enabled. Choose either one."
|
||||||
@@ -75,7 +77,11 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||||||
uint16_t color_temp = 327; // min is 154 and max is 500
|
uint16_t color_temp = 327; // min is 154 and max is 500
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char mqtt_clientid[] = "NeoPixelsStrip"; // MQTT ClientID
|
#ifdef ENABLE_MQTT_HOSTNAME_CHIPID
|
||||||
|
const char* mqtt_clientid = String(String(HOSTNAME) + "-" + String(ESP.getChipId())).c_str(); // MQTT ClientID
|
||||||
|
#else
|
||||||
|
const char* mqtt_clientid = HOSTNAME; // MQTT ClientID
|
||||||
|
#endif
|
||||||
|
|
||||||
char mqtt_host[64] = "";
|
char mqtt_host[64] = "";
|
||||||
char mqtt_port[6] = "";
|
char mqtt_port[6] = "";
|
||||||
@@ -87,7 +93,6 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Global variables / definitions
|
// Global variables / definitions
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#define DBG_OUTPUT_PORT Serial // Set debug output port
|
|
||||||
|
|
||||||
// List of all color modes
|
// List of all color modes
|
||||||
#ifdef ENABLE_LEGACY_ANIMATIONS
|
#ifdef ENABLE_LEGACY_ANIMATIONS
|
||||||
@@ -158,4 +163,3 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
|||||||
byte KeyPressCount_gy33 = 0;
|
byte KeyPressCount_gy33 = 0;
|
||||||
byte prevKeyState_gy33 = HIGH; // button is active low
|
byte prevKeyState_gy33 = HIGH; // button is active low
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,17 @@ void getArgs() {
|
|||||||
main_color.green = server.arg("g").toInt();
|
main_color.green = server.arg("g").toInt();
|
||||||
main_color.blue = server.arg("b").toInt();
|
main_color.blue = server.arg("b").toInt();
|
||||||
}
|
}
|
||||||
|
if (server.arg("s") != "") {
|
||||||
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||||
if (server.arg("s") == "") {
|
|
||||||
ws2812fx_speed = 196;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.arg("m") != "") {
|
if (server.arg("m") != "") {
|
||||||
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1);
|
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.arg("c").toInt() > 0) {
|
if (server.arg("c") != "") {
|
||||||
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
||||||
} else if (server.arg("p").toInt() > 0) {
|
} else if (server.arg("p") != "") {
|
||||||
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +85,6 @@ void handleSetMainColor(uint8_t * mypayload) {
|
|||||||
main_color.red = ((rgb >> 16) & 0xFF);
|
main_color.red = ((rgb >> 16) & 0xFF);
|
||||||
main_color.green = ((rgb >> 8) & 0xFF);
|
main_color.green = ((rgb >> 8) & 0xFF);
|
||||||
main_color.blue = ((rgb ) & 0xFF);
|
main_color.blue = ((rgb ) & 0xFF);
|
||||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
|
||||||
mode = SETCOLOR;
|
mode = SETCOLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,6 +392,265 @@ void handleAutoStop() {
|
|||||||
strip.stop();
|
strip.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkpayload(uint8_t * payload, bool mqtt = false, uint8_t num = 0) {
|
||||||
|
// # ==> Set main color
|
||||||
|
if (payload[0] == '#') {
|
||||||
|
handleSetMainColor(payload);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set main color to: W: [%u] R: [%u] G: [%u] B: [%u]\n", main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||||
|
#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
|
||||||
|
stateOn = true;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ? ==> Set speed
|
||||||
|
if (payload[0] == '?') {
|
||||||
|
uint8_t d = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
||||||
|
ws2812fx_speed = constrain(d, 0, 255);
|
||||||
|
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set speed to: [%u]\n", ws2812fx_speed);
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||||
|
#endif
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
// % ==> Set brightness
|
||||||
|
if (payload[0] == '%') {
|
||||||
|
uint8_t b = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
||||||
|
brightness = constrain(b, 0, 255);
|
||||||
|
strip.setBrightness(brightness);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("WS: Set brightness to: [%u]\n", brightness);
|
||||||
|
#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
|
||||||
|
stateOn = true;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// * ==> Set main color and light all LEDs (Shortcut)
|
||||||
|
if (payload[0] == '*') {
|
||||||
|
handleSetAllMode(payload);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set main color and light all LEDs [%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
|
||||||
|
stateOn = true;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! ==> Set single LED in given color
|
||||||
|
if (payload[0] == '!') {
|
||||||
|
handleSetSingleLED(payload, 1);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set single LED in given color [%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
|
||||||
|
}
|
||||||
|
|
||||||
|
// + ==> Set multiple LED in the given colors
|
||||||
|
if (payload[0] == '+') {
|
||||||
|
handleSetDifferentColors(payload);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set multiple LEDs in given color [%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
|
||||||
|
}
|
||||||
|
|
||||||
|
// + ==> Set range of LEDs in the given color
|
||||||
|
if (payload[0] == 'R') {
|
||||||
|
handleRangeDifferentColors(payload);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set range of LEDs in given color [%s]\n", payload);
|
||||||
|
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_LEGACY_ANIMATIONS
|
||||||
|
// = ==> Activate named mode
|
||||||
|
if (payload[0] == '=') {
|
||||||
|
// we get mode data
|
||||||
|
String str_mode = String((char *) &payload[0]);
|
||||||
|
|
||||||
|
handleSetNamedMode(str_mode);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Activated mode [%u]!\n", mode);
|
||||||
|
#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] == '$') {
|
||||||
|
String json = listStatusJSON();
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.println("Get status info: " + json);
|
||||||
|
webSocket.sendTXT(num, json);
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, listStatusJSON());
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_AMQTT
|
||||||
|
String liststat = (String) listStatusJSON();
|
||||||
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, liststat.c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~ ==> Get WS2812 modes.
|
||||||
|
if (payload[0] == '~') {
|
||||||
|
String json = listModesJSON();
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.println("Get WS2812 modes.");
|
||||||
|
DBG_OUTPUT_PORT.println(json);
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
DBG_OUTPUT_PORT.printf("Error: Not implemented. Message too large for pubsubclient.");
|
||||||
|
mqtt_client.publish(mqtt_outtopic, "ERROR: Not implemented. Message too large for pubsubclient.");
|
||||||
|
//String json_modes = listModesJSON();
|
||||||
|
//DBG_OUTPUT_PORT.printf(json_modes.c_str());
|
||||||
|
|
||||||
|
//int res = mqtt_client.publish(mqtt_outtopic, json_modes.c_str(), json_modes.length());
|
||||||
|
//DBG_OUTPUT_PORT.printf("Result: %d / %d", res, json_modes.length());
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_AMQTT
|
||||||
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("ERROR: Not implemented. Message too large for AsyncMQTT.").c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// / ==> Set WS2812 mode.
|
||||||
|
// TODO: Fix this, doesn't return anything. Too long?
|
||||||
|
// Hint: https://github.com/knolleary/pubsubclient/issues/110
|
||||||
|
if (payload[0] == '/') {
|
||||||
|
handleSetWS2812FXMode(payload);
|
||||||
|
if (mqtt == true) {
|
||||||
|
DBG_OUTPUT_PORT.print("MQTT: ");
|
||||||
|
} else {
|
||||||
|
DBG_OUTPUT_PORT.print("WS: ");
|
||||||
|
webSocket.sendTXT(num, "OK");
|
||||||
|
}
|
||||||
|
DBG_OUTPUT_PORT.printf("Set WS2812 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
|
||||||
|
stateOn = true;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// WS request handlers
|
// WS request handlers
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
@@ -415,201 +672,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
case WStype_TEXT:
|
case WStype_TEXT:
|
||||||
DBG_OUTPUT_PORT.printf("WS: [%u] get Text: %s\n", num, payload);
|
DBG_OUTPUT_PORT.printf("WS: [%u] get Text: %s\n", num, payload);
|
||||||
|
|
||||||
// # ==> Set main color
|
checkpayload(payload, false, num);
|
||||||
if (payload[0] == '#') {
|
|
||||||
handleSetMainColor(payload);
|
|
||||||
DBG_OUTPUT_PORT.printf("Set main color to: R: [%u] G: [%u] B: [%u] W: [%u]\n", main_color.red, main_color.green, main_color.blue, main_color.white);
|
|
||||||
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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// ? ==> Set speed
|
|
||||||
if (payload[0] == '?') {
|
|
||||||
uint8_t d = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
|
||||||
ws2812fx_speed = constrain(d, 0, 255);
|
|
||||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
|
||||||
DBG_OUTPUT_PORT.printf("WS: Set speed to: [%u]\n", ws2812fx_speed);
|
|
||||||
webSocket.sendTXT(num, "OK");
|
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
|
||||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
|
||||||
#endif
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
|
|
||||||
// % ==> Set brightness
|
|
||||||
if (payload[0] == '%') {
|
|
||||||
uint8_t b = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
|
||||||
brightness = ((b >> 0) & 0xFF);
|
|
||||||
DBG_OUTPUT_PORT.printf("WS: Set brightness to: [%u]\n", brightness);
|
|
||||||
strip.setBrightness(brightness);
|
|
||||||
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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// * ==> Set main color and light all LEDs (Shortcut)
|
|
||||||
if (payload[0] == '*') {
|
|
||||||
handleSetAllMode(payload);
|
|
||||||
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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! ==> Set single LED in given color
|
|
||||||
if (payload[0] == '!') {
|
|
||||||
handleSetSingleLED(payload, 1);
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// + ==> Set multiple LED in the given colors
|
|
||||||
if (payload[0] == '+') {
|
|
||||||
handleSetDifferentColors(payload);
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// + ==> Set range of LEDs in the given color
|
|
||||||
if (payload[0] == 'R') {
|
|
||||||
handleRangeDifferentColors(payload);
|
|
||||||
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_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] == '$') {
|
|
||||||
DBG_OUTPUT_PORT.printf("Get status info.");
|
|
||||||
|
|
||||||
String json = listStatusJSON();
|
|
||||||
DBG_OUTPUT_PORT.println(json);
|
|
||||||
webSocket.sendTXT(num, json);
|
|
||||||
#ifdef ENABLE_MQTT
|
|
||||||
mqtt_client.publish(mqtt_outtopic, listStatusJSON());
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_AMQTT
|
|
||||||
String liststat = (String) listStatusJSON();
|
|
||||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, liststat.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~ ==> Get WS2812 modes.
|
|
||||||
if (payload[0] == '~') {
|
|
||||||
DBG_OUTPUT_PORT.printf("Get WS2812 modes.");
|
|
||||||
|
|
||||||
String json = listModesJSON();
|
|
||||||
DBG_OUTPUT_PORT.println(json);
|
|
||||||
webSocket.sendTXT(num, json);
|
|
||||||
#ifdef ENABLE_MQTT
|
|
||||||
DBG_OUTPUT_PORT.printf("Error: Not implemented. Message too large for pubsubclient.");
|
|
||||||
mqtt_client.publish(mqtt_outtopic, "ERROR: Not implemented. Message too large for pubsubclient.");
|
|
||||||
//String json_modes = listModesJSON();
|
|
||||||
//DBG_OUTPUT_PORT.printf(json_modes.c_str());
|
|
||||||
|
|
||||||
//int res = mqtt_client.publish(mqtt_outtopic, json_modes.c_str(), json_modes.length());
|
|
||||||
//DBG_OUTPUT_PORT.printf("Result: %d / %d", res, json_modes.length());
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_AMQTT
|
|
||||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("ERROR: Not implemented. Message too large for AsyncMQTT.").c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// / ==> Set WS2812 mode.
|
|
||||||
if (payload[0] == '/') {
|
|
||||||
handleSetWS2812FXMode(payload);
|
|
||||||
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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// start auto cycling
|
// start auto cycling
|
||||||
if (strcmp((char *)payload, "start") == 0 ) {
|
if (strcmp((char *)payload, "start") == 0 ) {
|
||||||
@@ -848,188 +911,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// # ==> Set main color
|
checkpayload(payload, true);
|
||||||
if (payload[0] == '#') {
|
|
||||||
handleSetMainColor(payload);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set main color to [%u] [%u] [%u]\n", main_color.red, main_color.green, main_color.blue);
|
|
||||||
#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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// ? ==> Set speed
|
|
||||||
if (payload[0] == '?') {
|
|
||||||
uint8_t d = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
|
||||||
ws2812fx_speed = constrain(d, 0, 255);
|
|
||||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set speed to [%u]\n", ws2812fx_speed);
|
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
|
||||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
|
||||||
#endif
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
|
|
||||||
// % ==> Set brightness
|
|
||||||
if (payload[0] == '%') {
|
|
||||||
uint8_t b = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
|
||||||
brightness = constrain(b, 0, 255);
|
|
||||||
strip.setBrightness(brightness);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set brightness to [%u]\n", brightness);
|
|
||||||
#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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// * ==> Set main color and light all LEDs (Shortcut)
|
|
||||||
if (payload[0] == '*') {
|
|
||||||
handleSetAllMode(payload);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set main color and light all LEDs [%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
|
|
||||||
stateOn = true;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! ==> Set single LED in given color
|
|
||||||
if (payload[0] == '!') {
|
|
||||||
handleSetSingleLED(payload, 1);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set single LED in given color [%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
|
|
||||||
}
|
|
||||||
|
|
||||||
// + ==> Set multiple LED in the given colors
|
|
||||||
if (payload[0] == '+') {
|
|
||||||
handleSetDifferentColors(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
|
|
||||||
}
|
|
||||||
|
|
||||||
// R ==> Set range of LEDs in the given colors
|
|
||||||
if (payload[0] == 'R') {
|
|
||||||
handleRangeDifferentColors(payload);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set range of LEDS to single color: [%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_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] == '$') {
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Get status info.\n");
|
|
||||||
DBG_OUTPUT_PORT.println("MQTT: Out: " + String(listStatusJSON()));
|
|
||||||
#ifdef ENABLE_MQTT
|
|
||||||
mqtt_client.publish(mqtt_outtopic, listStatusJSON());
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_AMQTT
|
|
||||||
String liststat = (String) listStatusJSON();
|
|
||||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, liststat.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~ ==> Get WS2812 modes.
|
|
||||||
// TODO: Fix this, doesn't return anything. Too long?
|
|
||||||
// Hint: https://github.com/knolleary/pubsubclient/issues/110
|
|
||||||
if (payload[0] == '~') {
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Get WS2812 modes.\n");
|
|
||||||
#ifdef ENABLE_MQTT
|
|
||||||
DBG_OUTPUT_PORT.printf("Error: Not implemented. Message too large for pubsubclient.");
|
|
||||||
mqtt_client.publish(mqtt_outtopic, "ERROR: Not implemented. Message too large for pubsubclient.");
|
|
||||||
//String json_modes = listModesJSON();
|
|
||||||
//DBG_OUTPUT_PORT.printf(json_modes.c_str());
|
|
||||||
|
|
||||||
//int res = mqtt_client.publish(mqtt_outtopic, json_modes.c_str(), json_modes.length());
|
|
||||||
//DBG_OUTPUT_PORT.printf("Result: %d / %d", res, json_modes.length());
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_AMQTT
|
|
||||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("ERROR: Not implemented. Message too large for AsyncMQTT.").c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// / ==> Set WS2812 mode.
|
|
||||||
if (payload[0] == '/') {
|
|
||||||
handleSetWS2812FXMode(payload);
|
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Set WS2812 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
|
|
||||||
stateOn = true;
|
|
||||||
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_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
}
|
}
|
||||||
@@ -1200,6 +1082,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =static white").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =static white").c_str());
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENABLE_AMQTT
|
||||||
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =static white").c_str());
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
|
stateOn = true;
|
||||||
|
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
|
||||||
} else {
|
} else {
|
||||||
mode = OFF;
|
mode = OFF;
|
||||||
buttonState = false;
|
buttonState = false;
|
||||||
@@ -1291,48 +1183,36 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
#ifdef ENABLE_BUTTON_GY33
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
void shortKeyPress_gy33() {
|
void shortKeyPress_gy33() {
|
||||||
DBG_OUTPUT_PORT.printf("Short GY-33 button press\n");
|
DBG_OUTPUT_PORT.printf("Short GY-33 button press\n");
|
||||||
if (buttonState == false) {
|
// tcs.setConfig(MCU_LED_04, MCU_WHITE_OFF);
|
||||||
|
// delay(500);
|
||||||
uint16_t red, green, blue, cl, ct, lux;
|
uint16_t red, green, blue, cl, ct, lux;
|
||||||
tcs.getRawData(&red, &green, &blue, &cl, &lux, &ct);
|
tcs.getRawData(&red, &green, &blue, &cl, &lux, &ct);
|
||||||
DBG_OUTPUT_PORT.printf("Raw Colors: R: [%d] G: [%d] B: [%d] Clear: [%d] Lux: [%d] Colortemp: [%d]\n", (int)red, (int)green, (int)blue, (int)cl, (int)lux, (int)ct);
|
DBG_OUTPUT_PORT.printf("Raw Colors: R: [%d] G: [%d] B: [%d] Clear: [%d] Lux: [%d] Colortemp: [%d]\n", (int)red, (int)green, (int)blue, (int)cl, (int)lux, (int)ct);
|
||||||
uint8_t r, g, b, col, conf;
|
uint8_t r, g, b, col, conf;
|
||||||
tcs.getData(&r, &g, &b, &col, &conf);
|
tcs.getData(&r, &g, &b, &col, &conf);
|
||||||
DBG_OUTPUT_PORT.printf("Colors: R: [%d] G: [%d] B: [%d] Color: [%d] Conf: [%d]\n", (int)r, (int)g, (int)b, (int)col, (int)conf);
|
DBG_OUTPUT_PORT.printf("Colors: R: [%d] G: [%d] B: [%d] Color: [%d] Conf: [%d]\n", (int)r, (int)g, (int)b, (int)col, (int)conf);
|
||||||
char newmode[38];
|
main_color.white = 0; main_color.red = (pow((r/255.0), 2.5)*255); main_color.green = (pow((g/255.0), 2.5)*255); main_color.blue = (pow((b/255.0), 2.5)*255);
|
||||||
sprintf(newmode, "STA| 1| 0|245|196|0|%3d|%3d|%3d", (int)r, (int)g, (int)b);
|
ws2812fx_mode = 0;
|
||||||
DBG_OUTPUT_PORT.println(newmode);
|
mode = SET_MODE;
|
||||||
// setModeByStateString(newmode);
|
buttonState = true;
|
||||||
main_color.white = 0; main_color.red = gammatable[(int)r]; main_color.green = gammatable[(int)g]; main_color.blue = gammatable[(int)b];
|
|
||||||
mode = HOLD;
|
|
||||||
strip.setMode(0);
|
|
||||||
//strip.setBrightness(196);
|
|
||||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
|
||||||
buttonState = false;
|
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =static GY-33").c_str());
|
mqtt_client.publish(mqtt_outtopic, String("OK =static GY-33").c_str());
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
mode = OFF;
|
|
||||||
buttonState = false;
|
|
||||||
#ifdef ENABLE_MQTT
|
|
||||||
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_AMQTT
|
#ifdef ENABLE_AMQTT
|
||||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =off").c_str());
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =static GY-33").c_str());
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_HOMEASSISTANT
|
#ifdef ENABLE_HOMEASSISTANT
|
||||||
stateOn = false;
|
|
||||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||||
#endif
|
#endif
|
||||||
}
|
// tcs.setConfig(MCU_LED_OFF, MCU_WHITE_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when button is kept pressed for less than 2 seconds
|
// called when button is kept pressed for less than 2 seconds
|
||||||
void mediumKeyPress_gy33() {
|
void mediumKeyPress_gy33() {
|
||||||
tcs.setConfig(MCU_LED_02, MCU_WHITE_OFF);
|
tcs.setConfig(MCU_LED_07, MCU_WHITE_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when button is kept pressed for 2 seconds or more
|
// called when button is kept pressed for 2 seconds or more
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ There are some informations in the [Wiki](https://github.com/toblum/McLighting/w
|
|||||||
|
|
||||||
Update 17.02.2018:
|
Update 17.02.2018:
|
||||||
User @debsahu contributed code for integration with homeassistant. It's currently in a separate branch (https://github.com/toblum/McLighting/tree/feature/ha_integration). If you're using Homeassistant, please try it out and give feedback.
|
User @debsahu contributed code for integration with homeassistant. It's currently in a separate branch (https://github.com/toblum/McLighting/tree/feature/ha_integration). If you're using Homeassistant, please try it out and give feedback.
|
||||||
User @FabLab-Luenn created a version of McLighting (https://github.com/FabLab-Luenen/McLighting) for 6812 and other RGBW strips. Give it a try, if you own such strips.
|
User @FabLab-Luenen created a version of McLighting (https://github.com/FabLab-Luenen/McLighting) for 6812 and other RGBW strips. Give it a try, if you own such strips.
|
||||||
A thank you goes to all contributors.
|
A thank you goes to all contributors.
|
||||||
|
|
||||||
Update 12. / 15.02.2018:
|
Update 12. / 15.02.2018:
|
||||||
@@ -151,6 +151,7 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so
|
|||||||
- [x] Make a set of NodeRed nodes.
|
- [x] Make a set of NodeRed nodes.
|
||||||
- [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119)
|
- [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119)
|
||||||
- [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111)
|
- [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111)
|
||||||
|
- [ ] Display version and parameters (Number of LEDs, definition settings, ..) in the web UI [Issue](https://github.com/toblum/McLighting/issues/150)
|
||||||
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ $(function(){
|
|||||||
console.log("modes", data);
|
console.log("modes", data);
|
||||||
var modes_html = "";
|
var modes_html = "";
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 3) {
|
if (mode == "3") {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
|
||||||
} else {
|
} else {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
|
||||||
@@ -224,7 +224,7 @@ $(function(){
|
|||||||
modes_html += '</a>';
|
modes_html += '</a>';
|
||||||
modes_html += '</div>'
|
modes_html += '</div>'
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 4) {
|
if (mode == "4") {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
|
||||||
} else {
|
} else {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
|
||||||
@@ -239,7 +239,7 @@ $(function(){
|
|||||||
data.forEach(function(current_mode){
|
data.forEach(function(current_mode){
|
||||||
if (current_mode.mode !== undefined) {
|
if (current_mode.mode !== undefined) {
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 1 && current_mode.mode == ws2812fx_mode) {
|
if (mode == "1" && current_mode.mode == ws2812fx_mode) {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
|
modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ $(function(){
|
|||||||
console.log("modes", data);
|
console.log("modes", data);
|
||||||
var modes_html = "";
|
var modes_html = "";
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 2) {
|
if (mode == "3") {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="off">OFF';
|
||||||
} else {
|
} else {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="off">OFF';
|
||||||
@@ -70,7 +70,7 @@ $(function(){
|
|||||||
modes_html += '</a>';
|
modes_html += '</a>';
|
||||||
modes_html += '</div>'
|
modes_html += '</div>'
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 10) {
|
if (mode == "4") {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static red" name="action" data-mode="tv">TV';
|
||||||
} else {
|
} else {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
|
modes_html += '<a class="btn waves-effect waves-light btn_mode_static blue" name="action" data-mode="tv">TV';
|
||||||
@@ -85,7 +85,7 @@ $(function(){
|
|||||||
data.forEach(function(current_mode){
|
data.forEach(function(current_mode){
|
||||||
if (current_mode.mode !== undefined) {
|
if (current_mode.mode !== undefined) {
|
||||||
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
modes_html += '<div class="col s12 m6 l6 btn_grid">';
|
||||||
if (mode == 1 && current_mode.mode == ws2812fx_mode) {
|
if (mode == "1" && current_mode.mode == ws2812fx_mode) {
|
||||||
modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
|
modes_html += '<a class="btn waves-effect waves-light btn_mode red" name="action" data-mode="' + current_mode.mode + '">(' + current_mode.mode +') '+ current_mode.name;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user