Added Hyperion support on UDP port 19446

This commit is contained in:
cschwinne 2018-05-18 23:24:47 +02:00
parent 3afb499930
commit ce1ba3bc2c
4 changed files with 66 additions and 34 deletions

View File

@ -33,7 +33,7 @@
#include "WS2812FX.h" #include "WS2812FX.h"
//version in format yymmddb (b = daily build) //version in format yymmddb (b = daily build)
#define VERSION 1805061 #define VERSION 1805181
const String versionString = "0.6.5"; const String versionString = "0.6.5";
//AP and OTA default passwords (change them!) //AP and OTA default passwords (change them!)
@ -92,7 +92,7 @@ bool receiveNotifications = true, receiveNotificationBrightness = true, receiveN
byte briMultiplier = 100; byte briMultiplier = 100;
byte nightlightDelayMins = 60; byte nightlightDelayMins = 60;
bool nightlightFade = true; bool nightlightFade = true;
uint16_t udpPort = 21324; uint16_t udpPort = 21324, udpRgbPort = 19446;
byte effectDefault = 0; byte effectDefault = 0;
byte effectSpeedDefault = 75; byte effectSpeedDefault = 75;
byte effectIntensityDefault = 128; byte effectIntensityDefault = 128;
@ -158,20 +158,20 @@ byte notificationSentCallMode = 0;
bool notificationTwoRequired = false; bool notificationTwoRequired = false;
bool nightlightActive = false; bool nightlightActive = false;
bool nightlightActiveOld = false; bool nightlightActiveOld = false;
uint32_t nightlightDelayMs; uint32_t nightlightDelayMs = 10;
byte briNlT; byte briNlT = 0;
byte effectCurrent = 0; byte effectCurrent = 0;
byte effectSpeed = 75; byte effectSpeed = 75;
byte effectIntensity = 128; byte effectIntensity = 128;
bool onlyAP = false; bool onlyAP = false;
bool udpConnected = false; bool udpConnected = false, udpRgbConnected = false;
String cssCol[]={"","","","","",""}; String cssCol[]={"","","","","",""};
String cssFont="Verdana"; String cssFont="Verdana";
String cssColorString=""; String cssColorString="";
//NTP stuff //NTP stuff
bool ntpConnected = false; bool ntpConnected = false;
byte currentTimezone = 0; byte currentTimezone = 0;
time_t local; time_t local = 0;
int utcOffsetSecs = 0; int utcOffsetSecs = 0;
//hue //hue
@ -217,10 +217,10 @@ bool presetApplyBri = true, presetApplyCol = true, presetApplyFx = true;
uint32_t arlsTimeoutMillis = 2500; uint32_t arlsTimeoutMillis = 2500;
bool arlsTimeout = false; bool arlsTimeout = false;
bool receiveDirect = true, enableRealtimeUI = false; bool receiveDirect = true, enableRealtimeUI = false;
unsigned long arlsTimeoutTime; unsigned long arlsTimeoutTime = 0;
byte auxTime = 0; byte auxTime = 0;
unsigned long auxStartTime; unsigned long auxStartTime = 0;
bool auxActive, auxActiveBefore; bool auxActive = false, auxActiveBefore = false;
bool showWelcomePage = false; bool showWelcomePage = false;
bool useGammaCorrectionBri = false; bool useGammaCorrectionBri = false;
@ -245,7 +245,7 @@ ESP8266WebServer server(80);
#endif #endif
HTTPClient hueClient; HTTPClient hueClient;
ESP8266HTTPUpdateServer httpUpdater; ESP8266HTTPUpdateServer httpUpdater;
WiFiUDP notifierUdp;//, rgbUdp; WiFiUDP notifierUdp, rgbUdp;
WiFiUDP ntpUdp; WiFiUDP ntpUdp;
IPAddress ntpServerIP; IPAddress ntpServerIP;
unsigned int ntpLocalPort = 2390; unsigned int ntpLocalPort = 2390;

View File

@ -13,7 +13,7 @@ void handleSerial()
strip.setMode(0); strip.setMode(0);
} }
arlsTimeout = true; arlsTimeout = true;
arlsTimeoutTime = millis() + 4900; arlsTimeoutTime = millis() + 5200;
delay(1); delay(1);
byte hi = Serial.read(); byte hi = Serial.read();
byte ledc = Serial.read(); byte ledc = Serial.read();

View File

@ -43,7 +43,7 @@ void wledInit()
if (udpPort > 0 && udpPort != ntpLocalPort && WiFi.status() == WL_CONNECTED) if (udpPort > 0 && udpPort != ntpLocalPort && WiFi.status() == WL_CONNECTED)
{ {
udpConnected = notifierUdp.begin(udpPort); udpConnected = notifierUdp.begin(udpPort);
//if (udpConnected && udpRgbPort != udpPort) udpRgbConnected = rgbUdp.begin(udpRgbPort); if (udpConnected && udpRgbPort != udpPort) udpRgbConnected = rgbUdp.begin(udpRgbPort);
} }
if (ntpEnabled && WiFi.status() == WL_CONNECTED) if (ntpEnabled && WiFi.status() == WL_CONNECTED)
ntpConnected = ntpUdp.begin(ntpLocalPort); ntpConnected = ntpUdp.begin(ntpLocalPort);

View File

@ -50,14 +50,58 @@ void notify(byte callMode, bool followUp=false)
notificationTwoRequired = (followUp)? false:notifyTwice; notificationTwoRequired = (followUp)? false:notifyTwice;
} }
void arlsLock(uint32_t timeoutMs)
{
if (!arlsTimeout){
strip.setRange(0, ledCount-1, 0);
strip.setMode(0);
}
arlsTimeout = true;
arlsTimeoutTime = millis() + timeoutMs;
}
void handleNotifications() void handleNotifications()
{ {
//send second notification if enabled
if(udpConnected && notificationTwoRequired && millis()-notificationSentTime > 250){ if(udpConnected && notificationTwoRequired && millis()-notificationSentTime > 250){
notify(notificationSentCallMode,true); notify(notificationSentCallMode,true);
} }
//unlock strip when realtime UDP times out
if (arlsTimeout && millis() > arlsTimeoutTime)
{
strip.unlockAll();
if (bri == 0) strip.setBrightness(0);
arlsTimeout = false;
strip.setMode(effectCurrent);
}
//receive UDP notifications
if(udpConnected && (receiveNotifications || receiveDirect)){ if(udpConnected && (receiveNotifications || receiveDirect)){
uint16_t packetSize = notifierUdp.parsePacket(); uint16_t packetSize = notifierUdp.parsePacket();
//hyperion / raw RGB
if (!packetSize && receiveDirect && udpRgbConnected) {
packetSize = rgbUdp.parsePacket();
if (packetSize > 1026 || packetSize < 3) return;
byte udpIn[packetSize];
rgbUdp.read(udpIn, packetSize);
arlsLock(5200);
uint16_t id = 0;
for (uint16_t i = 0; i < packetSize -2; i += 3)
{
if (useGammaCorrectionRGB)
{
strip.setPixelColor(id, gamma8[udpIn[i]], gamma8[udpIn[i+1]], gamma8[udpIn[i+2]]);
} else {
strip.setPixelColor(id, udpIn[i], udpIn[i+1], udpIn[i+2]);
}
id++; if (id >= ledCount) break;
}
strip.show();
return;
}
if (packetSize > 1026) return; if (packetSize > 1026) return;
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves
{ {
@ -107,23 +151,18 @@ void handleNotifications()
if (receiveNotificationBrightness) bri = udpIn[2]; if (receiveNotificationBrightness) bri = udpIn[2];
colorUpdated(3); colorUpdated(3);
} }
} else if (udpIn[0] > 0 && udpIn[0] < 4) //1 warls //2 drgb //3 drgbw } else if (udpIn[0] > 0 && udpIn[0] < 4 && receiveDirect) //1 warls //2 drgb //3 drgbw
{ {
if (packetSize > 1) { if (packetSize > 1) {
if (udpIn[1] == 0) if (udpIn[1] == 0)
{ {
arlsTimeout = false; arlsTimeout = false;
} else { } else {
if (!arlsTimeout){ arlsLock(udpIn[1]*1000);
strip.setRange(0, ledCount-1, 0);
strip.setMode(0);
}
arlsTimeout = true;
arlsTimeoutTime = millis() + 1000*udpIn[1];
} }
if (udpIn[0] == 1) //warls if (udpIn[0] == 1) //warls
{ {
for (int i = 2; i < packetSize -3; i += 4) for (uint16_t i = 2; i < packetSize -3; i += 4)
{ {
if (udpIn[i] + arlsOffset < ledCount && udpIn[i] + arlsOffset >= 0) if (udpIn[i] + arlsOffset < ledCount && udpIn[i] + arlsOffset >= 0)
if (useGammaCorrectionRGB) if (useGammaCorrectionRGB)
@ -133,10 +172,10 @@ void handleNotifications()
strip.setPixelColor(udpIn[i] + arlsOffset, udpIn[i+1], udpIn[i+2], udpIn[i+3]); strip.setPixelColor(udpIn[i] + arlsOffset, udpIn[i+1], udpIn[i+2], udpIn[i+3]);
} }
} }
} else if (udpIn[0] == 2 && receiveDirect) //drgb } else if (udpIn[0] == 2) //drgb
{ {
int id = 0; uint16_t id = 0;
for (int i = 2; i < packetSize -2; i += 3) for (uint16_t i = 2; i < packetSize -2; i += 3)
{ {
if (useGammaCorrectionRGB) if (useGammaCorrectionRGB)
{ {
@ -146,10 +185,10 @@ void handleNotifications()
} }
id++; if (id >= ledCount) break; id++; if (id >= ledCount) break;
} }
} else if (udpIn[0] == 3 && receiveDirect) //drgbw } else if (udpIn[0] == 3) //drgbw
{ {
int id = 0; uint16_t id = 0;
for (int i = 2; i < packetSize -3; i += 4) for (uint16_t i = 2; i < packetSize -3; i += 4)
{ {
if (useGammaCorrectionRGB) if (useGammaCorrectionRGB)
{ {
@ -165,13 +204,6 @@ void handleNotifications()
} }
} }
} }
if (arlsTimeout && millis() > arlsTimeoutTime)
{
strip.unlockAll();
if (bri == 0) strip.setBrightness(0);
arlsTimeout = false;
strip.setMode(effectCurrent);
}
} }