diff --git a/NeoPatterns.cpp b/NeoPatterns.cpp index 6a6ded8..0d92cf4 100644 --- a/NeoPatterns.cpp +++ b/NeoPatterns.cpp @@ -55,6 +55,9 @@ void NeoPatterns::Update() { break; case RANDOM: break; + case SHOWINPUT: + ShowInputUpdate(); + break; case NONE: break; default: @@ -545,6 +548,31 @@ void NeoPatterns::RadarUpdate() } + +/**** Input ****/ + +void NeoPatterns::ShowInput() { + if (ActivePattern != SHOWINPUT) { + clear(); + colorBox(currentinput, Color(255, 255, 255)); + show(); + } + ActivePattern = SHOWINPUT; +} + +void NeoPatterns::ShowInputUpdate() { + clear(); + colorBox(currentinput, Color(255, 255, 255)); + show(); +} + +// setCurrentInput +void NeoPatterns::setCurrentInput(uint8_t input) { + currentinput = input; +} + +/********/ + /****************** Helper functions ******************/ void NeoPatterns::SetColor1(uint32_t color) { diff --git a/NeoPatterns.h b/NeoPatterns.h index 16ba39f..64570cb 100644 --- a/NeoPatterns.h +++ b/NeoPatterns.h @@ -1,7 +1,7 @@ #include // Pattern types supported: -enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, RADAR, FILL, RANDOM }; +enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, RADAR, FILL, RANDOM, SHOWINPUT }; // Patern directions supported: enum direction { FORWARD, REVERSE }; @@ -36,6 +36,8 @@ class NeoPatterns : public Adafruit_NeoPixel void PlasmaUpdate(); void Radar(float radarspeed = 0.5,float radarthickness = 1, uint8_t interval = 50); void RadarUpdate(); + void ShowInput(); + void ShowInputUpdate(); void SetColor1(uint32_t color); void SetColor2(uint32_t color); @@ -121,6 +123,7 @@ class NeoPatterns : public Adafruit_NeoPixel uint8_t numToPos(int num); uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y); uint32_t parseColor(String value); + void setCurrentInput(uint8_t input); private: // Member Variables: @@ -171,7 +174,8 @@ class NeoPatterns : public Adafruit_NeoPixel float Radardotposition; uint8_t Radardotbrightness; uint8_t Radardotfadespeed; - + + uint8_t currentinput; uint32_t DimColor(uint32_t color); void Increment(); diff --git a/esp-videoswitcher.ino b/esp-videoswitcher.ino index 5cb4cc5..c56b0a9 100644 --- a/esp-videoswitcher.ino +++ b/esp-videoswitcher.ino @@ -18,7 +18,7 @@ HomieNode homieNode("pixel", "commands"); #define TIMEOUT 500 #define FW_NAME "esp-videoswitcher" -#define FW_VERSION "1.0.3" +#define FW_VERSION "1.0.4" SoftwareSerial swSer(D2, D1); int currentnumber = 0; @@ -26,6 +26,8 @@ int inputbytes[4]; int commandbytes[4]; String output = ""; String output2 = ""; +uint8_t currentinput = 255; // Override +uint8_t currentoutput; unsigned long lastMillis = 0; @@ -197,6 +199,9 @@ bool onSetEffect(const HomieRange& range, const String& value) { else if (effect == "radar") { strip.Radar(); } + else if (effect == "input") { + strip.ShowInput(); + } else { // Test whether command with parameters was sent int sep = value.indexOf("|"); @@ -267,11 +272,11 @@ bool switchHandler(const HomieRange& range, const String& value) { swSer.write(commandbytes[2]); swSer.write(commandbytes[3]); // Zeige aktuelle Quelle auf dem Strip an - strip.None(); - strip.clear(); - strip.show(); - strip.colorBox(commandbytes[1]-128, strip.Color(255, 255, 255)); - strip.show(); +// strip.None(); +// strip.clear(); +// strip.show(); +// strip.colorBox(commandbytes[1]-128, strip.Color(255, 255, 255)); +// strip.show(); } else { @@ -310,7 +315,6 @@ void setup() { // homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels); // homieNode.advertiseRange("boxs", 0, (BIGPIXELS - 1)*7).settable(onSetBoxs); - Homie.setup(); strip.begin(); @@ -335,7 +339,7 @@ void setup() { // strip.setPixelColor(progress / (total / NUMPIXELS), strip.Color(100, 0, 0)); // strip.show(); }); - + strip.setCurrentInput(255); ArduinoOTA.begin(); } @@ -351,6 +355,7 @@ void loop() { Serial.print(": "); Serial.print(r1); Serial.print(" "); + switchNode.setProperty("dataSeq").send(String(r1)); inputbytes[currentnumber] = r1; output += String(r1, DEC); @@ -366,13 +371,16 @@ void loop() { switchNode.setProperty("input").send(String(inputbytes[1]-128, DEC)); switchNode.setProperty("output").send(String(inputbytes[2]-128, DEC)); - - // Zeige aktuelle Quelle auf dem Strip an - strip.None(); - strip.clear(); - strip.show(); - strip.colorBox(inputbytes[1]-128, strip.Color(255, 255, 255)); - strip.show(); + // Merke aktuelle Quelle zur Anzeige auf dem Strip + currentinput = inputbytes[1]-128; + strip.setCurrentInput(currentinput); + currentoutput = inputbytes[2]-128; + +// strip.None(); +// strip.clear(); +// strip.show(); +// strip.colorBox(inputbytes[1]-128, strip.Color(255, 255, 255)); +// strip.show(); currentnumber = 0; inputbytes[0] = 0; @@ -382,12 +390,17 @@ void loop() { output = ""; } else { + if ((currentnumber == 0) && (r1 != 65)) + { + // Wrong input. + break; + } Serial.print(">"); Serial.print(currentnumber); Serial.print("<"); currentnumber++; } - if (millis() > lastMillis + 1000) // Timeout + if (millis() > lastMillis + TIMEOUT) // Timeout { currentnumber = 0; }