Simplifying Code
This commit is contained in:
@@ -372,7 +372,7 @@ void initMqtt() {
|
|||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 0
|
||||||
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
||||||
mqtt_client->setServer(mqtt_host, mqtt_port);
|
mqtt_client->setServer(mqtt_host, mqtt_port);
|
||||||
mqtt_client->setCallback(mqtt_callback);
|
mqtt_client->setCallback(onMqttMessage);
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 1
|
||||||
DBG_OUTPUT_PORT.printf("AMQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
DBG_OUTPUT_PORT.printf("AMQTT active: %s:%d\r\n", mqtt_host, mqtt_port);
|
||||||
@@ -451,11 +451,12 @@ void setup() {
|
|||||||
//Strip Config
|
//Strip Config
|
||||||
#if ENABLE_STATE_SAVE == 1
|
#if ENABLE_STATE_SAVE == 1
|
||||||
(readConfigFS()) ? DBG_OUTPUT_PORT.println("WiFiManager config FS read success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Read failure!");
|
(readConfigFS()) ? DBG_OUTPUT_PORT.println("WiFiManager config FS read success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Read failure!");
|
||||||
delay(500);
|
delay(250);
|
||||||
(readStateFS()) ? DBG_OUTPUT_PORT.println("Strip state config FS read Success!") : DBG_OUTPUT_PORT.println("Strip state config FS read failure!");
|
(readStateFS()) ? DBG_OUTPUT_PORT.println("Strip state config FS read Success!") : DBG_OUTPUT_PORT.println("Strip state config FS read failure!");
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_STATE_SAVE == 0
|
#if ENABLE_STATE_SAVE == 0
|
||||||
(setConfByConfString(readEEPROM(0, 222)))? DBG_OUTPUT_PORT.println("WiFiManager config EEPROM read success!"): DBG_OUTPUT_PORT.println("WiFiManager config EEPROM Read failure!");
|
(setConfByConfString(readEEPROM(0, 222)))? DBG_OUTPUT_PORT.println("WiFiManager config EEPROM read success!"): DBG_OUTPUT_PORT.println("WiFiManager config EEPROM Read failure!");
|
||||||
|
delay(250);
|
||||||
(setModeByStateString(readEEPROM(256, 66)))? DBG_OUTPUT_PORT.println("Strip state config EEPROM read Success!") : DBG_OUTPUT_PORT.println("Strip state config EEPROM read failure!");
|
(setModeByStateString(readEEPROM(256, 66)))? DBG_OUTPUT_PORT.println("Strip state config EEPROM read Success!") : DBG_OUTPUT_PORT.println("Strip state config EEPROM read failure!");
|
||||||
#endif
|
#endif
|
||||||
char tmp_strip_size[6], tmp_fxoptions[5], tmp_rgbOrder[5]; //needed tempararily for WiFiManager Settings
|
char tmp_strip_size[6], tmp_fxoptions[5], tmp_rgbOrder[5]; //needed tempararily for WiFiManager Settings
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ void convertColors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getArgs() {
|
void getArgs() {
|
||||||
|
|
||||||
|
if (mode == SET_ALL || mode == SET_MODE || mode == SET_COLOR) {
|
||||||
if (server.arg("rgb") != "") {
|
if (server.arg("rgb") != "") {
|
||||||
uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16);
|
uint32_t rgb = (uint32_t) strtoul(server.arg("rgb").c_str(), NULL, 16);
|
||||||
main_color.white = ((rgb >> 24) & 0xFF);
|
main_color.white = ((rgb >> 24) & 0xFF);
|
||||||
@@ -86,7 +88,7 @@ void getArgs() {
|
|||||||
back_color.blue = ((rgb2 >> 0) & 0xFF);
|
back_color.blue = ((rgb2 >> 0) & 0xFF);
|
||||||
} else {
|
} else {
|
||||||
if ((server.arg("r2") != "") && (server.arg("r2").toInt() >= 0) && (server.arg("r2").toInt() <= 255)) {
|
if ((server.arg("r2") != "") && (server.arg("r2").toInt() >= 0) && (server.arg("r2").toInt() <= 255)) {
|
||||||
back_color.red = constrain(server.arg("r2").toInt(), 0, 255);
|
back_color.red = server.arg("r2").toInt();
|
||||||
}
|
}
|
||||||
if ((server.arg("g2") != "") && (server.arg("g2").toInt() >= 0) && (server.arg("g2").toInt() <= 255)) {
|
if ((server.arg("g2") != "") && (server.arg("g2").toInt() >= 0) && (server.arg("g2").toInt() <= 255)) {
|
||||||
back_color.green = server.arg("g2").toInt();
|
back_color.green = server.arg("g2").toInt();
|
||||||
@@ -118,20 +120,6 @@ void getArgs() {
|
|||||||
xtra_color.white = server.arg("w3").toInt();
|
xtra_color.white = server.arg("w3").toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((server.arg("s") != "") && (server.arg("s").toInt() >= 0) && (server.arg("s").toInt() <= 255)) {
|
|
||||||
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((server.arg("m") != "") && (server.arg("m").toInt() >= 0) && (server.arg("m").toInt() <= strip->getModeCount())) {
|
|
||||||
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((server.arg("c") != "") && (server.arg("c").toInt() >= 0) && (server.arg("c").toInt() <= 100)) {
|
|
||||||
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
|
||||||
} else if ((server.arg("p") != "") && (server.arg("p").toInt() >= 0) && (server.arg("p").toInt() <= 255)) {
|
|
||||||
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
main_color.red = constrain(main_color.red, 0, 255);
|
main_color.red = constrain(main_color.red, 0, 255);
|
||||||
main_color.green = constrain(main_color.green, 0, 255);
|
main_color.green = constrain(main_color.green, 0, 255);
|
||||||
main_color.blue = constrain(main_color.blue, 0, 255);
|
main_color.blue = constrain(main_color.blue, 0, 255);
|
||||||
@@ -145,10 +133,27 @@ void getArgs() {
|
|||||||
xtra_color.blue = constrain(xtra_color.blue, 0, 255);
|
xtra_color.blue = constrain(xtra_color.blue, 0, 255);
|
||||||
xtra_color.white = constrain(xtra_color.white, 0, 255);
|
xtra_color.white = constrain(xtra_color.white, 0, 255);
|
||||||
convertColors();
|
convertColors();
|
||||||
DBG_OUTPUT_PORT.print("Get Args: ");
|
}
|
||||||
DBG_OUTPUT_PORT.println(listStatusJSON());
|
if (mode == SET_ALL || mode == SET_MODE || mode == SET_SPEED || mode == TV) {
|
||||||
|
if ((server.arg("s") != "") && (server.arg("s").toInt() >= 0) && (server.arg("s").toInt() <= 255)) {
|
||||||
|
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mode == SET_ALL || mode == SET_MODE) {
|
||||||
|
if ((server.arg("m") != "") && (server.arg("m").toInt() >= 0) && (server.arg("m").toInt() <= strip->getModeCount())) {
|
||||||
|
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip->getModeCount() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mode == SET_ALL || mode == SET_MODE || mode == SET_BRIGHTNESS || mode == AUTO || mode == TV || mode == E131) {
|
||||||
|
if ((server.arg("c") != "") && (server.arg("c").toInt() >= 0) && (server.arg("c").toInt() <= 100)) {
|
||||||
|
brightness = constrain((int) server.arg("c").toInt() * 2.55, 0, 255);
|
||||||
|
} else if ((server.arg("p") != "") && (server.arg("p").toInt() >= 0) && (server.arg("p").toInt() <= 255)) {
|
||||||
|
brightness = constrain(server.arg("p").toInt(), 0, 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBG_OUTPUT_PORT.printf("Get Args: %s\r\n", listStatusJSON());
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t convertSpeed(uint8_t mcl_speed) {
|
uint16_t convertSpeed(uint8_t mcl_speed) {
|
||||||
//long ws2812_speed = mcl_speed * 256;
|
//long ws2812_speed = mcl_speed * 256;
|
||||||
@@ -1254,23 +1259,17 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_MQTT == 1
|
#if ENABLE_MQTT == 0
|
||||||
void onMqttMessage(char* topic, char* payload_in, AsyncMqttClientMessageProperties properties, size_t length, size_t index, size_t total) {
|
void onMqttMessage(char* topic, byte* payload_in, uint16_t length) {
|
||||||
DBG_OUTPUT_PORT.print("MQTT: Recieved ["); DBG_OUTPUT_PORT.print(topic);
|
|
||||||
// DBG_OUTPUT_PORT.print("]: "); DBG_OUTPUT_PORT.println(payload_in);
|
|
||||||
uint8_t * payload = (uint8_t *) malloc(length + 1);
|
|
||||||
memcpy(payload, payload_in, length);
|
|
||||||
payload[length] = 0;
|
|
||||||
DBG_OUTPUT_PORT.printf("]: %s\r\n", payload);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_MQTT == 0
|
#if ENABLE_MQTT == 1
|
||||||
void mqtt_callback(char* topic, byte* payload_in, uint16_t length) {
|
void onMqttMessage(char* topic, char* payload_in, AsyncMqttClientMessageProperties properties, size_t length, size_t index, size_t total) {
|
||||||
|
#endif
|
||||||
uint8_t * payload = (uint8_t *) malloc(length + 1);
|
uint8_t * payload = (uint8_t *) malloc(length + 1);
|
||||||
memcpy(payload, payload_in, length);
|
memcpy(payload, payload_in, length);
|
||||||
payload[length] = 0;
|
payload[length] = 0;
|
||||||
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\r\n", payload);
|
DBG_OUTPUT_PORT.printf("MQTT: Recieved [%s]: %s\r\n", topic, payload);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ENABLE_HOMEASSISTANT)
|
#if defined(ENABLE_HOMEASSISTANT)
|
||||||
if (strcmp(topic, mqtt_ha_state_in) == 0) {
|
if (strcmp(topic, mqtt_ha_state_in) == 0) {
|
||||||
|
|||||||
@@ -193,8 +193,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/set_brightness", []() {
|
server.on("/set_brightness", []() {
|
||||||
getArgs();
|
|
||||||
mode = SET_BRIGHTNESS;
|
mode = SET_BRIGHTNESS;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -207,8 +207,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/set_speed", []() {
|
server.on("/set_speed", []() {
|
||||||
getArgs();
|
|
||||||
mode = SET_SPEED;
|
mode = SET_SPEED;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -347,7 +347,6 @@
|
|||||||
updateStrip = false;
|
updateStrip = false;
|
||||||
updateConf = false;
|
updateConf = false;
|
||||||
getConfigJSON();
|
getConfigJSON();
|
||||||
delay(500);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/off", []() {
|
server.on("/off", []() {
|
||||||
@@ -357,56 +356,57 @@
|
|||||||
|
|
||||||
server.on("/auto", []() {
|
server.on("/auto", []() {
|
||||||
mode = AUTO;
|
mode = AUTO;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/all", []() {
|
server.on("/all", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_STATIC;
|
ws2812fx_mode = FX_MODE_STATIC;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
#if defined(ENABLE_LEGACY_ANIMATIONS)
|
#if defined(ENABLE_LEGACY_ANIMATIONS)
|
||||||
server.on("/wipe", []() {
|
server.on("/wipe", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_COLOR_WIPE;
|
ws2812fx_mode = FX_MODE_COLOR_WIPE;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/rainbow", []() {
|
server.on("/rainbow", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_RAINBOW;
|
ws2812fx_mode = FX_MODE_RAINBOW;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/rainbowcycle", []() {
|
server.on("/rainbowcycle", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_RAINBOW_CYCLE;
|
ws2812fx_mode = FX_MODE_RAINBOW_CYCLE;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/theaterchase", []() {
|
server.on("/theaterchase", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_THEATER_CHASE;
|
ws2812fx_mode = FX_MODE_THEATER_CHASE;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/twinklerandom", []() {
|
server.on("/twinklerandom", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_TWINKLE_RANDOM;
|
ws2812fx_mode = FX_MODE_TWINKLE_RANDOM;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/theaterchaserainbow", []() {
|
server.on("/theaterchaserainbow", []() {
|
||||||
getArgs();
|
|
||||||
ws2812fx_mode = FX_MODE_THEATER_CHASE_RAINBOW;
|
ws2812fx_mode = FX_MODE_THEATER_CHASE_RAINBOW;
|
||||||
mode = SET_ALL;
|
mode = SET_ALL;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@@ -414,6 +414,7 @@
|
|||||||
#if defined(ENABLE_E131)
|
#if defined(ENABLE_E131)
|
||||||
server.on("/e131", []() {
|
server.on("/e131", []() {
|
||||||
mode = E131;
|
mode = E131;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@@ -421,6 +422,7 @@
|
|||||||
#if defined(ENABLE_TV)
|
#if defined(ENABLE_TV)
|
||||||
server.on("/tv", []() {
|
server.on("/tv", []() {
|
||||||
mode = TV;
|
mode = TV;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@@ -430,7 +432,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/set_mode", []() {
|
server.on("/set_mode", []() {
|
||||||
getArgs();
|
|
||||||
mode = SET_MODE;
|
mode = SET_MODE;
|
||||||
|
getArgs();
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|||||||
+4
-3
@@ -35,8 +35,8 @@ arduino_core_2_5_0 = espressif8266@2.0.4
|
|||||||
arduino_core_stage = https://github.com/platformio/platform-espressif8266.git#feature/stage
|
arduino_core_stage = https://github.com/platformio/platform-espressif8266.git#feature/stage
|
||||||
|
|
||||||
framework = arduino
|
framework = arduino
|
||||||
platform = ${common.arduino_core_2_4_2}
|
;platform = ${common.arduino_core_2_4_2}
|
||||||
; platform = ${common.arduino_core_2_5_0}
|
platform = ${common.arduino_core_2_5_0}
|
||||||
build_flags =
|
build_flags =
|
||||||
-DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
|
-DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
|
||||||
-DMQTT_MAX_PACKET_SIZE=512 ; PubSubClient Specific flags
|
-DMQTT_MAX_PACKET_SIZE=512 ; PubSubClient Specific flags
|
||||||
@@ -74,9 +74,10 @@ lib_deps = ${common.lib_deps}
|
|||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
platform = ${common.platform}
|
platform = ${common.platform}
|
||||||
|
board_build.f_cpu = 160000000L
|
||||||
build_flags =
|
build_flags =
|
||||||
${common.build_flags}
|
${common.build_flags}
|
||||||
; -Wl,-Teagle.flash.4m3m.ld ;;;; Required for core > v2.5.0 or staging version
|
-Wl,-Teagle.flash.4m3m.ld ; Required for core > v2.5.0 or staging version
|
||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
upload_speed = ${common.upload_speed}
|
upload_speed = ${common.upload_speed}
|
||||||
upload_resetmethod = ${common.upload_resetmethod}
|
upload_resetmethod = ${common.upload_resetmethod}
|
||||||
|
|||||||
Reference in New Issue
Block a user