WARLS support added

This commit is contained in:
cschwinne 2017-01-26 23:45:55 +01:00
parent e9ae7c34c7
commit 02443ed697
3 changed files with 50 additions and 24 deletions

View File

@ -17,7 +17,7 @@
#include <Timezone.h>
//to toggle usb serial debug (un)comment following line
#define DEBUG
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x)
@ -35,7 +35,7 @@
* @author Christian Schwinne
*/
//Hardware-settings (only changeble via code)
uint8_t led_amount = 84;
#define LEDCOUNT 84
uint8_t buttonPin = 0; //needs pull-up
//AP and OTA default passwords (change them!)
@ -114,7 +114,7 @@ int nightlightDelayMs;
uint8_t effectCurrent = 0;
uint8_t effectSpeed = 75;
boolean udpConnected = false;
byte udpIn[16];
byte udpIn[LEDCOUNT*4+2];
IPAddress ntpIp;
IPAddress ntpBackupIp(134,130,5,17);
byte ntpBuffer[48];
@ -131,13 +131,15 @@ int overlayPauseDur[6];
int nixieClockI = -1;
boolean nixiePause;
long countdownTime = 1483225200L;
boolean arlsTimeout = false;
long arlsTimeoutTime;
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;
WiFiUDP notifierUdp;
WiFiUDP ntpUdp;
WS2812FX strip = WS2812FX(led_amount, 2, NEO_GRB + NEO_KHZ800);
WS2812FX strip = WS2812FX(LEDCOUNT, 2, NEO_GRB + NEO_KHZ800);
File fsUploadFile;

View File

@ -43,7 +43,7 @@ void saveSettingsToEEPROM()
EEPROM.write(226, notifyDirect);
EEPROM.write(227, apchannel);
EEPROM.write(228, aphide);
EEPROM.write(229, led_amount);
EEPROM.write(229, LEDCOUNT);
EEPROM.write(230, notifyButton);
EEPROM.write(231, notifyNightlight);
EEPROM.write(232, buttonEnabled);
@ -135,7 +135,7 @@ void loadSettingsFromEEPROM()
if (apchannel > 13 || apchannel < 1) apchannel = 1;
aphide = EEPROM.read(228);
if (aphide > 1) aphide = 1;
led_amount = EEPROM.read(229);
//LEDCOUNT = EEPROM.read(229);
notifyButton = EEPROM.read(230);
notifyNightlight = EEPROM.read(231);
buttonEnabled = EEPROM.read(232);

View File

@ -15,7 +15,7 @@ void notify(uint8_t callMode)
default: return;
}
byte udpOut[16];
udpOut[0] = 0; //reserved
udpOut[0] = 0; //0: wled notifier protocol 1: WARLS protocol
udpOut[1] = callMode;
udpOut[2] = bri;
udpOut[3] = col[0];
@ -40,27 +40,51 @@ void handleNotifications()
int packetSize = notifierUdp.parsePacket();
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP())
{
notifierUdp.read(udpIn, 16);
col[0] = udpIn[3];
col[1] = udpIn[4];
col[2] = udpIn[5];
if (udpIn[8] != effectCurrent)
notifierUdp.read(udpIn, packetSize);
if (udpIn[0] == 0) //wled notifier
{
effectCurrent = udpIn[8];
strip.setMode(effectCurrent);
}
if (udpIn[9] != effectSpeed)
col[0] = udpIn[3];
col[1] = udpIn[4];
col[2] = udpIn[5];
if (udpIn[8] != effectCurrent)
{
effectCurrent = udpIn[8];
strip.setMode(effectCurrent);
}
if (udpIn[9] != effectSpeed)
{
effectSpeed = udpIn[9];
strip.setSpeed(effectSpeed);
}
nightlightActive = udpIn[6];
if (!udpIn[6])
{
bri = udpIn[2];
colorUpdated(3);
}
} else if (udpIn[0] == 1) //warls
{
effectSpeed = udpIn[9];
strip.setSpeed(effectSpeed);
}
nightlightActive = udpIn[6];
if (!udpIn[6])
{
bri = udpIn[2];
colorUpdated(3);
if (packetSize > 1) {
if (udpIn[1] == 0)
{
arlsTimeout = false;
} else {
arlsTimeout = true;
arlsTimeoutTime = millis() + 1000*udpIn[1];
}
for (int i = 2; i < packetSize -3; i += 4)
{
if (udpIn[i] < LEDCOUNT)
strip.setIndividual(udpIn[i], ((uint32_t)udpIn[i+1] << 16) | ((uint32_t)udpIn[i+2] << 8) | udpIn[i+3]);
}
}
}
}
if (arlsTimeout && millis() > arlsTimeoutTime)
{
strip.unlockAll();
arlsTimeout = false;
}
}
}