From 790ec5b8677f4813d2f5ef8837c3f6516549fb61 Mon Sep 17 00:00:00 2001 From: starcalc Date: Thu, 21 Dec 2017 21:17:35 +0100 Subject: [PATCH] =?UTF-8?q?Boxen=20k=C3=B6nnen=20per=20MQTT=20angesteuert?= =?UTF-8?q?=20werden.=20Die=20INPUT-Box=20wird=20illuminiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp-videoswitcher.ino | 74 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/esp-videoswitcher.ino b/esp-videoswitcher.ino index 4070f30..b3be74d 100644 --- a/esp-videoswitcher.ino +++ b/esp-videoswitcher.ino @@ -16,7 +16,7 @@ HomieNode homieNode("pixel", "commands"); #define TIMEOUT 500 #define FW_NAME "esp-videoswitcher" -#define FW_VERSION "1.0.0" +#define FW_VERSION "1.0.1" SoftwareSerial swSer(D2, D1); int currentnumber = 0; @@ -46,6 +46,19 @@ bool onSetColor(const HomieRange& range, const String& value) { homieNode.setProperty("color_" + String(range.index)).send(value); } +bool onSetBox(const HomieRange& range, const String& value) { + if (range.index < 0 || range.index > BIGPIXELS) { + return false; + } + strip.None(); + strip.setPixelColor(range.index*3, value.toInt()); + strip.setPixelColor(range.index*3+1, value.toInt()); + strip.setPixelColor(range.index*3+2, value.toInt()); + strip.show(); + homieNode.setProperty("box_" + String(range.index)).send(value); +} + + bool onSetPixel(const HomieRange& range, const String& value) { if (!range.isRange) { strip.None(); @@ -100,6 +113,37 @@ bool onSetPixels(const HomieRange& range, const String& value) { return true; } +bool onSetBoxs(const HomieRange& range, const String& value) { + + String remaining = value; + int i = 0; + // Kein Effekt + strip.Stop(); + do { + String current = remaining.substring(0, 7); + Homie.getLogger() << i << ":" << current << endl; + uint32_t currentcolor = strip.parseColor(current); + + strip.setPixelColor(i*3, currentcolor); + strip.setPixelColor(i*3+1, currentcolor); + strip.setPixelColor(i*3+2, currentcolor); + i++; + + remaining = remaining.substring(7); + + } while (remaining.length() > 2 && (i < strip.numPixels())); + Homie.getLogger() << " filling rest with black" << endl; + while (i < strip.numPixels()) { + strip.setPixelColor(strip.numToPos(i), strip.Color(0, 0, 0)); + i++; + } + + strip.show(); + + return true; +} + + bool onSetEffect(const HomieRange& range, const String& value) { String effect = value; effect.toLowerCase(); @@ -232,12 +276,14 @@ void setup() { switchNode.advertise("switch").settable(switchHandler); homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel); + homieNode.advertiseRange("box", 0, BIGPIXELS - 1).settable(onSetBox); homieNode.advertiseRange("color", 0, 1).settable(onSetColor); homieNode.advertise("brightness").settable(onSetBrightness); homieNode.advertise("effect").settable(onSetEffect); homieNode.advertise("clear").settable(onSetClear); homieNode.advertise("length").settable(onSetLength); homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels); + homieNode.advertiseRange("boxs", 0, (BIGPIXELS - 1)*7).settable(onSetBoxs); Homie.setup(); @@ -250,6 +296,18 @@ void setup() { strip.RainbowCycle(50); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); + ArduinoOTA.onStart([]() { + strip.clear(); + strip.setBrightness(64); + }); + ArduinoOTA.onEnd([]() { + strip.clear(); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + strip.setPixelColor(progress / (total / NUMPIXELS), strip.Color(100, 0, 0)); + strip.show(); + }); + ArduinoOTA.begin(); } @@ -278,6 +336,20 @@ 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(); + for (int j=0;j