2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* UDP notifier
|
|
|
|
*/
|
|
|
|
|
2016-11-27 22:37:51 +01:00
|
|
|
void notify(uint8_t callMode)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2017-05-08 21:46:04 +02:00
|
|
|
if (!udpConnected) return;
|
2016-11-19 19:39:17 +01:00
|
|
|
switch (callMode)
|
|
|
|
{
|
|
|
|
case 1: if (!notifyDirect) return; break;
|
|
|
|
case 2: if (!notifyButton) return; break;
|
2016-12-11 20:11:14 +01:00
|
|
|
case 3: return;
|
2017-05-08 21:46:04 +02:00
|
|
|
case 4: if (!notifyDirect) return; break;
|
2016-12-14 23:40:47 +01:00
|
|
|
case 6: if (!notifyDirect) return; break; //fx change
|
2016-11-19 19:39:17 +01:00
|
|
|
default: return;
|
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
byte udpOut[16];
|
2017-02-04 23:37:28 +01:00
|
|
|
udpOut[0] = 0; //0: wled notifier protocol 1: WARLS protocol
|
2016-11-27 22:37:51 +01:00
|
|
|
udpOut[1] = callMode;
|
|
|
|
udpOut[2] = bri;
|
|
|
|
udpOut[3] = col[0];
|
|
|
|
udpOut[4] = col[1];
|
|
|
|
udpOut[5] = col[2];
|
|
|
|
udpOut[6] = nightlightActive;
|
2016-12-14 21:40:09 +01:00
|
|
|
udpOut[7] = nightlightDelayMins;
|
|
|
|
udpOut[8] = effectCurrent;
|
|
|
|
udpOut[9] = effectSpeed;
|
2017-10-12 17:09:59 +02:00
|
|
|
udpOut[10] = white;
|
2017-11-29 17:57:20 +01:00
|
|
|
udpOut[11] = 2; //compatibilityVersionByte: 0: old 1: supports white 2: supports secondary color
|
2017-11-28 16:04:11 +01:00
|
|
|
udpOut[12] = col_sec[0];
|
|
|
|
udpOut[13] = col_sec[1];
|
|
|
|
udpOut[14] = col_sec[2];
|
|
|
|
udpOut[15] = white_sec;
|
2016-11-19 19:39:17 +01:00
|
|
|
|
2016-11-27 22:37:51 +01:00
|
|
|
IPAddress broadcastIp;
|
|
|
|
broadcastIp = ~WiFi.subnetMask() | WiFi.gatewayIP();
|
2016-11-19 19:39:17 +01:00
|
|
|
|
2016-11-27 22:37:51 +01:00
|
|
|
notifierUdp.beginPacket(broadcastIp, udpPort);
|
|
|
|
notifierUdp.write(udpOut, 16);
|
|
|
|
notifierUdp.endPacket();
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleNotifications()
|
|
|
|
{
|
|
|
|
if(udpConnected && receiveNotifications){
|
|
|
|
int packetSize = notifierUdp.parsePacket();
|
|
|
|
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP())
|
2016-11-20 00:07:04 +01:00
|
|
|
{
|
2017-01-26 23:45:55 +01:00
|
|
|
notifierUdp.read(udpIn, packetSize);
|
2017-02-04 23:37:28 +01:00
|
|
|
if (udpIn[0] == 0) //wled notifier
|
2016-12-31 00:38:51 +01:00
|
|
|
{
|
2017-01-26 23:45:55 +01:00
|
|
|
col[0] = udpIn[3];
|
|
|
|
col[1] = udpIn[4];
|
|
|
|
col[2] = udpIn[5];
|
2017-11-29 17:57:20 +01:00
|
|
|
if (udpIn[11] > 1)
|
2017-11-28 16:04:11 +01:00
|
|
|
{
|
2017-11-29 17:57:20 +01:00
|
|
|
col_sec[0] = udpIn[12];
|
|
|
|
col_sec[1] = udpIn[13];
|
|
|
|
col_sec[2] = udpIn[14];
|
2017-11-28 16:04:11 +01:00
|
|
|
white_sec = udpIn[15];
|
|
|
|
}
|
2017-11-29 17:57:20 +01:00
|
|
|
if (udpIn[11] > 0) //check if sending modules white val is inteded
|
|
|
|
{
|
|
|
|
white = udpIn[10];
|
|
|
|
}
|
2017-01-26 23:45:55 +01:00
|
|
|
if (udpIn[8] != effectCurrent)
|
|
|
|
{
|
|
|
|
effectCurrent = udpIn[8];
|
|
|
|
strip.setMode(effectCurrent);
|
|
|
|
}
|
|
|
|
if (udpIn[9] != effectSpeed)
|
|
|
|
{
|
|
|
|
effectSpeed = udpIn[9];
|
|
|
|
strip.setSpeed(effectSpeed);
|
|
|
|
}
|
|
|
|
nightlightActive = udpIn[6];
|
2017-11-28 16:04:11 +01:00
|
|
|
if (!nightlightActive)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
|
|
|
bri = udpIn[2];
|
|
|
|
colorUpdated(3);
|
|
|
|
}
|
2017-02-21 23:13:05 +01:00
|
|
|
} else if (udpIn[0] == 1 && realtimeEnabled) //warls
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
2017-02-04 23:37:28 +01:00
|
|
|
if (packetSize > 1) {
|
|
|
|
if (udpIn[1] == 0)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
2017-02-04 23:37:28 +01:00
|
|
|
arlsTimeout = false;
|
2017-01-26 23:45:55 +01:00
|
|
|
} else {
|
2017-02-04 23:37:28 +01:00
|
|
|
if (!arlsTimeout){
|
2017-02-24 23:21:48 +01:00
|
|
|
strip.setRange(0, ledcount-1, 0);
|
2017-02-04 23:37:28 +01:00
|
|
|
strip.setMode(0);
|
|
|
|
}
|
|
|
|
arlsTimeout = true;
|
|
|
|
arlsTimeoutTime = millis() + 1000*udpIn[1];
|
|
|
|
}
|
|
|
|
for (int i = 2; i < packetSize -3; i += 4)
|
|
|
|
{
|
2017-02-24 23:21:48 +01:00
|
|
|
if (udpIn[i] + arlsOffset < ledcount && udpIn[i] + arlsOffset >= 0)
|
2017-02-04 23:37:28 +01:00
|
|
|
if (useGammaCorrectionRGB)
|
|
|
|
{
|
2017-02-21 23:13:05 +01:00
|
|
|
strip.setIndividual(udpIn[i] + arlsOffset, ((uint32_t)gamma8[udpIn[i+1]] << 16) | ((uint32_t)gamma8[udpIn[i+2]] << 8) | gamma8[udpIn[i+3]]);
|
2017-02-04 23:37:28 +01:00
|
|
|
} else {
|
|
|
|
strip.setIndividual(udpIn[i], ((uint32_t)udpIn[i+1] << 16) | ((uint32_t)udpIn[i+2] << 8) | udpIn[i+3]);
|
|
|
|
}
|
2017-01-26 23:45:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
}
|
2016-11-20 00:07:04 +01:00
|
|
|
}
|
2017-01-26 23:45:55 +01:00
|
|
|
if (arlsTimeout && millis() > arlsTimeoutTime)
|
|
|
|
{
|
|
|
|
strip.unlockAll();
|
|
|
|
arlsTimeout = false;
|
2017-02-04 23:37:28 +01:00
|
|
|
strip.setMode(effectCurrent);
|
2017-01-26 23:45:55 +01:00
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
|
|
|
|
|