Refactored code to improve readability
Fixed non-2-char indentations
This commit is contained in:
parent
48265bbe02
commit
a5cf553f17
@ -10,33 +10,34 @@
|
||||
//uncomment this if red and green are swapped
|
||||
//#define SWAPRG
|
||||
|
||||
|
||||
//automatically uses the right driver method for each platform
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
#define PIXELMETHOD NeoEsp32BitBangWs2813Method
|
||||
#pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering."
|
||||
#else
|
||||
#define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
|
||||
#endif
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
#define PIXELMETHOD NeoEsp32BitBangWs2813Method
|
||||
#pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering."
|
||||
#else
|
||||
#define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
|
||||
#endif
|
||||
#else //esp8266
|
||||
//autoselect the right method depending on strip pin
|
||||
#if LEDPIN == 2
|
||||
#define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
|
||||
#elif LEDPIN == 3
|
||||
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
|
||||
#else
|
||||
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod
|
||||
#pragma message "Software BitBang will be used because of your selected LED pin. This may cause flicker. Use GPIO 2 or 3 for best results."
|
||||
#endif
|
||||
//autoselect the right method depending on strip pin
|
||||
#if LEDPIN == 2
|
||||
#define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
|
||||
#elif LEDPIN == 3
|
||||
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
|
||||
#else
|
||||
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod
|
||||
#pragma message "Software BitBang will be used because of your selected LED pin. This may cause flicker. Use GPIO 2 or 3 for best results."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//handle swapping Red and Green automatically
|
||||
#ifdef SWAPRG
|
||||
#define PIXELFEATURE3 NeoRgbFeature
|
||||
#define PIXELFEATURE4 NeoRgbwFeature
|
||||
#define PIXELFEATURE3 NeoRgbFeature
|
||||
#define PIXELFEATURE4 NeoRgbwFeature
|
||||
#else
|
||||
#define PIXELFEATURE3 NeoGrbFeature
|
||||
#define PIXELFEATURE4 NeoGrbwFeature
|
||||
#define PIXELFEATURE3 NeoGrbFeature
|
||||
#define PIXELFEATURE4 NeoGrbwFeature
|
||||
#endif
|
||||
|
||||
#include <NeoPixelBrightnessBus.h>
|
||||
@ -53,10 +54,10 @@ class NeoPixelWrapper
|
||||
{
|
||||
public:
|
||||
NeoPixelWrapper() :
|
||||
// initialize each member to null
|
||||
_pGrb(NULL),
|
||||
_pGrbw(NULL),
|
||||
_type(NeoPixelType_None)
|
||||
// initialize each member to null
|
||||
_pGrb(NULL),
|
||||
_pGrbw(NULL),
|
||||
_type(NeoPixelType_None)
|
||||
{
|
||||
|
||||
}
|
||||
@ -71,8 +72,8 @@ public:
|
||||
cleanup();
|
||||
_type = type;
|
||||
|
||||
switch (_type) {
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case NeoPixelType_Grb:
|
||||
_pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN);
|
||||
_pGrb->Begin();
|
||||
@ -88,23 +89,25 @@ public:
|
||||
void Show()
|
||||
{
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
delay(1);
|
||||
portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
|
||||
#endif
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
delay(1);
|
||||
portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
switch (_type) {
|
||||
switch (_type)
|
||||
{
|
||||
case NeoPixelType_Grb: _pGrb->Show(); break;
|
||||
case NeoPixelType_Grbw: _pGrbw->Show(); break;
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
portENABLE_INTERRUPTS();
|
||||
#endif
|
||||
#ifdef WORKAROUND_ESP32_BITBANG
|
||||
portENABLE_INTERRUPTS();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CanShow() const
|
||||
{
|
||||
switch (_type) {
|
||||
@ -113,65 +116,65 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void SetPixelColor(uint16_t indexPixel, RgbColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
|
||||
}
|
||||
void SetPixelColor(uint16_t indexPixel, RgbColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
|
||||
case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
|
||||
}
|
||||
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
|
||||
case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetBrightness(byte b)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
|
||||
}
|
||||
void SetBrightness(byte b)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
|
||||
}
|
||||
}
|
||||
|
||||
RgbColor GetPixelColor(uint16_t indexPixel) const
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
|
||||
case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
|
||||
}
|
||||
return 0;
|
||||
RgbColor GetPixelColor(uint16_t indexPixel) const
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
|
||||
case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// NOTE: Due to feature differences, some support RGBW but the method name
|
||||
// here needs to be unique, thus GetPixeColorRgbw
|
||||
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
|
||||
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
|
||||
}
|
||||
return 0;
|
||||
// NOTE: Due to feature differences, some support RGBW but the method name
|
||||
// here needs to be unique, thus GetPixeColorRgbw
|
||||
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
|
||||
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClearTo(RgbColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
|
||||
}
|
||||
void ClearTo(RgbColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
|
||||
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearTo(RgbwColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: break;
|
||||
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
|
||||
}
|
||||
void ClearTo(RgbwColor color)
|
||||
{
|
||||
switch (_type) {
|
||||
case NeoPixelType_Grb: break;
|
||||
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
NeoPixelType _type;
|
||||
|
@ -67,9 +67,11 @@ void WS2812FX::service() {
|
||||
if(_running || _triggered) {
|
||||
unsigned long now = millis(); // Be aware, millis() rolls over every 49 days
|
||||
bool doShow = false;
|
||||
for(uint8_t i=0; i < _num_segments; i++) {
|
||||
for(uint8_t i=0; i < _num_segments; i++)
|
||||
{
|
||||
_segment_index = i;
|
||||
if(now > SEGMENT_RUNTIME.next_time || _triggered) {
|
||||
if(now > SEGMENT_RUNTIME.next_time || _triggered)
|
||||
{
|
||||
doShow = true;
|
||||
handle_palette();
|
||||
uint16_t delay = (this->*_mode[SEGMENT.mode])();
|
||||
|
@ -40,6 +40,8 @@
|
||||
#define WS2812FX_h
|
||||
|
||||
#include "NpbWrapper.h"
|
||||
|
||||
#define FASTLED_INTERNAL //remove annoying pragma messages
|
||||
#include "FastLED.h"
|
||||
|
||||
#define DEFAULT_BRIGHTNESS (uint8_t)50
|
||||
|
@ -30,29 +30,29 @@
|
||||
//library inclusions
|
||||
#include <Arduino.h>
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include "src/dependencies/webserver/WebServer.h"
|
||||
#include <HTTPClient.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include "src/dependencies/webserver/WebServer.h"
|
||||
#include <HTTPClient.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#endif
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include <WiFiUDP.h>
|
||||
#include <DNSServer.h>
|
||||
#ifndef WLED_DISABLE_OTA
|
||||
#include <ArduinoOTA.h>
|
||||
#include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h"
|
||||
#include <ArduinoOTA.h>
|
||||
#include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h"
|
||||
#endif
|
||||
#include "src/dependencies/time/Time.h"
|
||||
#include "src/dependencies/time/TimeLib.h"
|
||||
#include "src/dependencies/timezone/Timezone.h"
|
||||
#ifndef WLED_DISABLE_BLYNK
|
||||
#include "src/dependencies/blynk/BlynkSimpleEsp.h"
|
||||
#include "src/dependencies/blynk/BlynkSimpleEsp.h"
|
||||
#endif
|
||||
#include "src/dependencies/e131/E131.h"
|
||||
#include "src/dependencies/pubsubclient/PubSubClient.h"
|
||||
@ -63,7 +63,7 @@
|
||||
|
||||
|
||||
//version code in format yymmddb (b = daily build)
|
||||
#define VERSION 1811071
|
||||
#define VERSION 1811091
|
||||
char versionString[] = "0.8.1";
|
||||
|
||||
|
||||
@ -357,6 +357,7 @@ bool auxActive = false, auxActiveBefore = false;
|
||||
|
||||
//alexa udp
|
||||
WiFiUDP alexaUDP;
|
||||
bool alexaUdpConnected = false;
|
||||
IPAddress ipMulti(239, 255, 255, 250);
|
||||
unsigned int portMulti = 1900;
|
||||
String escapedMac;
|
||||
@ -381,16 +382,16 @@ uint16_t olen = 0;
|
||||
|
||||
//server library objects
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
WebServer server(80);
|
||||
WebServer server(80);
|
||||
#else
|
||||
ESP8266WebServer server(80);
|
||||
ESP8266WebServer server(80);
|
||||
#endif
|
||||
HTTPClient* hueClient = NULL;
|
||||
WiFiClient* mqttTCPClient = NULL;
|
||||
PubSubClient* mqtt = NULL;
|
||||
|
||||
#ifndef WLED_DISABLE_OTA
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
#endif
|
||||
|
||||
//udp interface objects
|
||||
@ -417,8 +418,8 @@ WS2812FX strip = WS2812FX();
|
||||
|
||||
//filesystem
|
||||
#ifdef USEFS
|
||||
#include <FS.h>;
|
||||
File fsUploadFile;
|
||||
#include <FS.h>;
|
||||
File fsUploadFile;
|
||||
#endif
|
||||
|
||||
//gamma 2.4 lookup table used for color correction
|
||||
@ -478,64 +479,63 @@ bool oappendi(int i)
|
||||
|
||||
//boot starts here
|
||||
void setup() {
|
||||
wledInit();
|
||||
wledInit();
|
||||
}
|
||||
|
||||
|
||||
//main program loop
|
||||
void loop() {
|
||||
server.handleClient();
|
||||
handleSerial();
|
||||
handleNotifications();
|
||||
handleTransitions();
|
||||
userLoop();
|
||||
server.handleClient();
|
||||
handleSerial();
|
||||
handleNotifications();
|
||||
handleTransitions();
|
||||
userLoop();
|
||||
|
||||
yield();
|
||||
handleButton();
|
||||
handleNetworkTime();
|
||||
if (!onlyAP)
|
||||
{
|
||||
handleAlexa();
|
||||
handleMQTT();
|
||||
}
|
||||
yield();
|
||||
handleButton();
|
||||
handleNetworkTime();
|
||||
if (!onlyAP)
|
||||
{
|
||||
handleAlexa();
|
||||
handleMQTT();
|
||||
}
|
||||
|
||||
handleOverlays();
|
||||
handleOverlays();
|
||||
|
||||
yield();
|
||||
yield();
|
||||
|
||||
|
||||
if (!realtimeActive) //block stuff if WARLS/Adalight is enabled
|
||||
{
|
||||
if (dnsActive) dnsServer.processNextRequest();
|
||||
#ifndef WLED_DISABLE_OTA
|
||||
if (aOtaEnabled) ArduinoOTA.handle();
|
||||
#endif
|
||||
handleNightlight();
|
||||
if (!onlyAP) {
|
||||
handleHue();
|
||||
handleBlynk();
|
||||
}
|
||||
if (briT) strip.service(); //do not update strip if off, prevents flicker on ESP32
|
||||
}
|
||||
|
||||
//DEBUG serial logging
|
||||
#ifdef DEBUG
|
||||
if (millis() - debugTime > 5000)
|
||||
{
|
||||
DEBUG_PRINTLN("---MODULE DEBUG INFO---");
|
||||
DEBUG_PRINT("Runtime: "); DEBUG_PRINTLN(millis());
|
||||
DEBUG_PRINT("Unix time: "); DEBUG_PRINTLN(now());
|
||||
DEBUG_PRINT("Free heap: "); DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||
DEBUG_PRINT("Wifi state: "); DEBUG_PRINTLN(WiFi.status());
|
||||
if (WiFi.status() != lastWifiState)
|
||||
{
|
||||
wifiStateChangedTime = millis();
|
||||
}
|
||||
lastWifiState = WiFi.status();
|
||||
DEBUG_PRINT("State time: "); DEBUG_PRINTLN(wifiStateChangedTime);
|
||||
DEBUG_PRINT("NTP last sync: "); DEBUG_PRINTLN(ntpLastSyncTime);
|
||||
DEBUG_PRINT("Client IP: "); DEBUG_PRINTLN(WiFi.localIP());
|
||||
debugTime = millis();
|
||||
}
|
||||
if (!realtimeActive) //block stuff if WARLS/Adalight is enabled
|
||||
{
|
||||
if (dnsActive) dnsServer.processNextRequest();
|
||||
#ifndef WLED_DISABLE_OTA
|
||||
if (aOtaEnabled) ArduinoOTA.handle();
|
||||
#endif
|
||||
handleNightlight();
|
||||
if (!onlyAP) {
|
||||
handleHue();
|
||||
handleBlynk();
|
||||
}
|
||||
if (briT) strip.service(); //do not update strip if off, prevents flicker on ESP32
|
||||
}
|
||||
|
||||
//DEBUG serial logging
|
||||
#ifdef DEBUG
|
||||
if (millis() - debugTime > 5000)
|
||||
{
|
||||
DEBUG_PRINTLN("---MODULE DEBUG INFO---");
|
||||
DEBUG_PRINT("Runtime: "); DEBUG_PRINTLN(millis());
|
||||
DEBUG_PRINT("Unix time: "); DEBUG_PRINTLN(now());
|
||||
DEBUG_PRINT("Free heap: "); DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||
DEBUG_PRINT("Wifi state: "); DEBUG_PRINTLN(WiFi.status());
|
||||
if (WiFi.status() != lastWifiState)
|
||||
{
|
||||
wifiStateChangedTime = millis();
|
||||
}
|
||||
lastWifiState = WiFi.status();
|
||||
DEBUG_PRINT("State time: "); DEBUG_PRINTLN(wifiStateChangedTime);
|
||||
DEBUG_PRINT("NTP last sync: "); DEBUG_PRINTLN(ntpLastSyncTime);
|
||||
DEBUG_PRINT("Client IP: "); DEBUG_PRINTLN(WiFi.localIP());
|
||||
debugTime = millis();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -2,60 +2,57 @@
|
||||
* Sending XML status files to client
|
||||
*/
|
||||
|
||||
//build XML response to HTTP /win API request
|
||||
void XML_response(bool isHTTP)
|
||||
{
|
||||
olen = 0;
|
||||
oappend("<?xml version = \"1.0\" ?><vs><ac>");
|
||||
if (nightlightActive && nightlightFade)
|
||||
{
|
||||
oappendi(briT);
|
||||
} else
|
||||
{
|
||||
oappendi(bri);
|
||||
}
|
||||
oappend("</ac>");
|
||||
olen = 0;
|
||||
oappend("<?xml version = \"1.0\" ?><vs><ac>");
|
||||
oappendi((nightlightActive && nightlightFade) ? briT : bri);
|
||||
oappend("</ac>");
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
oappend("<cl>");
|
||||
oappendi(col[i]);
|
||||
oappend("</cl>");
|
||||
}
|
||||
oappend("<ns>");
|
||||
oappendi(notifyDirect);
|
||||
oappend("</ns><nr>");
|
||||
oappendi(receiveNotifications);
|
||||
oappend("</nr><nl>");
|
||||
oappendi(nightlightActive);
|
||||
oappend("</nl><nf>");
|
||||
oappendi(nightlightFade);
|
||||
oappend("</nf><nd>");
|
||||
oappendi(nightlightDelayMins);
|
||||
oappend("</nd><nt>");
|
||||
oappendi(nightlightTargetBri);
|
||||
oappend("</nt><fx>");
|
||||
oappendi(effectCurrent);
|
||||
oappend("</fx><sx>");
|
||||
oappendi(effectSpeed);
|
||||
oappend("</sx><ix>");
|
||||
oappendi(effectIntensity);
|
||||
oappend("</ix><fp>");
|
||||
oappendi(effectPalette);
|
||||
oappend("</fp><wv>");
|
||||
if (useRGBW && !autoRGBtoRGBW) {
|
||||
oappendi(white);
|
||||
} else {
|
||||
oappend("-1");
|
||||
}
|
||||
oappend("</wv><md>");
|
||||
oappendi(useHSB);
|
||||
oappend("</md><ds>");
|
||||
oappend(serverDescription);
|
||||
oappend("</ds></vs>");
|
||||
if (isHTTP) server.send(200, "text/xml", obuf);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
oappend("<cl>");
|
||||
oappendi(col[i]);
|
||||
oappend("</cl>");
|
||||
}
|
||||
|
||||
oappend("<ns>");
|
||||
oappendi(notifyDirect);
|
||||
oappend("</ns><nr>");
|
||||
oappendi(receiveNotifications);
|
||||
oappend("</nr><nl>");
|
||||
oappendi(nightlightActive);
|
||||
oappend("</nl><nf>");
|
||||
oappendi(nightlightFade);
|
||||
oappend("</nf><nd>");
|
||||
oappendi(nightlightDelayMins);
|
||||
oappend("</nd><nt>");
|
||||
oappendi(nightlightTargetBri);
|
||||
oappend("</nt><fx>");
|
||||
oappendi(effectCurrent);
|
||||
oappend("</fx><sx>");
|
||||
oappendi(effectSpeed);
|
||||
oappend("</sx><ix>");
|
||||
oappendi(effectIntensity);
|
||||
oappend("</ix><fp>");
|
||||
oappendi(effectPalette);
|
||||
oappend("</fp><wv>");
|
||||
if (useRGBW && !autoRGBtoRGBW) {
|
||||
oappendi(white);
|
||||
} else {
|
||||
oappend("-1");
|
||||
}
|
||||
oappend("</wv><md>");
|
||||
oappendi(useHSB);
|
||||
oappend("</md><ds>");
|
||||
oappend(serverDescription);
|
||||
oappend("</ds></vs>");
|
||||
if (isHTTP) server.send(200, "text/xml", obuf);
|
||||
}
|
||||
|
||||
void sappend(char stype, char* key, int val) //append a setting to string buffer
|
||||
//append a numeric setting to string buffer
|
||||
void sappend(char stype, char* key, int val)
|
||||
{
|
||||
char ds[] = "d.Sf.";
|
||||
|
||||
@ -85,28 +82,30 @@ void sappend(char stype, char* key, int val) //append a setting to string buffer
|
||||
}
|
||||
}
|
||||
|
||||
void sappends(char stype, char* key, char* val) //append a string setting
|
||||
//append a string setting to buffer
|
||||
void sappends(char stype, char* key, char* val)
|
||||
{
|
||||
switch(stype)
|
||||
{
|
||||
case 's': //string (we can interpret val as char*)
|
||||
oappend("d.Sf.");
|
||||
oappend(key);
|
||||
oappend(".value=\"");
|
||||
oappend(val);
|
||||
oappend("\";");
|
||||
break;
|
||||
oappend("d.Sf.");
|
||||
oappend(key);
|
||||
oappend(".value=\"");
|
||||
oappend(val);
|
||||
oappend("\";");
|
||||
break;
|
||||
case 'm': //message
|
||||
oappend("d.getElementsByClassName");
|
||||
oappend(key);
|
||||
oappend(".innerHTML=\"");
|
||||
oappend(val);
|
||||
oappend("\";");
|
||||
break;
|
||||
oappend("d.getElementsByClassName");
|
||||
oappend(key);
|
||||
oappend(".innerHTML=\"");
|
||||
oappend(val);
|
||||
oappend("\";");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void getSettingsJS(byte subPage) //get values for settings form in javascript
|
||||
//get values for settings form in javascript
|
||||
void getSettingsJS(byte subPage)
|
||||
{
|
||||
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec
|
||||
DEBUG_PRINT("settings resp");
|
||||
|
@ -61,7 +61,9 @@ void handleSettingsSet(byte subPage)
|
||||
#endif
|
||||
useRGBW = server.hasArg("EW");
|
||||
autoRGBtoRGBW = server.hasArg("AW");
|
||||
if (server.hasArg("IS")) //ignore settings and save current brightness, colors and fx as default
|
||||
|
||||
//ignore settings and save current brightness, colors and fx as default
|
||||
if (server.hasArg("IS"))
|
||||
{
|
||||
colS[0] = col[0];
|
||||
colS[1] = col[1];
|
||||
@ -170,7 +172,9 @@ void handleSettingsSet(byte subPage)
|
||||
strcpy(alexaInvocationName, server.arg("AI").c_str());
|
||||
notifyAlexa = server.hasArg("SA");
|
||||
|
||||
if (server.hasArg("BK") && !server.arg("BK").equals("Hidden")) {strcpy(blynkApiKey,server.arg("BK").c_str()); initBlynk(blynkApiKey);}
|
||||
if (server.hasArg("BK") && !server.arg("BK").equals("Hidden")) {
|
||||
strcpy(blynkApiKey,server.arg("BK").c_str()); initBlynk(blynkApiKey);
|
||||
}
|
||||
|
||||
strcpy(mqttServer, server.arg("MS").c_str());
|
||||
strcpy(mqttDeviceTopic, server.arg("MD").c_str());
|
||||
@ -209,7 +213,9 @@ void handleSettingsSet(byte subPage)
|
||||
useAMPM = !server.hasArg("CF");
|
||||
currentTimezone = server.arg("TZ").toInt();
|
||||
utcOffsetSecs = server.arg("UO").toInt();
|
||||
if (ntpEnabled && WiFi.status() == WL_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort); //start if not already connected
|
||||
|
||||
//start ntp if not already connected
|
||||
if (ntpEnabled && WiFi.status() == WL_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort);
|
||||
|
||||
if (server.hasArg("OL")){
|
||||
overlayDefault = server.arg("OL").toInt();
|
||||
@ -305,451 +311,453 @@ void handleSettingsSet(byte subPage)
|
||||
|
||||
bool handleSet(String req)
|
||||
{
|
||||
bool effectUpdated = false;
|
||||
if (!(req.indexOf("win") >= 0)) return false;
|
||||
bool effectUpdated = false;
|
||||
if (!(req.indexOf("win") >= 0)) return false;
|
||||
|
||||
int pos = 0;
|
||||
DEBUG_PRINT("API req: ");
|
||||
DEBUG_PRINTLN(req);
|
||||
int pos = 0;
|
||||
DEBUG_PRINT("API req: ");
|
||||
DEBUG_PRINTLN(req);
|
||||
|
||||
//save macro, requires &MS=<slot>(<macro>) format
|
||||
pos = req.indexOf("&MS=");
|
||||
if (pos > 0) {
|
||||
int i = req.substring(pos + 4).toInt();
|
||||
pos = req.indexOf('(') +1;
|
||||
if (pos > 0) {
|
||||
int en = req.indexOf(')');
|
||||
String mc = req.substring(pos);
|
||||
if (en > 0) mc = req.substring(pos, en);
|
||||
saveMacro(i, mc);
|
||||
}
|
||||
//save macro, requires &MS=<slot>(<macro>) format
|
||||
pos = req.indexOf("&MS=");
|
||||
if (pos > 0) {
|
||||
int i = req.substring(pos + 4).toInt();
|
||||
pos = req.indexOf('(') +1;
|
||||
if (pos > 0) {
|
||||
int en = req.indexOf(')');
|
||||
String mc = req.substring(pos);
|
||||
if (en > 0) mc = req.substring(pos, en);
|
||||
saveMacro(i, mc);
|
||||
}
|
||||
|
||||
pos = req.indexOf("IN");
|
||||
if (pos < 1) XML_response(true);
|
||||
return true;
|
||||
//if you save a macro in one request, other commands in that request are ignored due to unwanted behavior otherwise
|
||||
}
|
||||
pos = req.indexOf("IN");
|
||||
if (pos < 1) XML_response(true);
|
||||
return true;
|
||||
//if you save a macro in one request, other commands in that request are ignored due to unwanted behavior otherwise
|
||||
}
|
||||
|
||||
//set brigthness
|
||||
pos = req.indexOf("&A=");
|
||||
if (pos > 0) {
|
||||
bri = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set brigthness
|
||||
pos = req.indexOf("&A=");
|
||||
if (pos > 0) {
|
||||
bri = req.substring(pos + 3).toInt();
|
||||
}
|
||||
|
||||
//set hue
|
||||
pos = req.indexOf("HU=");
|
||||
if (pos > 0) {
|
||||
uint16_t temphue = req.substring(pos + 3).toInt();
|
||||
byte tempsat = 255;
|
||||
pos = req.indexOf("SA=");
|
||||
if (pos > 0) {
|
||||
tempsat = req.substring(pos + 3).toInt();
|
||||
}
|
||||
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
|
||||
}
|
||||
//set hue
|
||||
pos = req.indexOf("HU=");
|
||||
if (pos > 0) {
|
||||
uint16_t temphue = req.substring(pos + 3).toInt();
|
||||
byte tempsat = 255;
|
||||
pos = req.indexOf("SA=");
|
||||
if (pos > 0) {
|
||||
tempsat = req.substring(pos + 3).toInt();
|
||||
}
|
||||
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
|
||||
}
|
||||
|
||||
//set red value
|
||||
pos = req.indexOf("&R=");
|
||||
if (pos > 0) {
|
||||
col[0] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set green value
|
||||
pos = req.indexOf("&G=");
|
||||
if (pos > 0) {
|
||||
col[1] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set blue value
|
||||
pos = req.indexOf("&B=");
|
||||
if (pos > 0) {
|
||||
col[2] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set white value
|
||||
pos = req.indexOf("&W=");
|
||||
if (pos > 0) {
|
||||
white = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set red value
|
||||
pos = req.indexOf("&R=");
|
||||
if (pos > 0) {
|
||||
col[0] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set green value
|
||||
pos = req.indexOf("&G=");
|
||||
if (pos > 0) {
|
||||
col[1] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set blue value
|
||||
pos = req.indexOf("&B=");
|
||||
if (pos > 0) {
|
||||
col[2] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set white value
|
||||
pos = req.indexOf("&W=");
|
||||
if (pos > 0) {
|
||||
white = req.substring(pos + 3).toInt();
|
||||
}
|
||||
|
||||
//set 2nd red value
|
||||
pos = req.indexOf("R2=");
|
||||
if (pos > 0) {
|
||||
colSec[0] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd green value
|
||||
pos = req.indexOf("G2=");
|
||||
if (pos > 0) {
|
||||
colSec[1] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd blue value
|
||||
pos = req.indexOf("B2=");
|
||||
if (pos > 0) {
|
||||
colSec[2] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd white value
|
||||
pos = req.indexOf("W2=");
|
||||
if (pos > 0) {
|
||||
whiteSec = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd red value
|
||||
pos = req.indexOf("R2=");
|
||||
if (pos > 0) {
|
||||
colSec[0] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd green value
|
||||
pos = req.indexOf("G2=");
|
||||
if (pos > 0) {
|
||||
colSec[1] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd blue value
|
||||
pos = req.indexOf("B2=");
|
||||
if (pos > 0) {
|
||||
colSec[2] = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set 2nd white value
|
||||
pos = req.indexOf("W2=");
|
||||
if (pos > 0) {
|
||||
whiteSec = req.substring(pos + 3).toInt();
|
||||
}
|
||||
|
||||
//set color from HEX or 32bit DEC
|
||||
pos = req.indexOf("CL=");
|
||||
if (pos > 0) {
|
||||
colorFromDecOrHexString(col, &white, (char*)req.substring(pos + 3).c_str());
|
||||
}
|
||||
pos = req.indexOf("C2=");
|
||||
if (pos > 0) {
|
||||
colorFromDecOrHexString(colSec, &whiteSec, (char*)req.substring(pos + 3).c_str());
|
||||
}
|
||||
//set color from HEX or 32bit DEC
|
||||
pos = req.indexOf("CL=");
|
||||
if (pos > 0) {
|
||||
colorFromDecOrHexString(col, &white, (char*)req.substring(pos + 3).c_str());
|
||||
}
|
||||
pos = req.indexOf("C2=");
|
||||
if (pos > 0) {
|
||||
colorFromDecOrHexString(colSec, &whiteSec, (char*)req.substring(pos + 3).c_str());
|
||||
}
|
||||
|
||||
//set 2nd to white
|
||||
pos = req.indexOf("SW");
|
||||
if (pos > 0) {
|
||||
if(useRGBW) {
|
||||
whiteSec = 255;
|
||||
colSec[0] = 0;
|
||||
colSec[1] = 0;
|
||||
colSec[2] = 0;
|
||||
} else {
|
||||
colSec[0] = 255;
|
||||
colSec[1] = 255;
|
||||
colSec[2] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
//set 2nd to black
|
||||
pos = req.indexOf("SB");
|
||||
if (pos > 0) {
|
||||
whiteSec = 0;
|
||||
//set 2nd to white
|
||||
pos = req.indexOf("SW");
|
||||
if (pos > 0) {
|
||||
if(useRGBW) {
|
||||
whiteSec = 255;
|
||||
colSec[0] = 0;
|
||||
colSec[1] = 0;
|
||||
colSec[2] = 0;
|
||||
}
|
||||
} else {
|
||||
colSec[0] = 255;
|
||||
colSec[1] = 255;
|
||||
colSec[2] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
//set to random hue SR=0->1st SR=1->2nd
|
||||
pos = req.indexOf("SR");
|
||||
if (pos > 0) {
|
||||
_setRandomColor(req.substring(pos + 3).toInt());
|
||||
}
|
||||
//set 2nd to 1st
|
||||
pos = req.indexOf("SP");
|
||||
if (pos > 0) {
|
||||
colSec[0] = col[0];
|
||||
colSec[1] = col[1];
|
||||
colSec[2] = col[2];
|
||||
whiteSec = white;
|
||||
}
|
||||
//swap 2nd & 1st
|
||||
pos = req.indexOf("SC");
|
||||
if (pos > 0) {
|
||||
byte _temp[4];
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
_temp[i] = col[i];
|
||||
col[i] = colSec[i];
|
||||
colSec[i] = _temp[i];
|
||||
}
|
||||
_temp[3] = white;
|
||||
white = whiteSec;
|
||||
whiteSec = _temp[3];
|
||||
}
|
||||
//set 2nd to black
|
||||
pos = req.indexOf("SB");
|
||||
if (pos > 0) {
|
||||
whiteSec = 0;
|
||||
colSec[0] = 0;
|
||||
colSec[1] = 0;
|
||||
colSec[2] = 0;
|
||||
}
|
||||
|
||||
//set current effect index
|
||||
pos = req.indexOf("FX=");
|
||||
if (pos > 0) {
|
||||
if (effectCurrent != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectCurrent = req.substring(pos + 3).toInt();
|
||||
strip.setMode(effectCurrent);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect speed
|
||||
pos = req.indexOf("SX=");
|
||||
if (pos > 0) {
|
||||
if (effectSpeed != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectSpeed = req.substring(pos + 3).toInt();
|
||||
strip.setSpeed(effectSpeed);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect intensity
|
||||
pos = req.indexOf("IX=");
|
||||
if (pos > 0) {
|
||||
if (effectIntensity != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectIntensity = req.substring(pos + 3).toInt();
|
||||
strip.setIntensity(effectIntensity);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect palette (only for FastLED effects)
|
||||
pos = req.indexOf("FP=");
|
||||
if (pos > 0) {
|
||||
if (effectPalette != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectPalette = req.substring(pos + 3).toInt();
|
||||
strip.setPalette(effectPalette);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set to random hue SR=0->1st SR=1->2nd
|
||||
pos = req.indexOf("SR");
|
||||
if (pos > 0) {
|
||||
_setRandomColor(req.substring(pos + 3).toInt());
|
||||
}
|
||||
//set 2nd to 1st
|
||||
pos = req.indexOf("SP");
|
||||
if (pos > 0) {
|
||||
colSec[0] = col[0];
|
||||
colSec[1] = col[1];
|
||||
colSec[2] = col[2];
|
||||
whiteSec = white;
|
||||
}
|
||||
//swap 2nd & 1st
|
||||
pos = req.indexOf("SC");
|
||||
if (pos > 0) {
|
||||
byte _temp[4];
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
_temp[i] = col[i];
|
||||
col[i] = colSec[i];
|
||||
colSec[i] = _temp[i];
|
||||
}
|
||||
_temp[3] = white;
|
||||
white = whiteSec;
|
||||
whiteSec = _temp[3];
|
||||
}
|
||||
|
||||
//set hue polling light: 0 -off
|
||||
pos = req.indexOf("HP=");
|
||||
if (pos > 0) {
|
||||
int id = req.substring(pos + 3).toInt();
|
||||
if (id > 0)
|
||||
{
|
||||
if (id < 100) huePollLightId = id;
|
||||
setupHue();
|
||||
} else {
|
||||
huePollingEnabled = false;
|
||||
}
|
||||
}
|
||||
//set current effect index
|
||||
pos = req.indexOf("FX=");
|
||||
if (pos > 0) {
|
||||
if (effectCurrent != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectCurrent = req.substring(pos + 3).toInt();
|
||||
strip.setMode(effectCurrent);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect speed
|
||||
pos = req.indexOf("SX=");
|
||||
if (pos > 0) {
|
||||
if (effectSpeed != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectSpeed = req.substring(pos + 3).toInt();
|
||||
strip.setSpeed(effectSpeed);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect intensity
|
||||
pos = req.indexOf("IX=");
|
||||
if (pos > 0) {
|
||||
if (effectIntensity != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectIntensity = req.substring(pos + 3).toInt();
|
||||
strip.setIntensity(effectIntensity);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
//set effect palette (only for FastLED effects)
|
||||
pos = req.indexOf("FP=");
|
||||
if (pos > 0) {
|
||||
if (effectPalette != req.substring(pos + 3).toInt())
|
||||
{
|
||||
effectPalette = req.substring(pos + 3).toInt();
|
||||
strip.setPalette(effectPalette);
|
||||
effectUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
//set default control mode (0 - RGB, 1 - HSB)
|
||||
pos = req.indexOf("MD=");
|
||||
if (pos > 0) {
|
||||
useHSB = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set advanced overlay
|
||||
pos = req.indexOf("OL=");
|
||||
if (pos > 0) {
|
||||
overlayCurrent = req.substring(pos + 3).toInt();
|
||||
strip.unlockAll();
|
||||
}
|
||||
//(un)lock pixel (ranges)
|
||||
pos = req.indexOf("&L=");
|
||||
if (pos > 0){
|
||||
int index = req.substring(pos + 3).toInt();
|
||||
pos = req.indexOf("L2=");
|
||||
if (pos > 0){
|
||||
int index2 = req.substring(pos + 3).toInt();
|
||||
if (req.indexOf("UL") > 0)
|
||||
{
|
||||
strip.unlockRange(index, index2);
|
||||
} else
|
||||
{
|
||||
strip.lockRange(index, index2);
|
||||
}
|
||||
//set hue polling light: 0 -off
|
||||
pos = req.indexOf("HP=");
|
||||
if (pos > 0) {
|
||||
int id = req.substring(pos + 3).toInt();
|
||||
if (id > 0)
|
||||
{
|
||||
if (id < 100) huePollLightId = id;
|
||||
setupHue();
|
||||
} else {
|
||||
huePollingEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//set default control mode (0 - RGB, 1 - HSB)
|
||||
pos = req.indexOf("MD=");
|
||||
if (pos > 0) {
|
||||
useHSB = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//set advanced overlay
|
||||
pos = req.indexOf("OL=");
|
||||
if (pos > 0) {
|
||||
overlayCurrent = req.substring(pos + 3).toInt();
|
||||
strip.unlockAll();
|
||||
}
|
||||
//(un)lock pixel (ranges)
|
||||
pos = req.indexOf("&L=");
|
||||
if (pos > 0){
|
||||
int index = req.substring(pos + 3).toInt();
|
||||
pos = req.indexOf("L2=");
|
||||
if (pos > 0){
|
||||
int index2 = req.substring(pos + 3).toInt();
|
||||
if (req.indexOf("UL") > 0)
|
||||
{
|
||||
strip.unlockRange(index, index2);
|
||||
} else
|
||||
{
|
||||
if (req.indexOf("UL") > 0)
|
||||
{
|
||||
strip.unlock(index);
|
||||
} else
|
||||
{
|
||||
strip.lock(index);
|
||||
}
|
||||
strip.lockRange(index, index2);
|
||||
}
|
||||
}
|
||||
|
||||
//apply macro
|
||||
pos = req.indexOf("&M=");
|
||||
if (pos > 0) {
|
||||
applyMacro(req.substring(pos + 3).toInt());
|
||||
}
|
||||
//toggle send UDP direct notifications
|
||||
if (req.indexOf("SN=") > 0)
|
||||
{
|
||||
notifyDirect = true;
|
||||
if (req.indexOf("SN=0") > 0)
|
||||
} else
|
||||
{
|
||||
if (req.indexOf("UL") > 0)
|
||||
{
|
||||
notifyDirect = false;
|
||||
}
|
||||
}
|
||||
|
||||
//toggle receive UDP direct notifications
|
||||
if (req.indexOf("RN=") > 0)
|
||||
{
|
||||
receiveNotifications = true;
|
||||
if (req.indexOf("RN=0") > 0)
|
||||
strip.unlock(index);
|
||||
} else
|
||||
{
|
||||
receiveNotifications = false;
|
||||
strip.lock(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//toggle nightlight mode
|
||||
bool aNlDef = false;
|
||||
if (req.indexOf("&ND") > 0) aNlDef = true;
|
||||
pos = req.indexOf("NL=");
|
||||
if (pos > 0)
|
||||
{
|
||||
if (req.indexOf("NL=0") > 0)
|
||||
{
|
||||
nightlightActive = false;
|
||||
bri = briT;
|
||||
} else {
|
||||
nightlightActive = true;
|
||||
if (!aNlDef) nightlightDelayMins = req.substring(pos + 3).toInt();
|
||||
nightlightStartTime = millis();
|
||||
}
|
||||
} else if (aNlDef)
|
||||
{
|
||||
//apply macro
|
||||
pos = req.indexOf("&M=");
|
||||
if (pos > 0) {
|
||||
applyMacro(req.substring(pos + 3).toInt());
|
||||
}
|
||||
//toggle send UDP direct notifications
|
||||
if (req.indexOf("SN=") > 0)
|
||||
{
|
||||
notifyDirect = true;
|
||||
if (req.indexOf("SN=0") > 0)
|
||||
{
|
||||
notifyDirect = false;
|
||||
}
|
||||
}
|
||||
|
||||
//toggle receive UDP direct notifications
|
||||
if (req.indexOf("RN=") > 0)
|
||||
{
|
||||
receiveNotifications = true;
|
||||
if (req.indexOf("RN=0") > 0)
|
||||
{
|
||||
receiveNotifications = false;
|
||||
}
|
||||
}
|
||||
|
||||
//toggle nightlight mode
|
||||
bool aNlDef = false;
|
||||
if (req.indexOf("&ND") > 0) aNlDef = true;
|
||||
pos = req.indexOf("NL=");
|
||||
if (pos > 0)
|
||||
{
|
||||
if (req.indexOf("NL=0") > 0)
|
||||
{
|
||||
nightlightActive = false;
|
||||
bri = briT;
|
||||
} else {
|
||||
nightlightActive = true;
|
||||
if (!aNlDef) nightlightDelayMins = req.substring(pos + 3).toInt();
|
||||
nightlightStartTime = millis();
|
||||
}
|
||||
}
|
||||
} else if (aNlDef)
|
||||
{
|
||||
nightlightActive = true;
|
||||
nightlightStartTime = millis();
|
||||
}
|
||||
|
||||
//set nightlight target brightness
|
||||
pos = req.indexOf("NT=");
|
||||
if (pos > 0) {
|
||||
nightlightTargetBri = req.substring(pos + 3).toInt();
|
||||
nightlightActiveOld = false; //re-init
|
||||
}
|
||||
//set nightlight target brightness
|
||||
pos = req.indexOf("NT=");
|
||||
if (pos > 0) {
|
||||
nightlightTargetBri = req.substring(pos + 3).toInt();
|
||||
nightlightActiveOld = false; //re-init
|
||||
}
|
||||
|
||||
//toggle nightlight fade
|
||||
if (req.indexOf("NF=") > 0)
|
||||
{
|
||||
if (req.indexOf("NF=0") > 0)
|
||||
//toggle nightlight fade
|
||||
if (req.indexOf("NF=") > 0)
|
||||
{
|
||||
if (req.indexOf("NF=0") > 0)
|
||||
{
|
||||
nightlightFade = false;
|
||||
} else {
|
||||
nightlightFade = true;
|
||||
}
|
||||
nightlightActiveOld = false; //re-init
|
||||
}
|
||||
|
||||
//toggle general purpose output
|
||||
pos = req.indexOf("AX=");
|
||||
if (pos > 0) {
|
||||
auxTime = req.substring(pos + 3).toInt();
|
||||
auxActive = true;
|
||||
if (auxTime == 0) auxActive = false;
|
||||
}
|
||||
pos = req.indexOf("TT=");
|
||||
if (pos > 0) {
|
||||
transitionDelay = req.substring(pos + 3).toInt();
|
||||
}
|
||||
|
||||
//main toggle on/off
|
||||
pos = req.indexOf("&T=");
|
||||
if (pos > 0) {
|
||||
nightlightActive = false; //always disable nightlight when toggling
|
||||
switch (req.substring(pos + 3).toInt())
|
||||
{
|
||||
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off
|
||||
case 1: bri = briLast; break; //on
|
||||
default: if (bri == 0) //toggle
|
||||
{
|
||||
nightlightFade = false;
|
||||
} else {
|
||||
nightlightFade = true;
|
||||
}
|
||||
nightlightActiveOld = false; //re-init
|
||||
}
|
||||
|
||||
//toggle general purpose output
|
||||
pos = req.indexOf("AX=");
|
||||
if (pos > 0) {
|
||||
auxTime = req.substring(pos + 3).toInt();
|
||||
auxActive = true;
|
||||
if (auxTime == 0) auxActive = false;
|
||||
}
|
||||
pos = req.indexOf("TT=");
|
||||
if (pos > 0) {
|
||||
transitionDelay = req.substring(pos + 3).toInt();
|
||||
}
|
||||
|
||||
//main toggle on/off
|
||||
pos = req.indexOf("&T=");
|
||||
if (pos > 0) {
|
||||
nightlightActive = false; //always disable nightlight when toggling
|
||||
switch (req.substring(pos + 3).toInt())
|
||||
bri = briLast;
|
||||
} else
|
||||
{
|
||||
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off
|
||||
case 1: bri = briLast; break; //on
|
||||
default: if (bri == 0) //toggle
|
||||
{
|
||||
bri = briLast;
|
||||
} else
|
||||
{
|
||||
briLast = bri;
|
||||
bri = 0;
|
||||
}
|
||||
briLast = bri;
|
||||
bri = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//deactivate nightlight if target brightness is reached
|
||||
if (bri == nightlightTargetBri) nightlightActive = false;
|
||||
//set time (unix timestamp)
|
||||
pos = req.indexOf("ST=");
|
||||
if (pos > 0) {
|
||||
setTime(req.substring(pos+3).toInt());
|
||||
}
|
||||
//deactivate nightlight if target brightness is reached
|
||||
if (bri == nightlightTargetBri) nightlightActive = false;
|
||||
//set time (unix timestamp)
|
||||
pos = req.indexOf("ST=");
|
||||
if (pos > 0) {
|
||||
setTime(req.substring(pos+3).toInt());
|
||||
}
|
||||
|
||||
//set countdown goal (unix timestamp)
|
||||
pos = req.indexOf("CT=");
|
||||
if (pos > 0) {
|
||||
countdownTime = req.substring(pos+3).toInt();
|
||||
if (countdownTime - now() > 0) countdownOverTriggered = false;
|
||||
}
|
||||
//set countdown goal (unix timestamp)
|
||||
pos = req.indexOf("CT=");
|
||||
if (pos > 0) {
|
||||
countdownTime = req.substring(pos+3).toInt();
|
||||
if (countdownTime - now() > 0) countdownOverTriggered = false;
|
||||
}
|
||||
|
||||
//set presets
|
||||
pos = req.indexOf("P1="); //sets first preset for cycle
|
||||
if (pos > 0) presetCycleMin = req.substring(pos + 3).toInt();
|
||||
//set presets
|
||||
pos = req.indexOf("P1="); //sets first preset for cycle
|
||||
if (pos > 0) presetCycleMin = req.substring(pos + 3).toInt();
|
||||
|
||||
pos = req.indexOf("P2="); //sets last preset for cycle
|
||||
if (pos > 0) presetCycleMax = req.substring(pos + 3).toInt();
|
||||
pos = req.indexOf("P2="); //sets last preset for cycle
|
||||
if (pos > 0) presetCycleMax = req.substring(pos + 3).toInt();
|
||||
|
||||
if (req.indexOf("CY=") > 0) //preset cycle
|
||||
{
|
||||
presetCyclingEnabled = true;
|
||||
if (req.indexOf("CY=0") > 0)
|
||||
{
|
||||
presetCyclingEnabled = false;
|
||||
}
|
||||
presetCycCurr = presetCycleMin;
|
||||
}
|
||||
pos = req.indexOf("PT="); //sets cycle time in ms
|
||||
if (pos > 0) {
|
||||
int v = req.substring(pos + 3).toInt();
|
||||
if (v > 49) presetCycleTime = v;
|
||||
}
|
||||
if (req.indexOf("PA=") > 0) //apply brightness from preset
|
||||
{
|
||||
presetApplyBri = true;
|
||||
if (req.indexOf("PA=0") > 0) presetApplyBri = false;
|
||||
}
|
||||
if (req.indexOf("PC=") > 0) //apply color from preset
|
||||
{
|
||||
presetApplyCol = true;
|
||||
if (req.indexOf("PC=0") > 0) presetApplyCol = false;
|
||||
}
|
||||
if (req.indexOf("PX=") > 0) //apply effects from preset
|
||||
{
|
||||
presetApplyFx = true;
|
||||
if (req.indexOf("PX=0") > 0) presetApplyFx = false;
|
||||
}
|
||||
pos = req.indexOf("PS="); //saves current in preset
|
||||
if (pos > 0) {
|
||||
savePreset(req.substring(pos + 3).toInt());
|
||||
}
|
||||
pos = req.indexOf("PL="); //applies entire preset
|
||||
if (pos > 0) {
|
||||
applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx);
|
||||
if (presetApplyFx) effectUpdated = true;
|
||||
}
|
||||
if (req.indexOf("CY=") > 0) //preset cycle
|
||||
{
|
||||
presetCyclingEnabled = true;
|
||||
if (req.indexOf("CY=0") > 0)
|
||||
{
|
||||
presetCyclingEnabled = false;
|
||||
}
|
||||
presetCycCurr = presetCycleMin;
|
||||
}
|
||||
pos = req.indexOf("PT="); //sets cycle time in ms
|
||||
if (pos > 0) {
|
||||
int v = req.substring(pos + 3).toInt();
|
||||
if (v > 49) presetCycleTime = v;
|
||||
}
|
||||
if (req.indexOf("PA=") > 0) //apply brightness from preset
|
||||
{
|
||||
presetApplyBri = true;
|
||||
if (req.indexOf("PA=0") > 0) presetApplyBri = false;
|
||||
}
|
||||
if (req.indexOf("PC=") > 0) //apply color from preset
|
||||
{
|
||||
presetApplyCol = true;
|
||||
if (req.indexOf("PC=0") > 0) presetApplyCol = false;
|
||||
}
|
||||
if (req.indexOf("PX=") > 0) //apply effects from preset
|
||||
{
|
||||
presetApplyFx = true;
|
||||
if (req.indexOf("PX=0") > 0) presetApplyFx = false;
|
||||
}
|
||||
|
||||
//cronixie
|
||||
pos = req.indexOf("NX="); //sets digits to code
|
||||
if (pos > 0) {
|
||||
strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str());
|
||||
setCronixie();
|
||||
}
|
||||
pos = req.indexOf("NM="); //mode, 1 countdown
|
||||
if (pos > 0) {
|
||||
countdownMode = true;
|
||||
if (req.indexOf("NM=0") > 0)
|
||||
{
|
||||
countdownMode = false;
|
||||
}
|
||||
}
|
||||
if (req.indexOf("NB=") > 0) //sets backlight
|
||||
{
|
||||
cronixieBacklight = true;
|
||||
if (req.indexOf("NB=0") > 0)
|
||||
{
|
||||
cronixieBacklight = false;
|
||||
}
|
||||
if (overlayCurrent == 3) strip.setCronixieBacklight(cronixieBacklight);
|
||||
overlayRefreshedTime = 0;
|
||||
}
|
||||
pos = req.indexOf("U0="); //user var 0
|
||||
if (pos > 0) {
|
||||
userVar0 = req.substring(pos + 3).toInt();
|
||||
}
|
||||
pos = req.indexOf("U1="); //user var 1
|
||||
if (pos > 0) {
|
||||
userVar1 = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//you can add more if you need
|
||||
pos = req.indexOf("PS="); //saves current in preset
|
||||
if (pos > 0) {
|
||||
savePreset(req.substring(pos + 3).toInt());
|
||||
}
|
||||
pos = req.indexOf("PL="); //applies entire preset
|
||||
if (pos > 0) {
|
||||
applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx);
|
||||
if (presetApplyFx) effectUpdated = true;
|
||||
}
|
||||
|
||||
//internal call, does not send XML response
|
||||
pos = req.indexOf("IN");
|
||||
if (pos < 1) XML_response(true);
|
||||
//do not send UDP notifications this time
|
||||
pos = req.indexOf("NN");
|
||||
if (pos > 0)
|
||||
{
|
||||
colorUpdated(5);
|
||||
return true;
|
||||
}
|
||||
if (effectUpdated)
|
||||
{
|
||||
colorUpdated(6);
|
||||
} else
|
||||
{
|
||||
colorUpdated(1);
|
||||
}
|
||||
return true;
|
||||
//cronixie
|
||||
pos = req.indexOf("NX="); //sets digits to code
|
||||
if (pos > 0) {
|
||||
strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str());
|
||||
setCronixie();
|
||||
}
|
||||
pos = req.indexOf("NM="); //mode, 1 countdown
|
||||
if (pos > 0) {
|
||||
countdownMode = true;
|
||||
if (req.indexOf("NM=0") > 0)
|
||||
{
|
||||
countdownMode = false;
|
||||
}
|
||||
}
|
||||
if (req.indexOf("NB=") > 0) //sets backlight
|
||||
{
|
||||
cronixieBacklight = true;
|
||||
if (req.indexOf("NB=0") > 0)
|
||||
{
|
||||
cronixieBacklight = false;
|
||||
}
|
||||
if (overlayCurrent == 3) strip.setCronixieBacklight(cronixieBacklight);
|
||||
overlayRefreshedTime = 0;
|
||||
}
|
||||
|
||||
pos = req.indexOf("U0="); //user var 0
|
||||
if (pos > 0) {
|
||||
userVar0 = req.substring(pos + 3).toInt();
|
||||
}
|
||||
pos = req.indexOf("U1="); //user var 1
|
||||
if (pos > 0) {
|
||||
userVar1 = req.substring(pos + 3).toInt();
|
||||
}
|
||||
//you can add more if you need
|
||||
|
||||
//internal call, does not send XML response
|
||||
pos = req.indexOf("IN");
|
||||
if (pos < 1) XML_response(true);
|
||||
//do not send UDP notifications this time
|
||||
pos = req.indexOf("NN");
|
||||
if (pos > 0)
|
||||
{
|
||||
colorUpdated(5);
|
||||
return true;
|
||||
}
|
||||
if (effectUpdated)
|
||||
{
|
||||
colorUpdated(6);
|
||||
} else
|
||||
{
|
||||
colorUpdated(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -3,36 +3,37 @@
|
||||
*/
|
||||
void handleSerial()
|
||||
{
|
||||
if (Serial.available() > 0) //support for Adalight protocol to high-speed control LEDs over serial (gamma correction done by PC)
|
||||
if (Serial.available() > 0) //support for Adalight protocol to high-speed control LEDs over serial
|
||||
{
|
||||
if (Serial.find("Ada"))
|
||||
if (!Serial.find("Ada")) return;
|
||||
|
||||
if (!realtimeActive && bri == 0) strip.setBrightness(briLast);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
|
||||
delay(1);
|
||||
byte hi = Serial.read();
|
||||
byte ledc = Serial.read();
|
||||
byte chk = Serial.read();
|
||||
if(chk != (hi ^ ledc ^ 0x55)) return;
|
||||
if (ledCount < ledc) ledc = ledCount;
|
||||
|
||||
byte sc[3]; int t =-1; int to = 0;
|
||||
for (int i=0; i < ledc; i++)
|
||||
{
|
||||
if (!realtimeActive && bri == 0) strip.setBrightness(briLast);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
delay(1);
|
||||
byte hi = Serial.read();
|
||||
byte ledc = Serial.read();
|
||||
byte chk = Serial.read();
|
||||
if(chk != (hi ^ ledc ^ 0x55)) return;
|
||||
if (ledCount < ledc) ledc = ledCount;
|
||||
byte sc[3]; int t =-1; int to = 0;
|
||||
for (int i=0; i < ledc; i++)
|
||||
for (byte j=0; j<3; j++)
|
||||
{
|
||||
for (byte j=0; j<3; j++)
|
||||
while (Serial.peek()<0) //no data yet available
|
||||
{
|
||||
while (Serial.peek()<0) //no data yet available
|
||||
{
|
||||
delay(1);
|
||||
to++;
|
||||
if (to>5) {strip.show(); return;} //unexpected end of transmission
|
||||
}
|
||||
to = 0;
|
||||
sc[j] = Serial.read();
|
||||
delay(1);
|
||||
to++;
|
||||
if (to>5) {strip.show(); return;} //unexpected end of transmission
|
||||
}
|
||||
setRealtimePixel(i,sc[0],sc[1],sc[2],0);
|
||||
to = 0;
|
||||
sc[j] = Serial.read();
|
||||
}
|
||||
strip.show();
|
||||
setRealtimePixel(i,sc[0],sc[1],sc[2],0);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ void wledInit()
|
||||
ledCount = ((EEPROM.read(229) << 0) & 0xFF) + ((EEPROM.read(398) << 8) & 0xFF00); if (ledCount > 1200 || ledCount == 0) ledCount = 10;
|
||||
//RMT eats up too much RAM
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (ledCount > 600) ledCount = 600;
|
||||
if (ledCount > 600) ledCount = 600;
|
||||
#endif
|
||||
if (!EEPROM.read(397)) strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //quick init
|
||||
|
||||
@ -16,7 +16,7 @@ void wledInit()
|
||||
Serial.setTimeout(50);
|
||||
|
||||
#ifdef USEFS
|
||||
SPIFFS.begin();
|
||||
SPIFFS.begin();
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTLN("Load EEPROM");
|
||||
@ -139,7 +139,9 @@ void initStrip()
|
||||
|
||||
if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true);
|
||||
colorUpdated(0);
|
||||
if(digitalRead(buttonPin) == LOW) buttonEnabled = false; //disable button if it is "pressed" unintentionally
|
||||
|
||||
//disable button if it is "pressed" unintentionally
|
||||
if(digitalRead(buttonPin) == LOW) buttonEnabled = false;
|
||||
|
||||
}
|
||||
|
||||
@ -173,13 +175,14 @@ void initCon()
|
||||
WiFi.softAPdisconnect(true);
|
||||
}
|
||||
int fail_count = 0;
|
||||
if (strlen(clientSSID) <1 || strcmp(clientSSID,"Your_Network") == 0) fail_count = apWaitTimeSecs*2; //instantly go to ap mode
|
||||
if (strlen(clientSSID) <1 || strcmp(clientSSID,"Your_Network") == 0)
|
||||
fail_count = apWaitTimeSecs*2; //instantly go to ap mode
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
WiFi.hostname(serverDescription);
|
||||
WiFi.hostname(serverDescription);
|
||||
#endif
|
||||
WiFi.begin(clientSSID, clientPass);
|
||||
WiFi.begin(clientSSID, clientPass);
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
WiFi.setHostname(serverDescription);
|
||||
WiFi.setHostname(serverDescription);
|
||||
#endif
|
||||
unsigned long lastTry = 0;
|
||||
bool con = false;
|
||||
@ -211,9 +214,9 @@ void initCon()
|
||||
}
|
||||
|
||||
|
||||
//fill string buffer with build info
|
||||
void getBuildInfo()
|
||||
{
|
||||
//fill string buffer with build info
|
||||
olen = 0;
|
||||
oappend("hard-coded build info:\r\n\n");
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
@ -118,135 +118,136 @@ void handleNotifications()
|
||||
}
|
||||
|
||||
//receive UDP notifications
|
||||
if(udpConnected && (receiveNotifications || receiveDirect)){
|
||||
uint16_t packetSize = notifierUdp.parsePacket();
|
||||
if (!udpConnected || !(receiveNotifications || receiveDirect)) return;
|
||||
|
||||
//hyperion / raw RGB
|
||||
if (!packetSize && udpRgbConnected) {
|
||||
packetSize = rgbUdp.parsePacket();
|
||||
if (!receiveDirect) return;
|
||||
if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) return;
|
||||
realtimeIP = rgbUdp.remoteIP();
|
||||
DEBUG_PRINTLN(rgbUdp.remoteIP());
|
||||
olen = 0;
|
||||
rgbUdp.read(obuf, packetSize);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 0; i < packetSize -2; i += 3)
|
||||
{
|
||||
setRealtimePixel(id, obuf[i], obuf[i+1], obuf[i+2], 0);
|
||||
uint16_t packetSize = notifierUdp.parsePacket();
|
||||
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
strip.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (packetSize > UDP_IN_MAXSIZE) return;
|
||||
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves
|
||||
//hyperion / raw RGB
|
||||
if (!packetSize && udpRgbConnected) {
|
||||
packetSize = rgbUdp.parsePacket();
|
||||
if (!receiveDirect) return;
|
||||
if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) return;
|
||||
realtimeIP = rgbUdp.remoteIP();
|
||||
DEBUG_PRINTLN(rgbUdp.remoteIP());
|
||||
olen = 0;
|
||||
rgbUdp.read(obuf, packetSize);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 0; i < packetSize -2; i += 3)
|
||||
{
|
||||
olen = 0;
|
||||
notifierUdp.read(obuf, packetSize);
|
||||
char* udpIn = obuf;
|
||||
setRealtimePixel(id, obuf[i], obuf[i+1], obuf[i+2], 0);
|
||||
|
||||
if (udpIn[0] == 0 && !realtimeActive && receiveNotifications) //wled notifier, block if realtime packets active
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
strip.show();
|
||||
return;
|
||||
}
|
||||
|
||||
//notifier and UDP realtime
|
||||
if (packetSize > UDP_IN_MAXSIZE) return;
|
||||
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) //don't process broadcasts we send ourselves
|
||||
{
|
||||
olen = 0;
|
||||
notifierUdp.read(obuf, packetSize);
|
||||
char* udpIn = obuf;
|
||||
|
||||
if (udpIn[0] == 0 && !realtimeActive && receiveNotifications) //wled notifier, block if realtime packets active
|
||||
{
|
||||
if (receiveNotificationColor)
|
||||
{
|
||||
if (receiveNotificationColor)
|
||||
{
|
||||
col[0] = udpIn[3];
|
||||
col[1] = udpIn[4];
|
||||
col[2] = udpIn[5];
|
||||
}
|
||||
if (udpIn[11] > 0 && receiveNotificationColor) //check if sending modules white val is inteded
|
||||
{
|
||||
white = udpIn[10];
|
||||
if (udpIn[11] > 1 )
|
||||
{
|
||||
colSec[0] = udpIn[12];
|
||||
colSec[1] = udpIn[13];
|
||||
colSec[2] = udpIn[14];
|
||||
whiteSec = udpIn[15];
|
||||
}
|
||||
}
|
||||
if (udpIn[8] != effectCurrent && receiveNotificationEffects)
|
||||
{
|
||||
effectCurrent = udpIn[8];
|
||||
strip.setMode(effectCurrent);
|
||||
}
|
||||
if (udpIn[9] != effectSpeed && receiveNotificationEffects)
|
||||
{
|
||||
effectSpeed = udpIn[9];
|
||||
strip.setSpeed(effectSpeed);
|
||||
}
|
||||
if (udpIn[11] > 2 && udpIn[16] != effectIntensity && receiveNotificationEffects)
|
||||
{
|
||||
effectIntensity = udpIn[16];
|
||||
strip.setIntensity(effectIntensity);
|
||||
}
|
||||
if (udpIn[11] > 3)
|
||||
{
|
||||
transitionDelayTemp = ((udpIn[17] << 0) & 0xFF) + ((udpIn[18] << 8) & 0xFF00);
|
||||
}
|
||||
if (udpIn[11] > 4 && udpIn[19] != effectPalette && receiveNotificationEffects)
|
||||
{
|
||||
effectPalette = udpIn[19];
|
||||
strip.setPalette(effectPalette);
|
||||
}
|
||||
nightlightActive = udpIn[6];
|
||||
if (!nightlightActive)
|
||||
{
|
||||
if (receiveNotificationBrightness) bri = udpIn[2];
|
||||
colorUpdated(3);
|
||||
}
|
||||
} else if (udpIn[0] > 0 && udpIn[0] < 4 && receiveDirect) //1 warls //2 drgb //3 drgbw
|
||||
col[0] = udpIn[3];
|
||||
col[1] = udpIn[4];
|
||||
col[2] = udpIn[5];
|
||||
}
|
||||
if (udpIn[11] > 0 && receiveNotificationColor) //check if sending modules white val is inteded
|
||||
{
|
||||
realtimeIP = notifierUdp.remoteIP();
|
||||
DEBUG_PRINTLN(notifierUdp.remoteIP());
|
||||
if (packetSize > 1) {
|
||||
if (udpIn[1] == 0)
|
||||
{
|
||||
realtimeActive = false;
|
||||
return;
|
||||
} else {
|
||||
arlsLock(udpIn[1]*1000);
|
||||
}
|
||||
if (udpIn[0] == 1) //warls
|
||||
{
|
||||
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
||||
{
|
||||
setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0);
|
||||
}
|
||||
} else if (udpIn[0] == 2) //drgb
|
||||
{
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 2; i < packetSize -2; i += 3)
|
||||
{
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
|
||||
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
} else if (udpIn[0] == 3) //drgbw
|
||||
{
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
||||
{
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
|
||||
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
} else if (udpIn[0] == 4) //dnrgb
|
||||
{
|
||||
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
|
||||
for (uint16_t i = 4; i < packetSize -2; i += 3)
|
||||
{
|
||||
if (id >= ledCount) break;
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
|
||||
id++;
|
||||
}
|
||||
}
|
||||
strip.show();
|
||||
white = udpIn[10];
|
||||
if (udpIn[11] > 1 )
|
||||
{
|
||||
colSec[0] = udpIn[12];
|
||||
colSec[1] = udpIn[13];
|
||||
colSec[2] = udpIn[14];
|
||||
whiteSec = udpIn[15];
|
||||
}
|
||||
}
|
||||
if (udpIn[8] != effectCurrent && receiveNotificationEffects)
|
||||
{
|
||||
effectCurrent = udpIn[8];
|
||||
strip.setMode(effectCurrent);
|
||||
}
|
||||
if (udpIn[9] != effectSpeed && receiveNotificationEffects)
|
||||
{
|
||||
effectSpeed = udpIn[9];
|
||||
strip.setSpeed(effectSpeed);
|
||||
}
|
||||
if (udpIn[11] > 2 && udpIn[16] != effectIntensity && receiveNotificationEffects)
|
||||
{
|
||||
effectIntensity = udpIn[16];
|
||||
strip.setIntensity(effectIntensity);
|
||||
}
|
||||
if (udpIn[11] > 3)
|
||||
{
|
||||
transitionDelayTemp = ((udpIn[17] << 0) & 0xFF) + ((udpIn[18] << 8) & 0xFF00);
|
||||
}
|
||||
if (udpIn[11] > 4 && udpIn[19] != effectPalette && receiveNotificationEffects)
|
||||
{
|
||||
effectPalette = udpIn[19];
|
||||
strip.setPalette(effectPalette);
|
||||
}
|
||||
nightlightActive = udpIn[6];
|
||||
if (!nightlightActive)
|
||||
{
|
||||
if (receiveNotificationBrightness) bri = udpIn[2];
|
||||
colorUpdated(3);
|
||||
}
|
||||
} else if (udpIn[0] > 0 && udpIn[0] < 4 && receiveDirect) //1 warls //2 drgb //3 drgbw
|
||||
{
|
||||
realtimeIP = notifierUdp.remoteIP();
|
||||
DEBUG_PRINTLN(notifierUdp.remoteIP());
|
||||
if (packetSize > 1) {
|
||||
if (udpIn[1] == 0)
|
||||
{
|
||||
realtimeActive = false;
|
||||
return;
|
||||
} else {
|
||||
arlsLock(udpIn[1]*1000);
|
||||
}
|
||||
if (udpIn[0] == 1) //warls
|
||||
{
|
||||
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
||||
{
|
||||
setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0);
|
||||
}
|
||||
} else if (udpIn[0] == 2) //drgb
|
||||
{
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 2; i < packetSize -2; i += 3)
|
||||
{
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
|
||||
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
} else if (udpIn[0] == 3) //drgbw
|
||||
{
|
||||
uint16_t id = 0;
|
||||
for (uint16_t i = 2; i < packetSize -3; i += 4)
|
||||
{
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
|
||||
|
||||
id++; if (id >= ledCount) break;
|
||||
}
|
||||
} else if (udpIn[0] == 4) //dnrgb
|
||||
{
|
||||
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
|
||||
for (uint16_t i = 4; i < packetSize -2; i += 3)
|
||||
{
|
||||
if (id >= ledCount) break;
|
||||
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
|
||||
id++;
|
||||
}
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ void handleNightlight()
|
||||
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
|
||||
if (nightlightFade)
|
||||
{
|
||||
bri = briNlT+((nightlightTargetBri - briNlT)*nper);
|
||||
bri = briNlT + ((nightlightTargetBri - briNlT)*nper);
|
||||
colorUpdated(5);
|
||||
}
|
||||
if (nper >= 1)
|
||||
|
@ -16,33 +16,28 @@ void alexaInit()
|
||||
{
|
||||
if (alexaEnabled && WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
udpConnected = connectUDP();
|
||||
alexaUdpConnected = connectUDP();
|
||||
|
||||
if (udpConnected) alexaInitPages();
|
||||
if (alexaUdpConnected) alexaInitPages();
|
||||
}
|
||||
}
|
||||
|
||||
void handleAlexa()
|
||||
{
|
||||
if (alexaEnabled && WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
if(udpConnected){
|
||||
// if there’s data available, read a packet
|
||||
int packetSize = alexaUDP.parsePacket();
|
||||
if(packetSize>0) {
|
||||
IPAddress remote = alexaUDP.remoteIP();
|
||||
int len = alexaUDP.read(obuf, 254);
|
||||
if (len > 0) {
|
||||
obuf[len] = 0;
|
||||
}
|
||||
if (!alexaEnabled || WiFi.status() != WL_CONNECTED || !alexaUdpConnected) return;
|
||||
|
||||
if(strstr(obuf,"M-SEARCH") > 0) {
|
||||
if(strstr(obuf,"upnp:rootdevice") > 0 || strstr(obuf,"device:basic:1") > 0) {
|
||||
DEBUG_PRINTLN("Responding search req...");
|
||||
respondToSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
// if there's data available, read a packet
|
||||
int packetSize = alexaUDP.parsePacket();
|
||||
if(packetSize < 1) return;
|
||||
|
||||
IPAddress remote = alexaUDP.remoteIP();
|
||||
int len = alexaUDP.read(obuf, 254);
|
||||
if (len > 0) obuf[len] = 0;
|
||||
|
||||
if(strstr(obuf,"M-SEARCH") > 0) {
|
||||
if(strstr(obuf,"upnp:rootdevice") > 0 || strstr(obuf,"device:basic:1") > 0) {
|
||||
DEBUG_PRINTLN("Responding search req...");
|
||||
respondToSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,126 +89,125 @@ void alexaDim(byte briL)
|
||||
}
|
||||
|
||||
void respondToSearch() {
|
||||
DEBUG_PRINTLN("");
|
||||
DEBUG_PRINT("Send resp to ");
|
||||
DEBUG_PRINTLN(alexaUDP.remoteIP());
|
||||
DEBUG_PRINT("Port : ");
|
||||
DEBUG_PRINTLN(alexaUDP.remotePort());
|
||||
DEBUG_PRINTLN("");
|
||||
DEBUG_PRINT("Send resp to ");
|
||||
DEBUG_PRINTLN(alexaUDP.remoteIP());
|
||||
DEBUG_PRINT("Port : ");
|
||||
DEBUG_PRINTLN(alexaUDP.remotePort());
|
||||
|
||||
IPAddress localIP = WiFi.localIP();
|
||||
char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
|
||||
|
||||
olen = 0;
|
||||
oappend(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"EXT:\r\n"
|
||||
"CACHE-CONTROL: max-age=100\r\n" // SSDP_INTERVAL
|
||||
"LOCATION: http://");
|
||||
oappend(s);
|
||||
oappend(":80/description.xml\r\n"
|
||||
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.17.0\r\n" // _modelName, _modelNumber
|
||||
"hue-bridgeid: ");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("\r\n"
|
||||
"ST: urn:schemas-upnp-org:device:basic:1\r\n" // _deviceType
|
||||
"USN: uuid:2f402f80-da50-11e1-9b23-");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("::upnp:rootdevice\r\n" // _uuid::_deviceType
|
||||
"\r\n");
|
||||
|
||||
alexaUDP.beginPacket(alexaUDP.remoteIP(), alexaUDP.remotePort());
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
alexaUDP.write((byte*)obuf, olen);
|
||||
#else
|
||||
alexaUDP.write(obuf);
|
||||
#endif
|
||||
alexaUDP.endPacket();
|
||||
|
||||
DEBUG_PRINTLN("Response sent!");
|
||||
}
|
||||
|
||||
void alexaInitPages() {
|
||||
|
||||
server.on("/description.xml", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN(" # Responding to description.xml ... #\n");
|
||||
|
||||
IPAddress localIP = WiFi.localIP();
|
||||
char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
|
||||
|
||||
olen = 0;
|
||||
oappend(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"EXT:\r\n"
|
||||
"CACHE-CONTROL: max-age=100\r\n" // SSDP_INTERVAL
|
||||
"LOCATION: http://");
|
||||
oappend(s);
|
||||
oappend(":80/description.xml\r\n"
|
||||
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.17.0\r\n" // _modelName, _modelNumber
|
||||
"hue-bridgeid: ");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("\r\n"
|
||||
"ST: urn:schemas-upnp-org:device:basic:1\r\n" // _deviceType
|
||||
"USN: uuid:2f402f80-da50-11e1-9b23-");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("::upnp:rootdevice\r\n" // _uuid::_deviceType
|
||||
"\r\n");
|
||||
|
||||
alexaUDP.beginPacket(alexaUDP.remoteIP(), alexaUDP.remotePort());
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
alexaUDP.write((byte*)obuf, olen);
|
||||
#else
|
||||
alexaUDP.write(obuf);
|
||||
#endif
|
||||
alexaUDP.endPacket();
|
||||
|
||||
DEBUG_PRINTLN("Response sent!");
|
||||
}
|
||||
|
||||
void alexaInitPages() {
|
||||
|
||||
server.on("/description.xml", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN(" # Responding to description.xml ... #\n");
|
||||
|
||||
IPAddress localIP = WiFi.localIP();
|
||||
char s[16];
|
||||
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
|
||||
|
||||
olen = 0;
|
||||
oappend("<?xml version=\"1.0\" ?>"
|
||||
oappend("<?xml version=\"1.0\" ?>"
|
||||
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
|
||||
"<specVersion><major>1</major><minor>0</minor></specVersion>"
|
||||
"<URLBase>http://");
|
||||
oappend(s);
|
||||
oappend(":80/</URLBase>"
|
||||
oappend(s);
|
||||
oappend(":80/</URLBase>"
|
||||
"<device>"
|
||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||
"<friendlyName>Philips hue (");
|
||||
oappend(s);
|
||||
oappend(")</friendlyName>"
|
||||
"<manufacturer>Royal Philips Electronics</manufacturer>"
|
||||
"<manufacturerURL>http://www.philips.com</manufacturerURL>"
|
||||
"<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>"
|
||||
"<modelName>Philips hue bridge 2012</modelName>"
|
||||
"<modelNumber>929000226503</modelNumber>"
|
||||
"<modelURL>http://www.meethue.com</modelURL>"
|
||||
"<serialNumber>");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("</serialNumber>"
|
||||
"<UDN>uuid:2f402f80-da50-11e1-9b23-");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("</UDN>"
|
||||
"<presentationURL>index.html</presentationURL>"
|
||||
"<iconList>"
|
||||
" <icon>"
|
||||
" <mimetype>image/png</mimetype>"
|
||||
" <height>48</height>"
|
||||
" <width>48</width>"
|
||||
" <depth>24</depth>"
|
||||
" <url>hue_logo_0.png</url>"
|
||||
" </icon>"
|
||||
" <icon>"
|
||||
" <mimetype>image/png</mimetype>"
|
||||
" <height>120</height>"
|
||||
" <width>120</width>"
|
||||
" <depth>24</depth>"
|
||||
" <url>hue_logo_3.png</url>"
|
||||
" </icon>"
|
||||
"</iconList>"
|
||||
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
|
||||
"<friendlyName>Philips hue (");
|
||||
oappend(s);
|
||||
oappend(")</friendlyName>"
|
||||
"<manufacturer>Royal Philips Electronics</manufacturer>"
|
||||
"<manufacturerURL>http://www.philips.com</manufacturerURL>"
|
||||
"<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>"
|
||||
"<modelName>Philips hue bridge 2012</modelName>"
|
||||
"<modelNumber>929000226503</modelNumber>"
|
||||
"<modelURL>http://www.meethue.com</modelURL>"
|
||||
"<serialNumber>");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("</serialNumber>"
|
||||
"<UDN>uuid:2f402f80-da50-11e1-9b23-");
|
||||
oappend((char*)escapedMac.c_str());
|
||||
oappend("</UDN>"
|
||||
"<presentationURL>index.html</presentationURL>"
|
||||
"<iconList>"
|
||||
" <icon>"
|
||||
" <mimetype>image/png</mimetype>"
|
||||
" <height>48</height>"
|
||||
" <width>48</width>"
|
||||
" <depth>24</depth>"
|
||||
" <url>hue_logo_0.png</url>"
|
||||
" </icon>"
|
||||
" <icon>"
|
||||
" <mimetype>image/png</mimetype>"
|
||||
" <height>120</height>"
|
||||
" <width>120</width>"
|
||||
" <depth>24</depth>"
|
||||
" <url>hue_logo_3.png</url>"
|
||||
" </icon>"
|
||||
"</iconList>"
|
||||
"</device>"
|
||||
"</root>");
|
||||
|
||||
server.send(200, "text/xml", obuf);
|
||||
server.send(200, "text/xml", obuf);
|
||||
|
||||
DEBUG_PRINTLN("Sending setup_xml");
|
||||
});
|
||||
DEBUG_PRINTLN("Sending setup_xml");
|
||||
});
|
||||
|
||||
// openHAB support
|
||||
server.on("/on.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("on req");
|
||||
server.send(200, "text/plain", "turned on");
|
||||
alexaOn();
|
||||
});
|
||||
// openHAB support
|
||||
server.on("/on.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("on req");
|
||||
server.send(200, "text/plain", "turned on");
|
||||
alexaOn();
|
||||
});
|
||||
|
||||
server.on("/off.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("off req");
|
||||
server.send(200, "text/plain", "turned off");
|
||||
alexaOff();
|
||||
});
|
||||
server.on("/off.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("off req");
|
||||
server.send(200, "text/plain", "turned off");
|
||||
alexaOff();
|
||||
});
|
||||
|
||||
server.on("/status.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("Got status request");
|
||||
server.on("/status.html", HTTP_GET, [](){
|
||||
DEBUG_PRINTLN("Got status request");
|
||||
|
||||
char statrespone[] = "0";
|
||||
if (bri > 0) {
|
||||
statrespone[0] = '1';
|
||||
}
|
||||
server.send(200, "text/plain", statrespone);
|
||||
|
||||
});
|
||||
char statrespone[] = "0";
|
||||
if (bri > 0) {
|
||||
statrespone[0] = '1';
|
||||
}
|
||||
server.send(200, "text/plain", statrespone);
|
||||
});
|
||||
}
|
||||
|
||||
String boolString(bool st)
|
||||
@ -288,9 +282,10 @@ bool connectUDP(){
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
#else
|
||||
void alexaInit(){}
|
||||
void handleAlexa(){}
|
||||
void alexaInitPages(){}
|
||||
bool handleAlexaApiCall(String req, String body){return false;}
|
||||
void alexaInit(){}
|
||||
void handleAlexa(){}
|
||||
void alexaInitPages(){}
|
||||
bool handleAlexaApiCall(String req, String body){return false;}
|
||||
#endif
|
||||
|
@ -145,72 +145,72 @@ void setCronixie()
|
||||
|
||||
void _overlayCronixie()
|
||||
{
|
||||
if (countdownMode) checkCountdown();
|
||||
#ifndef WLED_DISABLE_CRONIXIE
|
||||
if (countdownMode) checkCountdown();
|
||||
#ifndef WLED_DISABLE_CRONIXIE
|
||||
|
||||
byte h = hour(local);
|
||||
byte h0 = h;
|
||||
byte m = minute(local);
|
||||
byte s = second(local);
|
||||
byte d = day(local);
|
||||
byte mi = month(local);
|
||||
int y = year(local);
|
||||
//this has to be changed in time for 22nd century
|
||||
y -= 2000; if (y<0) y += 30; //makes countdown work
|
||||
byte h = hour(local);
|
||||
byte h0 = h;
|
||||
byte m = minute(local);
|
||||
byte s = second(local);
|
||||
byte d = day(local);
|
||||
byte mi = month(local);
|
||||
int y = year(local);
|
||||
//this has to be changed in time for 22nd century
|
||||
y -= 2000; if (y<0) y += 30; //makes countdown work
|
||||
|
||||
if (useAMPM && !countdownMode)
|
||||
{
|
||||
if (h>12) h-=12;
|
||||
else if (h==0) h+=12;
|
||||
}
|
||||
byte _digitOut[]{10,10,10,10,10,10};
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (dP[i] < 12) _digitOut[i] = dP[i];
|
||||
else {
|
||||
if (dP[i] < 65)
|
||||
if (useAMPM && !countdownMode)
|
||||
{
|
||||
if (h>12) h-=12;
|
||||
else if (h==0) h+=12;
|
||||
}
|
||||
byte _digitOut[]{10,10,10,10,10,10};
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (dP[i] < 12) _digitOut[i] = dP[i];
|
||||
else {
|
||||
if (dP[i] < 65)
|
||||
{
|
||||
switch(dP[i])
|
||||
{
|
||||
switch(dP[i])
|
||||
{
|
||||
case 21: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; i++; break; //HH
|
||||
case 25: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; i++; break; //MM
|
||||
case 31: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; i++; break; //SS
|
||||
case 21: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; i++; break; //HH
|
||||
case 25: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; i++; break; //MM
|
||||
case 31: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; i++; break; //SS
|
||||
|
||||
case 20: _digitOut[i] = h- (h/10)*10; break; //H
|
||||
case 24: _digitOut[i] = m/10; break; //M
|
||||
case 30: _digitOut[i] = s/10; break; //S
|
||||
case 20: _digitOut[i] = h- (h/10)*10; break; //H
|
||||
case 24: _digitOut[i] = m/10; break; //M
|
||||
case 30: _digitOut[i] = s/10; break; //S
|
||||
|
||||
case 43: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //D
|
||||
case 44: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; i++; break; //DD
|
||||
case 40: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; i++; break; //II
|
||||
case 37: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //YY
|
||||
case 39: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //YYYY
|
||||
case 43: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //D
|
||||
case 44: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; i++; break; //DD
|
||||
case 40: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; i++; break; //II
|
||||
case 37: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //YY
|
||||
case 39: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //YYYY
|
||||
|
||||
case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI)
|
||||
case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB
|
||||
case 14: _digitOut[i] = (h0>11)?1:0; break; //B
|
||||
}
|
||||
} else
|
||||
case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI)
|
||||
case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB
|
||||
case 14: _digitOut[i] = (h0>11)?1:0; break; //B
|
||||
}
|
||||
} else
|
||||
{
|
||||
switch(dP[i])
|
||||
{
|
||||
switch(dP[i])
|
||||
{
|
||||
case 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh
|
||||
case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm
|
||||
case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss
|
||||
case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI)
|
||||
case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb
|
||||
case 64: _digitOut[i] = (h0>11)?1:10; break; //b
|
||||
case 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh
|
||||
case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm
|
||||
case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss
|
||||
case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI)
|
||||
case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb
|
||||
case 64: _digitOut[i] = (h0>11)?1:10; break; //b
|
||||
|
||||
case 93: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //d
|
||||
case 94: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //dd
|
||||
case 90: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ii
|
||||
case 87: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //yy
|
||||
case 89: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //yyyy
|
||||
}
|
||||
case 93: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //d
|
||||
case 94: _digitOut[i] = d/10; _digitOut[i+1] = d- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //dd
|
||||
case 90: _digitOut[i] = mi/10; _digitOut[i+1] = mi- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ii
|
||||
case 87: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //yy
|
||||
case 89: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //yyyy
|
||||
}
|
||||
}
|
||||
}
|
||||
strip.setCronixieDigits(_digitOut);
|
||||
//strip.trigger(); //this has a drawback, no effects slower than RefreshMs. advantage: Quick update, not dependant on effect time
|
||||
#endif
|
||||
}
|
||||
strip.setCronixieDigits(_digitOut);
|
||||
//strip.trigger(); //this has a drawback, no effects slower than RefreshMs. advantage: Quick update, not dependant on effect time
|
||||
#endif
|
||||
}
|
||||
|
@ -25,29 +25,21 @@ void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
|
||||
void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb
|
||||
{
|
||||
//this is only an approximation using WS2812B with gamma correction enabled
|
||||
if (mired > 475)
|
||||
{
|
||||
if (mired > 475) {
|
||||
rgb[0]=255;rgb[1]=199;rgb[2]=92;//500
|
||||
} else if (mired > 425)
|
||||
{
|
||||
} else if (mired > 425) {
|
||||
rgb[0]=255;rgb[1]=213;rgb[2]=118;//450
|
||||
} else if (mired > 375)
|
||||
{
|
||||
} else if (mired > 375) {
|
||||
rgb[0]=255;rgb[1]=216;rgb[2]=118;//400
|
||||
} else if (mired > 325)
|
||||
{
|
||||
} else if (mired > 325) {
|
||||
rgb[0]=255;rgb[1]=234;rgb[2]=140;//350
|
||||
} else if (mired > 275)
|
||||
{
|
||||
} else if (mired > 275) {
|
||||
rgb[0]=255;rgb[1]=243;rgb[2]=160;//300
|
||||
} else if (mired > 225)
|
||||
{
|
||||
} else if (mired > 225) {
|
||||
rgb[0]=250;rgb[1]=255;rgb[2]=188;//250
|
||||
} else if (mired > 175)
|
||||
{
|
||||
} else if (mired > 175) {
|
||||
rgb[0]=247;rgb[1]=255;rgb[2]=215;//200
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
rgb[0]=237;rgb[1]=255;rgb[2]=239;//150
|
||||
}
|
||||
}
|
||||
@ -61,20 +53,20 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www
|
||||
float g = (int)255*(-X * 0.707196f + 1.655397f + Z * 0.036152f);
|
||||
float b = (int)255*(X * 0.051713f - 0.121364f + Z * 1.011530f);
|
||||
if (r > b && r > g && r > 1.0f) {
|
||||
// red is too big
|
||||
g = g / r;
|
||||
b = b / r;
|
||||
r = 1.0f;
|
||||
// red is too big
|
||||
g = g / r;
|
||||
b = b / r;
|
||||
r = 1.0f;
|
||||
} else if (g > b && g > r && g > 1.0f) {
|
||||
// green is too big
|
||||
r = r / g;
|
||||
b = b / g;
|
||||
g = 1.0f;
|
||||
// green is too big
|
||||
r = r / g;
|
||||
b = b / g;
|
||||
g = 1.0f;
|
||||
} else if (b > r && b > g && b > 1.0f) {
|
||||
// blue is too big
|
||||
r = r / b;
|
||||
g = g / b;
|
||||
b = 1.0f;
|
||||
// blue is too big
|
||||
r = r / b;
|
||||
g = g / b;
|
||||
b = 1.0f;
|
||||
}
|
||||
// Apply gamma correction
|
||||
r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f;
|
||||
@ -82,26 +74,26 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www
|
||||
b = b <= 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f;
|
||||
|
||||
if (r > b && r > g) {
|
||||
// red is biggest
|
||||
if (r > 1.0f) {
|
||||
g = g / r;
|
||||
b = b / r;
|
||||
r = 1.0f;
|
||||
}
|
||||
// red is biggest
|
||||
if (r > 1.0f) {
|
||||
g = g / r;
|
||||
b = b / r;
|
||||
r = 1.0f;
|
||||
}
|
||||
} else if (g > b && g > r) {
|
||||
// green is biggest
|
||||
if (g > 1.0f) {
|
||||
r = r / g;
|
||||
b = b / g;
|
||||
g = 1.0f;
|
||||
}
|
||||
// green is biggest
|
||||
if (g > 1.0f) {
|
||||
r = r / g;
|
||||
b = b / g;
|
||||
g = 1.0f;
|
||||
}
|
||||
} else if (b > r && b > g) {
|
||||
// blue is biggest
|
||||
if (b > 1.0f) {
|
||||
r = r / b;
|
||||
g = g / b;
|
||||
b = 1.0f;
|
||||
}
|
||||
// blue is biggest
|
||||
if (b > 1.0f) {
|
||||
r = r / b;
|
||||
g = g / b;
|
||||
b = 1.0f;
|
||||
}
|
||||
}
|
||||
rgb[0] = 255.0*r;
|
||||
rgb[1] = 255.0*g;
|
||||
|
@ -40,22 +40,22 @@ void updateBlynk()
|
||||
#ifndef WLED_DISABLE_BLYNK
|
||||
BLYNK_WRITE(V0)
|
||||
{
|
||||
bri = param.asInt();//bri
|
||||
colorUpdated(9);
|
||||
bri = param.asInt();//bri
|
||||
colorUpdated(9);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V1)
|
||||
{
|
||||
blHue = param.asInt();//hue
|
||||
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
||||
colorUpdated(9);
|
||||
blHue = param.asInt();//hue
|
||||
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
||||
colorUpdated(9);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V2)
|
||||
{
|
||||
blSat = param.asInt();//sat
|
||||
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
||||
colorUpdated(9);
|
||||
blSat = param.asInt();//sat
|
||||
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
||||
colorUpdated(9);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V3)
|
||||
@ -65,23 +65,23 @@ BLYNK_WRITE(V3)
|
||||
|
||||
BLYNK_WRITE(V4)
|
||||
{
|
||||
effectCurrent = param.asInt()-1;//fx
|
||||
strip.setMode(effectCurrent);
|
||||
colorUpdated(6);
|
||||
effectCurrent = param.asInt()-1;//fx
|
||||
strip.setMode(effectCurrent);
|
||||
colorUpdated(6);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V5)
|
||||
{
|
||||
effectSpeed = param.asInt();//sx
|
||||
strip.setSpeed(effectSpeed);
|
||||
colorUpdated(6);
|
||||
effectSpeed = param.asInt();//sx
|
||||
strip.setSpeed(effectSpeed);
|
||||
colorUpdated(6);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V6)
|
||||
{
|
||||
effectIntensity = param.asInt();//ix
|
||||
strip.setIntensity(effectIntensity);
|
||||
colorUpdated(6);
|
||||
effectIntensity = param.asInt();//ix
|
||||
strip.setIntensity(effectIntensity);
|
||||
colorUpdated(6);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V7)
|
||||
|
@ -14,6 +14,7 @@ void parseMQTTBriPayload(char* payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void callbackMQTT(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
DEBUG_PRINT("MQTT callb rec: ");
|
||||
@ -37,6 +38,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void publishMQTT()
|
||||
{
|
||||
if (mqtt == NULL) return;
|
||||
@ -64,6 +66,7 @@ void publishMQTT()
|
||||
mqtt->publish(subuf, obuf);*/
|
||||
}
|
||||
|
||||
|
||||
bool reconnectMQTT()
|
||||
{
|
||||
if (mqtt->connect(escapedMac.c_str()))
|
||||
@ -99,6 +102,7 @@ bool reconnectMQTT()
|
||||
return mqtt->connected();
|
||||
}
|
||||
|
||||
|
||||
bool initMQTT()
|
||||
{
|
||||
if (WiFi.status() != WL_CONNECTED) return false;
|
||||
@ -116,6 +120,7 @@ bool initMQTT()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void handleMQTT()
|
||||
{
|
||||
if (WiFi.status() != WL_CONNECTED || !mqttInit) return;
|
||||
|
@ -259,25 +259,26 @@ void serveIndex()
|
||||
if (uiConfiguration == 0) serveMobile = checkClientIsMobile(server.header("User-Agent"));
|
||||
else if (uiConfiguration == 2) serveMobile = true;
|
||||
|
||||
if (!realtimeActive || enableRealtimeUI) //do not serve while receiving realtime
|
||||
if (realtimeActive && !enableRealtimeUI) //do not serve while receiving realtime
|
||||
{
|
||||
if (serveMobile)
|
||||
{
|
||||
server.setContentLength(strlen_P(PAGE_indexM));
|
||||
server.send(200, "text/html", "");
|
||||
server.sendContent_P(PAGE_indexM);
|
||||
} else
|
||||
{
|
||||
server.setContentLength(strlen_P(PAGE_index0) + cssColorString.length() + strlen_P(PAGE_index1) + strlen_P(PAGE_index2) + strlen_P(PAGE_index3));
|
||||
server.send(200, "text/html", "");
|
||||
server.sendContent_P(PAGE_index0);
|
||||
server.sendContent(cssColorString);
|
||||
server.sendContent_P(PAGE_index1);
|
||||
server.sendContent_P(PAGE_index2);
|
||||
server.sendContent_P(PAGE_index3);
|
||||
}
|
||||
} else {
|
||||
serveRealtimeError(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (serveMobile)
|
||||
{
|
||||
server.setContentLength(strlen_P(PAGE_indexM));
|
||||
server.send(200, "text/html", "");
|
||||
server.sendContent_P(PAGE_indexM);
|
||||
} else
|
||||
{
|
||||
server.setContentLength(strlen_P(PAGE_index0) + cssColorString.length() + strlen_P(PAGE_index1) + strlen_P(PAGE_index2) + strlen_P(PAGE_index3));
|
||||
server.send(200, "text/html", "");
|
||||
server.sendContent_P(PAGE_index0);
|
||||
server.sendContent(cssColorString);
|
||||
server.sendContent_P(PAGE_index1);
|
||||
server.sendContent_P(PAGE_index2);
|
||||
server.sendContent_P(PAGE_index3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,58 +315,58 @@ void serveMessage(int code, String headl, String subl="", int optionType)
|
||||
|
||||
void serveSettings(byte subPage)
|
||||
{
|
||||
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 255: welcomepage
|
||||
if (!realtimeActive || enableRealtimeUI) //do not serve while receiving realtime
|
||||
{
|
||||
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage
|
||||
if (subPage == 255) {serveIndex(); return;}
|
||||
#endif
|
||||
if (realtimeActive && !enableRealtimeUI) //do not serve while receiving realtime
|
||||
{
|
||||
serveRealtimeError(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int pl0, pl1;
|
||||
switch (subPage)
|
||||
{
|
||||
case 1: pl0 = strlen_P(PAGE_settings_wifi0); pl1 = strlen_P(PAGE_settings_wifi1); break;
|
||||
case 2: pl0 = strlen_P(PAGE_settings_leds0); pl1 = strlen_P(PAGE_settings_leds1); break;
|
||||
case 3: pl0 = strlen_P(PAGE_settings_ui0); pl1 = strlen_P(PAGE_settings_ui1); break;
|
||||
case 4: pl0 = strlen_P(PAGE_settings_sync0); pl1 = strlen_P(PAGE_settings_sync1); break;
|
||||
case 5: pl0 = strlen_P(PAGE_settings_time0); pl1 = strlen_P(PAGE_settings_time1); break;
|
||||
case 6: pl0 = strlen_P(PAGE_settings_sec0); pl1 = strlen_P(PAGE_settings_sec1); break;
|
||||
case 255: pl0 = strlen_P(PAGE_welcome0); pl1 = strlen_P(PAGE_welcome1); break;
|
||||
default: pl0 = strlen_P(PAGE_settings0); pl1 = strlen_P(PAGE_settings1);
|
||||
}
|
||||
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage
|
||||
if (subPage == 255) {serveIndex(); return;}
|
||||
#endif
|
||||
|
||||
getSettingsJS(subPage);
|
||||
int sCssLength = (subPage >0 && subPage <7)?strlen_P(PAGE_settingsCss):0;
|
||||
int pl0, pl1;
|
||||
switch (subPage) //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 255: welcomepage
|
||||
{
|
||||
case 1: pl0 = strlen_P(PAGE_settings_wifi0); pl1 = strlen_P(PAGE_settings_wifi1); break;
|
||||
case 2: pl0 = strlen_P(PAGE_settings_leds0); pl1 = strlen_P(PAGE_settings_leds1); break;
|
||||
case 3: pl0 = strlen_P(PAGE_settings_ui0); pl1 = strlen_P(PAGE_settings_ui1); break;
|
||||
case 4: pl0 = strlen_P(PAGE_settings_sync0); pl1 = strlen_P(PAGE_settings_sync1); break;
|
||||
case 5: pl0 = strlen_P(PAGE_settings_time0); pl1 = strlen_P(PAGE_settings_time1); break;
|
||||
case 6: pl0 = strlen_P(PAGE_settings_sec0); pl1 = strlen_P(PAGE_settings_sec1); break;
|
||||
case 255: pl0 = strlen_P(PAGE_welcome0); pl1 = strlen_P(PAGE_welcome1); break;
|
||||
default: pl0 = strlen_P(PAGE_settings0); pl1 = strlen_P(PAGE_settings1);
|
||||
}
|
||||
|
||||
server.setContentLength(pl0 + cssColorString.length() + olen + sCssLength + pl1);
|
||||
server.send(200, "text/html", "");
|
||||
getSettingsJS(subPage);
|
||||
int sCssLength = (subPage >0 && subPage <7)?strlen_P(PAGE_settingsCss):0;
|
||||
|
||||
switch (subPage)
|
||||
{
|
||||
case 1: server.sendContent_P(PAGE_settings_wifi0); break;
|
||||
case 2: server.sendContent_P(PAGE_settings_leds0); break;
|
||||
case 3: server.sendContent_P(PAGE_settings_ui0); break;
|
||||
case 4: server.sendContent_P(PAGE_settings_sync0); break;
|
||||
case 5: server.sendContent_P(PAGE_settings_time0); break;
|
||||
case 6: server.sendContent_P(PAGE_settings_sec0); break;
|
||||
case 255: server.sendContent_P(PAGE_welcome0); break;
|
||||
default: server.sendContent_P(PAGE_settings0);
|
||||
}
|
||||
server.sendContent(obuf);
|
||||
server.sendContent(cssColorString);
|
||||
if (subPage >0 && subPage <7) server.sendContent_P(PAGE_settingsCss);
|
||||
switch (subPage)
|
||||
{
|
||||
case 1: server.sendContent_P(PAGE_settings_wifi1); break;
|
||||
case 2: server.sendContent_P(PAGE_settings_leds1); break;
|
||||
case 3: server.sendContent_P(PAGE_settings_ui1); break;
|
||||
case 4: server.sendContent_P(PAGE_settings_sync1); break;
|
||||
case 5: server.sendContent_P(PAGE_settings_time1); break;
|
||||
case 6: server.sendContent_P(PAGE_settings_sec1); break;
|
||||
case 255: server.sendContent_P(PAGE_welcome1); break;
|
||||
default: server.sendContent_P(PAGE_settings1);
|
||||
}
|
||||
} else {
|
||||
serveRealtimeError(true);
|
||||
}
|
||||
server.setContentLength(pl0 + cssColorString.length() + olen + sCssLength + pl1);
|
||||
server.send(200, "text/html", "");
|
||||
|
||||
switch (subPage)
|
||||
{
|
||||
case 1: server.sendContent_P(PAGE_settings_wifi0); break;
|
||||
case 2: server.sendContent_P(PAGE_settings_leds0); break;
|
||||
case 3: server.sendContent_P(PAGE_settings_ui0); break;
|
||||
case 4: server.sendContent_P(PAGE_settings_sync0); break;
|
||||
case 5: server.sendContent_P(PAGE_settings_time0); break;
|
||||
case 6: server.sendContent_P(PAGE_settings_sec0); break;
|
||||
case 255: server.sendContent_P(PAGE_welcome0); break;
|
||||
default: server.sendContent_P(PAGE_settings0);
|
||||
}
|
||||
server.sendContent(obuf);
|
||||
server.sendContent(cssColorString);
|
||||
if (subPage >0 && subPage <7) server.sendContent_P(PAGE_settingsCss);
|
||||
switch (subPage)
|
||||
{
|
||||
case 1: server.sendContent_P(PAGE_settings_wifi1); break;
|
||||
case 2: server.sendContent_P(PAGE_settings_leds1); break;
|
||||
case 3: server.sendContent_P(PAGE_settings_ui1); break;
|
||||
case 4: server.sendContent_P(PAGE_settings_sync1); break;
|
||||
case 5: server.sendContent_P(PAGE_settings_time1); break;
|
||||
case 6: server.sendContent_P(PAGE_settings_sec1); break;
|
||||
case 255: server.sendContent_P(PAGE_welcome1); break;
|
||||
default: server.sendContent_P(PAGE_settings1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user