diff --git a/esp-videoswitcher.ino b/esp-videoswitcher.ino index 0b27256..81149e3 100644 --- a/esp-videoswitcher.ino +++ b/esp-videoswitcher.ino @@ -11,6 +11,9 @@ SoftwareSerial swSer(D2, D1); int currentnumber = 0; +int inputbytes[4]; +String output = ""; +String output2 = ""; HomieNode switchNode("switch", "switch"); @@ -44,9 +47,42 @@ void loop() { while (swSer.available() > 0) { int r1 = swSer.read(); + Serial.print(currentnumber); + Serial.print(": "); Serial.print(r1); Serial.print(" "); - switchNode.setProperty("data").send(String(r1, DEC)); + inputbytes[currentnumber] = r1; + + output += String(r1, DEC); + output += " "; + if (currentnumber == 3) { + switchNode.setProperty("data").send(output); + output2 = ""; + output2 += "OUTPUT "; + output2 += String(inputbytes[2]-128, DEC); + output2 += " INPUT "; + output2 += String(inputbytes[1]-128, DEC); + switchNode.setProperty("switchevent").send(output2); + switchNode.setProperty("input").send(String(inputbytes[1]-128, DEC)); + switchNode.setProperty("output").send(String(inputbytes[2]-128, DEC)); + // Einfache Interpretation +// Serial.print("Von "); +// Serial.print(String(inputbytes[2]-128, DEC)); +// Serial.print(" zu "); +// Serial.println(String(inputbytes[1]-128, DEC)); + currentnumber = 0; + inputbytes[0] = 0; + inputbytes[1] = 0; + inputbytes[2] = 0; + inputbytes[3] = 0; + output = ""; + + } else { + Serial.print(">"); + Serial.print(currentnumber); + Serial.print("<"); + currentnumber++; + } } // while (Serial.available() > 0) { // swSer.write(Serial.read());