Added TPM2 protocol support via Serial (#933)

This commit is contained in:
cschwinne 2020-05-22 23:30:55 +02:00
parent fec8343f45
commit 06b9b66272
7 changed files with 50 additions and 22 deletions

View File

@ -2,6 +2,15 @@
### Development versions after 0.10.0 release ### Development versions after 0.10.0 release
#### Build 2005220
- Added TPM2.NET protocol support (need to set WLED broadcast UDP port to 65506)
- Added TPM2 protocol support via Serial
- Support up to 6553 seconds preset cycle durations (backend, NOT yet in UI)
- Merged pull request #591 fixing WS2801 color order
- Merged pull request #858 adding fully featured travis builds
- Merged pull request #862 adding DMX proxy feature
#### Build 2005100 #### Build 2005100
- Update to Espalexa v2.4.6 (+1.6kB free heap memory) - Update to Espalexa v2.4.6 (+1.6kB free heap memory)

View File

@ -927,7 +927,7 @@ input[type=number]::-webkit-outer-spin-button {
</label><br> </label><br>
First preset: <input id="cycs" class="noslide" type="number" min="1" max="14" value="1"><br> First preset: <input id="cycs" class="noslide" type="number" min="1" max="14" value="1"><br>
Last preset: <input id="cyce" class="noslide" type="number" min="2" max="15" value="3"><br> Last preset: <input id="cyce" class="noslide" type="number" min="2" max="15" value="3"><br>
Time per preset: <input id="cyct" class="noslide" type="number" min="0.2" max="65.5" step="0.1" value="1.2">s<br> Time per preset: <input id="cyct" class="noslide" type="number" min="0.2" max="6553.5" step="0.1" value="1.2">s<br>
Transition: <input id="cyctt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">s Transition: <input id="cyctt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">s
</div> </div>
</div> </div>

View File

@ -77,7 +77,6 @@ void handleIR();
#include "src/dependencies/json/ArduinoJson-v6.h" #include "src/dependencies/json/ArduinoJson-v6.h"
#include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/AsyncJson-v6.h"
#include "FX.h" #include "FX.h"
// TODO: AsynicWebServerRequest conflict?
void deserializeSegment(JsonObject elem, byte it); void deserializeSegment(JsonObject elem, byte it);
bool deserializeState(JsonObject root); bool deserializeState(JsonObject root);

View File

@ -315,7 +315,7 @@ void serializeInfo(JsonObject root)
case REALTIME_MODE_UDP: root["lm"] = "UDP"; break; case REALTIME_MODE_UDP: root["lm"] = "UDP"; break;
case REALTIME_MODE_HYPERION: root["lm"] = "Hyperion"; break; case REALTIME_MODE_HYPERION: root["lm"] = "Hyperion"; break;
case REALTIME_MODE_E131: root["lm"] = "E1.31"; break; case REALTIME_MODE_E131: root["lm"] = "E1.31"; break;
case REALTIME_MODE_ADALIGHT: root["lm"] = F("USB Adalight"); case REALTIME_MODE_ADALIGHT: root["lm"] = F("USB Adalight/TPM2");
case REALTIME_MODE_ARTNET: root["lm"] = "Art-Net"; break; case REALTIME_MODE_ARTNET: root["lm"] = "Art-Net"; break;
case REALTIME_MODE_TPM2NET: root["lm"] = F("tpm2.net"); break; case REALTIME_MODE_TPM2NET: root["lm"] = F("tpm2.net"); break;
} }

View File

@ -223,24 +223,24 @@ void handleNotifications()
if (tpmType == 0xaa) { //TPM2.NET polling, expect answer if (tpmType == 0xaa) { //TPM2.NET polling, expect answer
sendTPM2Ack(); return; sendTPM2Ack(); return;
} }
if (tpmType == 0xda) { //TPM2.NET data if (tpmType != 0xda) return; //return if notTPM2.NET data
realtimeIP = notifierUdp.remoteIP();
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_TPM2NET);
if (realtimeOverride) return;
uint16_t frameSize = (udpIn[2] << 8) + udpIn[3]; realtimeIP = notifierUdp.remoteIP();
byte packetNum = udpIn[4]; //starts with 1! realtimeLock(realtimeTimeoutMs, REALTIME_MODE_TPM2NET);
byte numPackets = udpIn[5]; if (realtimeOverride) return;
uint16_t id = tpmDataReceived / 3; //start LED uint16_t frameSize = (udpIn[2] << 8) + udpIn[3];
for (uint16_t i = 6; i < frameSize + 4; i += 3) byte packetNum = udpIn[4]; //starts with 1!
{ byte numPackets = udpIn[5];
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
id++; if (id >= ledCount) break; uint16_t id = ((tpmFirstFrameSize/3)*(packetNum-1)) / 3; //start LED
} for (uint16_t i = 6; i < frameSize + 4; i += 3)
tpmDataReceived += frameSize; {
if (packetNum == numPackets) {strip.show(); tpmDataReceived = 0;} //show if last packet setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
id++; if (id >= ledCount) break;
} }
if (packetNum == 1) tpmFirstFrameSize = frameSize;
if (packetNum == numPackets) {strip.show(); } //show if last packet
} }
//UDP realtime: 1 warls 2 drgb 3 drgbw //UDP realtime: 1 warls 2 drgb 3 drgbw

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2005180 #define VERSION 2005220
// ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS). // ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).
@ -426,7 +426,7 @@ WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE);
WLED_GLOBAL byte realtimeOverride _INIT(REALTIME_OVERRIDE_NONE); WLED_GLOBAL byte realtimeOverride _INIT(REALTIME_OVERRIDE_NONE);
WLED_GLOBAL IPAddress realtimeIP _INIT((0, 0, 0, 0)); WLED_GLOBAL IPAddress realtimeIP _INIT((0, 0, 0, 0));
WLED_GLOBAL unsigned long realtimeTimeout _INIT(0); WLED_GLOBAL unsigned long realtimeTimeout _INIT(0);
WLED_GLOBAL uint16_t tpmDataReceived _INIT(0); WLED_GLOBAL uint16_t tpmFirstFrameSize _INIT(0);
// mqtt // mqtt
WLED_GLOBAL long lastMqttReconnectAttempt _INIT(0); WLED_GLOBAL long lastMqttReconnectAttempt _INIT(0);

View File

@ -1,7 +1,7 @@
#include "wled.h" #include "wled.h"
/* /*
* Adalight handler * Adalight and TPM2 handler
*/ */
enum class AdaState { enum class AdaState {
@ -13,7 +13,10 @@ enum class AdaState {
Header_CountCheck, Header_CountCheck,
Data_Red, Data_Red,
Data_Green, Data_Green,
Data_Blue Data_Blue,
TPM2_Header_Type,
TPM2_Header_CountHi,
TPM2_Header_CountLo
}; };
void handleSerial() void handleSerial()
@ -33,6 +36,9 @@ void handleSerial()
switch (state) { switch (state) {
case AdaState::Header_A: case AdaState::Header_A:
if (next == 'A') state = AdaState::Header_d; if (next == 'A') state = AdaState::Header_d;
else if (next == 0x9C) { //TPM2 start byte
state = AdaState::TPM2_Header_Type;
}
break; break;
case AdaState::Header_d: case AdaState::Header_d:
if (next == 'd') state = AdaState::Header_a; if (next == 'd') state = AdaState::Header_a;
@ -57,6 +63,20 @@ void handleSerial()
if (check == next) state = AdaState::Data_Red; if (check == next) state = AdaState::Data_Red;
else state = AdaState::Header_A; else state = AdaState::Header_A;
break; break;
case AdaState::TPM2_Header_Type:
state = AdaState::Header_A; //(unsupported) TPM2 command or invalid type
if (next == 0xDA) state = AdaState::TPM2_Header_CountHi; //TPM2 data
else if (next == 0xAA) Serial.write(0xAC); //TPM2 ping
break;
case AdaState::TPM2_Header_CountHi:
pixel = 0;
count = (next * 0x100) /3;
state = AdaState::TPM2_Header_CountLo;
break;
case AdaState::TPM2_Header_CountLo:
count += next /3 + 1;
state = AdaState::Data_Red;
break;
case AdaState::Data_Red: case AdaState::Data_Red:
red = next; red = next;
state = AdaState::Data_Green; state = AdaState::Data_Green;