Boxen können per MQTT angesteuert werden. Die INPUT-Box wird illuminiert.

This commit is contained in:
starcalc 2017-12-21 21:17:35 +01:00
parent edb1e0088a
commit 790ec5b867
1 changed files with 73 additions and 1 deletions

View File

@ -16,7 +16,7 @@ HomieNode homieNode("pixel", "commands");
#define TIMEOUT 500 #define TIMEOUT 500
#define FW_NAME "esp-videoswitcher" #define FW_NAME "esp-videoswitcher"
#define FW_VERSION "1.0.0" #define FW_VERSION "1.0.1"
SoftwareSerial swSer(D2, D1); SoftwareSerial swSer(D2, D1);
int currentnumber = 0; int currentnumber = 0;
@ -46,6 +46,19 @@ bool onSetColor(const HomieRange& range, const String& value) {
homieNode.setProperty("color_" + String(range.index)).send(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) { bool onSetPixel(const HomieRange& range, const String& value) {
if (!range.isRange) { if (!range.isRange) {
strip.None(); strip.None();
@ -100,6 +113,37 @@ bool onSetPixels(const HomieRange& range, const String& value) {
return true; 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) { bool onSetEffect(const HomieRange& range, const String& value) {
String effect = value; String effect = value;
effect.toLowerCase(); effect.toLowerCase();
@ -232,12 +276,14 @@ void setup() {
switchNode.advertise("switch").settable(switchHandler); switchNode.advertise("switch").settable(switchHandler);
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel); homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
homieNode.advertiseRange("box", 0, BIGPIXELS - 1).settable(onSetBox);
homieNode.advertiseRange("color", 0, 1).settable(onSetColor); homieNode.advertiseRange("color", 0, 1).settable(onSetColor);
homieNode.advertise("brightness").settable(onSetBrightness); homieNode.advertise("brightness").settable(onSetBrightness);
homieNode.advertise("effect").settable(onSetEffect); homieNode.advertise("effect").settable(onSetEffect);
homieNode.advertise("clear").settable(onSetClear); homieNode.advertise("clear").settable(onSetClear);
homieNode.advertise("length").settable(onSetLength); homieNode.advertise("length").settable(onSetLength);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels); homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels);
homieNode.advertiseRange("boxs", 0, (BIGPIXELS - 1)*7).settable(onSetBoxs);
Homie.setup(); Homie.setup();
@ -250,6 +296,18 @@ void setup() {
strip.RainbowCycle(50); strip.RainbowCycle(50);
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); 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(); ArduinoOTA.begin();
} }
@ -278,6 +336,20 @@ void loop() {
switchNode.setProperty("input").send(String(inputbytes[1]-128, DEC)); switchNode.setProperty("input").send(String(inputbytes[1]-128, DEC));
switchNode.setProperty("output").send(String(inputbytes[2]-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<NUMPIXELS;j++)
{
strip.setPixelColor(j, strip.Color(0, 0, 0));
}
strip.show();
strip.colorBox(inputbytes[1]-128, strip.Color(255, 255, 255));
// strip.setPixelColor((inputbytes[1]-128)*3, strip.Color(255, 0, 0));
// strip.setPixelColor((inputbytes[1]-128)*3+1, strip.Color(255, 0, 0));
// strip.setPixelColor((inputbytes[1]-128)*3+2, strip.Color(255, 0, 0));
strip.show();
currentnumber = 0; currentnumber = 0;
inputbytes[0] = 0; inputbytes[0] = 0;
inputbytes[1] = 0; inputbytes[1] = 0;