diff --git a/BaseHeader.h b/BaseHeader.h index 2d7b37f..4da7c52 100644 --- a/BaseHeader.h +++ b/BaseHeader.h @@ -12,7 +12,7 @@ typeof (Y) y_ = (Y); \ (x_ < y_) ? x_ : y_; })*/ -enum Mode { RAINBOW, STATIC_COLOR, AMBILIGHT, FIRE2012, OFF }; +enum Mode { OFF, AMBILIGHT, STATIC_COLOR, RAINBOW, FIRE2012 }; #endif diff --git a/ConfigStatic.h.example b/ConfigStatic.h.example index 8c576ac..fce43c6 100644 --- a/ConfigStatic.h.example +++ b/ConfigStatic.h.example @@ -9,9 +9,9 @@ /*------------------------------------------------*/ /*Logging level*/ -//#define LOGLEVEL LOG_LEVEL_INFOS +#define LOGLEVEL LOG_LEVEL_INFOS //#define LOGLEVEL LOG_LEVEL_DEBUG -#define LOGLEVEL LOG_LEVEL_VERBOSE +//#define LOGLEVEL LOG_LEVEL_VERBOSE /*------------------------------------------------*/ /*Main static configuration*/ @@ -26,6 +26,7 @@ #define CONFIG_LED_COLOR_ORDER RGB #define CONFIG_LED_COUNT 50 +//OFF, RAINBOW, FIRE2012 #define CONFIG_LED_STANDARD_MODE FIRE2012 /*------------------------------------------------*/ diff --git a/HyperionRGB.ino b/HyperionRGB.ino index f8dd363..55dc1dd 100644 --- a/HyperionRGB.ino +++ b/HyperionRGB.ino @@ -61,10 +61,10 @@ void animationStep() { } void changeMode(Mode newMode) { - activeMode = newMode; -} -void modeFallback(void) { - changeMode(RAINBOW); + if (newMode != activeMode) { + Log.info("Mode changed to %i", newMode); + activeMode = newMode; + } } void handleEvents(void) { @@ -109,7 +109,7 @@ void ledColorWipe(byte r, byte g, byte b) { changeMode(STATIC_COLOR); } void resetMode(void) { - Log.info("reset Mode"); + Log.info("Reset Mode"); changeMode(CONFIG_LED_STANDARD_MODE); resetThread.enabled = false; } @@ -182,6 +182,7 @@ void setup(void) { jsonServer.begin(); jsonServer.onLedColorWipe(ledColorWipe); jsonServer.onClearCmd(resetMode); + jsonServer.onEffectChange(changeMode); pinMode(LED, OUTPUT); // LED pin as output. Log.info("HEAP=%i", ESP.getFreeHeap()); diff --git a/WrapperFastLed.h b/WrapperFastLed.h index ab48017..e92262f 100644 --- a/WrapperFastLed.h +++ b/WrapperFastLed.h @@ -2,6 +2,11 @@ #define WrapperFastLed_h #include "BaseHeader.h" + +#define FASTLED_ESP8266_RAW_PIN_ORDER +//#define FASTLED_ESP8266_NODEMCU_PIN_ORDER +//#define FASTLED_ESP8266_D1_PIN_ORDER + #include class WrapperFastLed { diff --git a/WrapperJsonServer.cpp b/WrapperJsonServer.cpp index 57565f6..f7e2a93 100644 --- a/WrapperJsonServer.cpp +++ b/WrapperJsonServer.cpp @@ -48,8 +48,6 @@ void WrapperJsonServer::readData(void) { String command = root["command"].asString(); if (command.equals("serverinfo")) { Log.info("serverinfo"); - //_tcpClient.println("{\"success\":true}"); - //enum Mode { RAINBOW, STATIC_COLOR, AMBILIGHT, FIRE2012, OFF }; _tcpClient.println("{\"info\":{\"effects\":[" "{\"args\":{\"speed\":1.0},\"name\":\"Rainbow mood\",\"script\":\"rainbow\"}," "{\"args\":{\"speed\":1.0},\"name\":\"Fire2012\",\"script\":\"fire2012\"}" @@ -57,13 +55,18 @@ void WrapperJsonServer::readData(void) { } else if (command.equals("color")) { ledColorWipe(root["color"][0], root["color"][1], root["color"][2]); _tcpClient.println("{\"success\":true}"); - } else if (command.equals("clear")) { + } else if (command.equals("clear") || command.equals("clearall")) { clearCmd(); _tcpClient.println("{\"success\":true}"); } else if (command.equals("effect")) { - //{"command":"effect","effect":{"name":"Rainbow mood","args":{"speed":1}},"priority":50} String effect = root["effect"]["name"].asString(); int speed = root["effect"]["speed"]; + + if (effect.equals("Rainbow mood")) { + effectChange(RAINBOW); + } else if (effect.equals("Fire2012")) { + effectChange(FIRE2012); + } _tcpClient.println("{\"success\":true}"); } else { _tcpClient.println("{\"success\":false}"); @@ -91,3 +94,12 @@ void WrapperJsonServer::clearCmd(void) { } } +void WrapperJsonServer::onEffectChange(void(* function) (Mode)) { + effectChangePointer = function; +} +void WrapperJsonServer::effectChange(Mode effect) { + if (effectChangePointer) { + effectChangePointer(effect); + } +} + diff --git a/WrapperJsonServer.h b/WrapperJsonServer.h index ff984d2..184c995 100644 --- a/WrapperJsonServer.h +++ b/WrapperJsonServer.h @@ -19,8 +19,8 @@ class WrapperJsonServer { void onLedColorWipe(void(* function) (byte, byte, byte)), - onClearCmd(void(* function) (void)); -// onEffect(void(* function) (Mode)); + onClearCmd(void(* function) (void)), + onEffectChange(void(* function) (Mode)); private: void handleConnection(boolean newClient), @@ -33,8 +33,8 @@ class WrapperJsonServer { clearCmd(void), (* clearCmdPointer) (void); void - effect(Mode effect), - (* effectPointer) (Mode); + effectChange(Mode effect), + (* effectChangePointer) (Mode); WiFiServer _tcpServer; WiFiClient _tcpClient; diff --git a/WrapperWebconfig.h b/WrapperWebconfig.h index 5321732..fab9de5 100644 --- a/WrapperWebconfig.h +++ b/WrapperWebconfig.h @@ -3,7 +3,7 @@ #include "BaseHeader.h" #include -#include +#include "WrapperFastLed.h" #include class SelectEntryBase {