2016-11-27 22:37:51 +01:00
|
|
|
void notify(uint8_t callMode)
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2016-12-11 20:11:14 +01: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;
|
2016-11-26 19:34:05 +01:00
|
|
|
case 4: if (!notifyNightlight) return; break;
|
2016-11-19 19:39:17 +01:00
|
|
|
default: return;
|
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
byte udpOut[16];
|
2016-12-11 20:11:14 +01:00
|
|
|
udpOut[0] = 0; //reserved
|
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-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
|
|
|
{
|
2016-11-27 22:37:51 +01:00
|
|
|
notifierUdp.read(notifierBuffer, 16);
|
2016-12-11 20:11:14 +01:00
|
|
|
col[0] = notifierBuffer[3];
|
2016-11-27 22:37:51 +01:00
|
|
|
col[1] = notifierBuffer[4];
|
|
|
|
col[2] = notifierBuffer[5];
|
2016-12-11 20:11:14 +01:00
|
|
|
nightlightActive = notifierBuffer[6];
|
|
|
|
if (!notifierBuffer[6])
|
2016-11-27 22:37:51 +01:00
|
|
|
{
|
2016-12-11 20:11:14 +01:00
|
|
|
bri = notifierBuffer[2];
|
2016-11-27 22:37:51 +01:00
|
|
|
colorUpdated(3);
|
|
|
|
}
|
2016-11-20 00:07:04 +01:00
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 22:37:51 +01:00
|
|
|
|
|
|
|
|