2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* UDP notifier
|
|
|
|
*/
|
|
|
|
|
2018-01-27 23:28:20 +01:00
|
|
|
#define WLEDPACKETSIZE 24
|
|
|
|
|
2018-03-14 13:16:28 +01:00
|
|
|
void notify(byte callMode, bool followUp=false)
|
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)
|
|
|
|
{
|
2018-04-11 23:50:35 +02:00
|
|
|
case 0: return;
|
2016-11-19 19:39:17 +01:00
|
|
|
case 1: if (!notifyDirect) return; break;
|
|
|
|
case 2: if (!notifyButton) return; break;
|
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
|
2018-02-28 00:27:10 +01:00
|
|
|
case 7: if (!notifyHue) return; break;
|
2018-04-11 23:50:35 +02:00
|
|
|
case 8: if (!notifyDirect) return; break;
|
2018-07-29 14:03:02 +02:00
|
|
|
case 9: if (!notifyDirect) return; break;
|
2016-11-19 19:39:17 +01:00
|
|
|
default: return;
|
|
|
|
}
|
2018-01-27 23:28:20 +01:00
|
|
|
byte udpOut[WLEDPACKETSIZE];
|
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;
|
2018-09-06 02:05:56 +02:00
|
|
|
udpOut[11] = 5; //compatibilityVersionByte: 0: old 1: supports white 2: supports secondary color 3: supports FX intensity, 24 byte packet 4: supports transitionDelay 5: sup palette
|
2018-03-14 13:16:28 +01:00
|
|
|
udpOut[12] = colSec[0];
|
|
|
|
udpOut[13] = colSec[1];
|
|
|
|
udpOut[14] = colSec[2];
|
|
|
|
udpOut[15] = whiteSec;
|
2018-01-27 23:28:20 +01:00
|
|
|
udpOut[16] = effectIntensity;
|
2018-03-15 12:04:14 +01:00
|
|
|
udpOut[17] = (transitionDelay >> 0) & 0xFF;
|
|
|
|
udpOut[18] = (transitionDelay >> 8) & 0xFF;
|
2018-09-06 02:05:56 +02:00
|
|
|
udpOut[19] = effectPalette;
|
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);
|
2018-01-27 23:28:20 +01:00
|
|
|
notifierUdp.write(udpOut, WLEDPACKETSIZE);
|
2016-11-27 22:37:51 +01:00
|
|
|
notifierUdp.endPacket();
|
2018-03-06 23:47:08 +01:00
|
|
|
notificationSentCallMode = callMode;
|
|
|
|
notificationSentTime = millis();
|
|
|
|
notificationTwoRequired = (followUp)? false:notifyTwice;
|
2016-11-27 22:37:51 +01:00
|
|
|
}
|
|
|
|
|
2018-05-18 23:24:47 +02:00
|
|
|
void arlsLock(uint32_t timeoutMs)
|
|
|
|
{
|
2018-09-15 17:29:01 +02:00
|
|
|
if (!realtimeActive){
|
2018-10-01 21:31:31 +02:00
|
|
|
for (uint16_t i = 0; i < ledCount; i++)
|
|
|
|
{
|
|
|
|
strip.setPixelColor(i,0,0,0,0);
|
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
strip.setMode(0);
|
|
|
|
}
|
2018-09-15 17:29:01 +02:00
|
|
|
realtimeActive = true;
|
|
|
|
realtimeTimeout = millis() + timeoutMs;
|
2018-08-11 22:57:13 +02:00
|
|
|
if (arlsForceMaxBri) strip.setBrightness(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initE131(){
|
|
|
|
if (WiFi.status() == WL_CONNECTED && e131Enabled)
|
|
|
|
{
|
2018-10-04 18:17:01 +02:00
|
|
|
e131 = new E131();
|
|
|
|
e131->begin((e131Multicast) ? E131_MULTICAST : E131_UNICAST , e131Universe);
|
2018-08-11 22:57:13 +02:00
|
|
|
} else {
|
|
|
|
e131Enabled = false;
|
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
}
|
|
|
|
|
2016-11-27 22:37:51 +01:00
|
|
|
void handleNotifications()
|
|
|
|
{
|
2018-05-18 23:24:47 +02:00
|
|
|
//send second notification if enabled
|
2018-03-06 23:47:08 +01:00
|
|
|
if(udpConnected && notificationTwoRequired && millis()-notificationSentTime > 250){
|
|
|
|
notify(notificationSentCallMode,true);
|
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
|
2018-08-11 22:57:13 +02:00
|
|
|
//E1.31 protocol support
|
|
|
|
if(e131Enabled) {
|
2018-10-04 18:17:01 +02:00
|
|
|
uint16_t len = e131->parsePacket();
|
|
|
|
if (len && e131->universe == e131Universe) {
|
2018-09-15 17:29:01 +02:00
|
|
|
arlsLock(realtimeTimeoutMs);
|
2018-08-11 22:57:13 +02:00
|
|
|
if (len > ledCount) len = ledCount;
|
|
|
|
for (uint16_t i = 0; i < len; i++) {
|
|
|
|
int j = i * 3;
|
|
|
|
|
2018-10-04 18:17:01 +02:00
|
|
|
setRealtimePixel(i, e131->data[j], e131->data[j+1], e131->data[j+2], 0);
|
2018-08-11 22:57:13 +02:00
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 23:24:47 +02:00
|
|
|
//unlock strip when realtime UDP times out
|
2018-09-15 17:29:01 +02:00
|
|
|
if (realtimeActive && millis() > realtimeTimeout)
|
2018-05-18 23:24:47 +02:00
|
|
|
{
|
|
|
|
strip.unlockAll();
|
2018-08-11 22:57:13 +02:00
|
|
|
strip.setBrightness(bri);
|
2018-09-15 17:29:01 +02:00
|
|
|
realtimeActive = false;
|
2018-05-18 23:24:47 +02:00
|
|
|
strip.setMode(effectCurrent);
|
2018-08-11 22:57:13 +02:00
|
|
|
realtimeIP[0] = 0;
|
2018-05-18 23:24:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//receive UDP notifications
|
2018-04-11 23:50:35 +02:00
|
|
|
if(udpConnected && (receiveNotifications || receiveDirect)){
|
2018-03-14 13:16:28 +01:00
|
|
|
uint16_t packetSize = notifierUdp.parsePacket();
|
2018-05-18 23:24:47 +02:00
|
|
|
|
|
|
|
//hyperion / raw RGB
|
2018-06-24 01:20:15 +02:00
|
|
|
if (!packetSize && udpRgbConnected) {
|
2018-05-18 23:24:47 +02:00
|
|
|
packetSize = rgbUdp.parsePacket();
|
2018-06-24 01:20:15 +02:00
|
|
|
if (!receiveDirect) return;
|
2018-05-18 23:24:47 +02:00
|
|
|
if (packetSize > 1026 || packetSize < 3) return;
|
2018-10-01 21:31:31 +02:00
|
|
|
realtimeIP = rgbUdp.remoteIP();
|
|
|
|
DEBUG_PRINTLN(rgbUdp.remoteIP());
|
2018-05-18 23:24:47 +02:00
|
|
|
byte udpIn[packetSize];
|
|
|
|
rgbUdp.read(udpIn, packetSize);
|
2018-09-15 17:29:01 +02:00
|
|
|
arlsLock(realtimeTimeoutMs);
|
2018-05-18 23:24:47 +02:00
|
|
|
uint16_t id = 0;
|
|
|
|
for (uint16_t i = 0; i < packetSize -2; i += 3)
|
|
|
|
{
|
2018-08-11 22:57:13 +02:00
|
|
|
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
|
|
|
|
|
2018-05-18 23:24:47 +02:00
|
|
|
id++; if (id >= ledCount) break;
|
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:16:28 +01:00
|
|
|
if (packetSize > 1026) return;
|
2018-02-23 01:33:32 +01:00
|
|
|
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves
|
2016-11-20 00:07:04 +01:00
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
byte udpIn[packetSize];
|
2017-01-26 23:45:55 +01:00
|
|
|
notifierUdp.read(udpIn, packetSize);
|
2018-09-15 17:29:01 +02:00
|
|
|
if (udpIn[0] == 0 && !realtimeActive && receiveNotifications) //wled notifier, block if realtime packets active
|
2016-12-31 00:38:51 +01:00
|
|
|
{
|
2018-02-23 01:33:32 +01:00
|
|
|
if (receiveNotificationColor)
|
|
|
|
{
|
2017-01-26 23:45:55 +01:00
|
|
|
col[0] = udpIn[3];
|
|
|
|
col[1] = udpIn[4];
|
|
|
|
col[2] = udpIn[5];
|
2017-11-28 16:04:11 +01:00
|
|
|
}
|
2018-02-23 01:33:32 +01:00
|
|
|
if (udpIn[11] > 0 && receiveNotificationColor) //check if sending modules white val is inteded
|
2017-11-29 17:57:20 +01:00
|
|
|
{
|
|
|
|
white = udpIn[10];
|
2018-02-23 01:33:32 +01:00
|
|
|
if (udpIn[11] > 1 )
|
|
|
|
{
|
2018-03-14 13:16:28 +01:00
|
|
|
colSec[0] = udpIn[12];
|
|
|
|
colSec[1] = udpIn[13];
|
|
|
|
colSec[2] = udpIn[14];
|
|
|
|
whiteSec = udpIn[15];
|
2018-02-23 01:33:32 +01:00
|
|
|
}
|
2017-11-29 17:57:20 +01:00
|
|
|
}
|
2018-02-23 01:33:32 +01:00
|
|
|
if (udpIn[8] != effectCurrent && receiveNotificationEffects)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
|
|
|
effectCurrent = udpIn[8];
|
|
|
|
strip.setMode(effectCurrent);
|
|
|
|
}
|
2018-02-23 01:33:32 +01:00
|
|
|
if (udpIn[9] != effectSpeed && receiveNotificationEffects)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
|
|
|
effectSpeed = udpIn[9];
|
|
|
|
strip.setSpeed(effectSpeed);
|
|
|
|
}
|
2018-02-23 12:22:58 +01:00
|
|
|
if (udpIn[11] > 2 && udpIn[16] != effectIntensity && receiveNotificationEffects)
|
2018-01-27 23:28:20 +01:00
|
|
|
{
|
2018-02-23 12:22:58 +01:00
|
|
|
effectIntensity = udpIn[16];
|
2018-01-27 23:28:20 +01:00
|
|
|
strip.setIntensity(effectIntensity);
|
|
|
|
}
|
2018-03-15 13:03:50 +01:00
|
|
|
if (udpIn[11] > 3)
|
|
|
|
{
|
|
|
|
transitionDelayTemp = ((udpIn[17] << 0) & 0xFF) + ((udpIn[18] << 8) & 0xFF00);
|
|
|
|
}
|
2018-09-06 02:05:56 +02:00
|
|
|
if (udpIn[11] > 4 && udpIn[19] != effectPalette && receiveNotificationEffects)
|
|
|
|
{
|
|
|
|
effectPalette = udpIn[19];
|
|
|
|
strip.setPalette(effectPalette);
|
|
|
|
}
|
2017-01-26 23:45:55 +01:00
|
|
|
nightlightActive = udpIn[6];
|
2017-11-28 16:04:11 +01:00
|
|
|
if (!nightlightActive)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
2018-02-23 01:33:32 +01:00
|
|
|
if (receiveNotificationBrightness) bri = udpIn[2];
|
2017-01-26 23:45:55 +01:00
|
|
|
colorUpdated(3);
|
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
} else if (udpIn[0] > 0 && udpIn[0] < 4 && receiveDirect) //1 warls //2 drgb //3 drgbw
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
2018-06-24 01:20:15 +02:00
|
|
|
realtimeIP = notifierUdp.remoteIP();
|
2018-10-01 21:31:31 +02:00
|
|
|
DEBUG_PRINTLN(notifierUdp.remoteIP());
|
2017-02-04 23:37:28 +01:00
|
|
|
if (packetSize > 1) {
|
|
|
|
if (udpIn[1] == 0)
|
2017-01-26 23:45:55 +01:00
|
|
|
{
|
2018-09-15 17:29:01 +02:00
|
|
|
realtimeActive = false;
|
2017-01-26 23:45:55 +01:00
|
|
|
} else {
|
2018-05-18 23:24:47 +02:00
|
|
|
arlsLock(udpIn[1]*1000);
|
2017-02-04 23:37:28 +01:00
|
|
|
}
|
2018-04-11 23:50:35 +02:00
|
|
|
if (udpIn[0] == 1) //warls
|
2017-02-04 23:37:28 +01:00
|
|
|
{
|
2018-05-18 23:24:47 +02:00
|
|
|
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
2017-02-04 23:37:28 +01:00
|
|
|
{
|
2018-08-11 22:57:13 +02:00
|
|
|
setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0);
|
2018-04-11 23:50:35 +02:00
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
} else if (udpIn[0] == 2) //drgb
|
2018-04-11 23:50:35 +02:00
|
|
|
{
|
2018-05-18 23:24:47 +02:00
|
|
|
uint16_t id = 0;
|
|
|
|
for (uint16_t i = 2; i < packetSize -2; i += 3)
|
2018-04-11 23:50:35 +02:00
|
|
|
{
|
2018-08-11 22:57:13 +02:00
|
|
|
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
|
|
|
|
|
2018-04-11 23:50:35 +02:00
|
|
|
id++; if (id >= ledCount) break;
|
|
|
|
}
|
2018-05-18 23:24:47 +02:00
|
|
|
} else if (udpIn[0] == 3) //drgbw
|
2018-04-11 23:50:35 +02:00
|
|
|
{
|
2018-05-18 23:24:47 +02:00
|
|
|
uint16_t id = 0;
|
|
|
|
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
2018-04-11 23:50:35 +02:00
|
|
|
{
|
2018-08-11 22:57:13 +02:00
|
|
|
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
|
|
|
|
|
2018-04-11 23:50:35 +02:00
|
|
|
id++; if (id >= ledCount) break;
|
2017-02-04 23:37:28 +01:00
|
|
|
}
|
2017-01-26 23:45:55 +01:00
|
|
|
}
|
2017-12-14 11:28:15 +01:00
|
|
|
strip.show();
|
2017-01-26 23:45:55 +01:00
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
}
|
2016-11-20 00:07:04 +01:00
|
|
|
}
|
2018-04-11 23:50:35 +02:00
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
|
2018-10-01 21:31:31 +02:00
|
|
|
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w)
|
2018-08-11 22:57:13 +02:00
|
|
|
{
|
2018-10-01 21:31:31 +02:00
|
|
|
uint16_t pix = i + arlsOffset;
|
|
|
|
if (pix < ledCount)
|
2018-08-11 22:57:13 +02:00
|
|
|
{
|
|
|
|
if (!arlsDisableGammaCorrection && useGammaCorrectionRGB)
|
|
|
|
{
|
2018-10-01 21:31:31 +02:00
|
|
|
strip.setPixelColor(pix, gamma8[r], gamma8[g], gamma8[b], gamma8[w]);
|
2018-08-11 22:57:13 +02:00
|
|
|
} else {
|
2018-10-01 21:31:31 +02:00
|
|
|
strip.setPixelColor(pix, r, g, b, w);
|
2018-08-11 22:57:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 22:37:51 +01:00
|
|
|
|