Refactored code to improve readability (merge dev PR)

Refactored code to improve readability
Fixed non-2-char indentations
This commit is contained in:
Aircoookie 2018-11-09 17:02:58 +01:00 committed by GitHub
commit a3bef49124
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1127 additions and 1115 deletions

View File

@ -10,33 +10,34 @@
//uncomment this if red and green are swapped //uncomment this if red and green are swapped
//#define SWAPRG //#define SWAPRG
//automatically uses the right driver method for each platform //automatically uses the right driver method for each platform
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#ifdef WORKAROUND_ESP32_BITBANG #ifdef WORKAROUND_ESP32_BITBANG
#define PIXELMETHOD NeoEsp32BitBangWs2813Method #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." #pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering."
#else #else
#define PIXELMETHOD NeoEsp32RmtWS2813_V3Method #define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
#endif #endif
#else //esp8266 #else //esp8266
//autoselect the right method depending on strip pin //autoselect the right method depending on strip pin
#if LEDPIN == 2 #if LEDPIN == 2
#define PIXELMETHOD NeoEsp8266Uart800KbpsMethod #define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
#elif LEDPIN == 3 #elif LEDPIN == 3
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod #define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
#else #else
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod #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." #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
#endif #endif
//handle swapping Red and Green automatically //handle swapping Red and Green automatically
#ifdef SWAPRG #ifdef SWAPRG
#define PIXELFEATURE3 NeoRgbFeature #define PIXELFEATURE3 NeoRgbFeature
#define PIXELFEATURE4 NeoRgbwFeature #define PIXELFEATURE4 NeoRgbwFeature
#else #else
#define PIXELFEATURE3 NeoGrbFeature #define PIXELFEATURE3 NeoGrbFeature
#define PIXELFEATURE4 NeoGrbwFeature #define PIXELFEATURE4 NeoGrbwFeature
#endif #endif
#include <NeoPixelBrightnessBus.h> #include <NeoPixelBrightnessBus.h>
@ -53,10 +54,10 @@ class NeoPixelWrapper
{ {
public: public:
NeoPixelWrapper() : NeoPixelWrapper() :
// initialize each member to null // initialize each member to null
_pGrb(NULL), _pGrb(NULL),
_pGrbw(NULL), _pGrbw(NULL),
_type(NeoPixelType_None) _type(NeoPixelType_None)
{ {
} }
@ -71,8 +72,8 @@ public:
cleanup(); cleanup();
_type = type; _type = type;
switch (_type) { switch (_type)
{
case NeoPixelType_Grb: case NeoPixelType_Grb:
_pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN); _pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN);
_pGrb->Begin(); _pGrb->Begin();
@ -88,23 +89,25 @@ public:
void Show() void Show()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#ifdef WORKAROUND_ESP32_BITBANG #ifdef WORKAROUND_ESP32_BITBANG
delay(1); delay(1);
portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139) portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
#endif #endif
#endif #endif
switch (_type) { switch (_type)
{
case NeoPixelType_Grb: _pGrb->Show(); break; case NeoPixelType_Grb: _pGrb->Show(); break;
case NeoPixelType_Grbw: _pGrbw->Show(); break; case NeoPixelType_Grbw: _pGrbw->Show(); break;
} }
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#ifdef WORKAROUND_ESP32_BITBANG #ifdef WORKAROUND_ESP32_BITBANG
portENABLE_INTERRUPTS(); portENABLE_INTERRUPTS();
#endif #endif
#endif #endif
} }
bool CanShow() const bool CanShow() const
{ {
switch (_type) { switch (_type) {
@ -113,65 +116,65 @@ public:
} }
} }
void SetPixelColor(uint16_t indexPixel, RgbColor color) void SetPixelColor(uint16_t indexPixel, RgbColor color)
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break; case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break; case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
}
} }
}
void SetPixelColor(uint16_t indexPixel, RgbwColor color) void SetPixelColor(uint16_t indexPixel, RgbwColor color)
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break; case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break; case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
}
} }
}
void SetBrightness(byte b) void SetBrightness(byte b)
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break; case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break; case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
}
} }
}
RgbColor GetPixelColor(uint16_t indexPixel) const RgbColor GetPixelColor(uint16_t indexPixel) const
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break; case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break; case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
}
return 0;
} }
return 0;
}
// NOTE: Due to feature differences, some support RGBW but the method name // NOTE: Due to feature differences, some support RGBW but the method name
// here needs to be unique, thus GetPixeColorRgbw // here needs to be unique, thus GetPixeColorRgbw
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break; case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break; case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
}
return 0;
} }
return 0;
}
void ClearTo(RgbColor color) void ClearTo(RgbColor color)
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: _pGrb->ClearTo(color); break; case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break; case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
}
} }
}
void ClearTo(RgbwColor color) void ClearTo(RgbwColor color)
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: break; case NeoPixelType_Grb: break;
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break; case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
}
} }
}
private: private:
NeoPixelType _type; NeoPixelType _type;

View File

@ -67,9 +67,11 @@ void WS2812FX::service() {
if(_running || _triggered) { if(_running || _triggered) {
unsigned long now = millis(); // Be aware, millis() rolls over every 49 days unsigned long now = millis(); // Be aware, millis() rolls over every 49 days
bool doShow = false; bool doShow = false;
for(uint8_t i=0; i < _num_segments; i++) { for(uint8_t i=0; i < _num_segments; i++)
{
_segment_index = i; _segment_index = i;
if(now > SEGMENT_RUNTIME.next_time || _triggered) { if(now > SEGMENT_RUNTIME.next_time || _triggered)
{
doShow = true; doShow = true;
handle_palette(); handle_palette();
uint16_t delay = (this->*_mode[SEGMENT.mode])(); uint16_t delay = (this->*_mode[SEGMENT.mode])();

View File

@ -40,6 +40,8 @@
#define WS2812FX_h #define WS2812FX_h
#include "NpbWrapper.h" #include "NpbWrapper.h"
#define FASTLED_INTERNAL //remove annoying pragma messages
#include "FastLED.h" #include "FastLED.h"
#define DEFAULT_BRIGHTNESS (uint8_t)50 #define DEFAULT_BRIGHTNESS (uint8_t)50

View File

@ -30,29 +30,29 @@
//library inclusions //library inclusions
#include <Arduino.h> #include <Arduino.h>
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h> #include <WiFi.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include "src/dependencies/webserver/WebServer.h" #include "src/dependencies/webserver/WebServer.h"
#include <HTTPClient.h> #include <HTTPClient.h>
#else #else
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
#endif #endif
#include <EEPROM.h> #include <EEPROM.h>
#include <WiFiUDP.h> #include <WiFiUDP.h>
#include <DNSServer.h> #include <DNSServer.h>
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h" #include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h"
#endif #endif
#include "src/dependencies/time/Time.h" #include "src/dependencies/time/Time.h"
#include "src/dependencies/time/TimeLib.h" #include "src/dependencies/time/TimeLib.h"
#include "src/dependencies/timezone/Timezone.h" #include "src/dependencies/timezone/Timezone.h"
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
#include "src/dependencies/blynk/BlynkSimpleEsp.h" #include "src/dependencies/blynk/BlynkSimpleEsp.h"
#endif #endif
#include "src/dependencies/e131/E131.h" #include "src/dependencies/e131/E131.h"
#include "src/dependencies/pubsubclient/PubSubClient.h" #include "src/dependencies/pubsubclient/PubSubClient.h"
@ -63,7 +63,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1811071 #define VERSION 1811091
char versionString[] = "0.8.1"; char versionString[] = "0.8.1";
@ -357,6 +357,7 @@ bool auxActive = false, auxActiveBefore = false;
//alexa udp //alexa udp
WiFiUDP alexaUDP; WiFiUDP alexaUDP;
bool alexaUdpConnected = false;
IPAddress ipMulti(239, 255, 255, 250); IPAddress ipMulti(239, 255, 255, 250);
unsigned int portMulti = 1900; unsigned int portMulti = 1900;
String escapedMac; String escapedMac;
@ -381,16 +382,16 @@ uint16_t olen = 0;
//server library objects //server library objects
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WebServer server(80); WebServer server(80);
#else #else
ESP8266WebServer server(80); ESP8266WebServer server(80);
#endif #endif
HTTPClient* hueClient = NULL; HTTPClient* hueClient = NULL;
WiFiClient* mqttTCPClient = NULL; WiFiClient* mqttTCPClient = NULL;
PubSubClient* mqtt = NULL; PubSubClient* mqtt = NULL;
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
ESP8266HTTPUpdateServer httpUpdater; ESP8266HTTPUpdateServer httpUpdater;
#endif #endif
//udp interface objects //udp interface objects
@ -417,8 +418,8 @@ WS2812FX strip = WS2812FX();
//filesystem //filesystem
#ifdef USEFS #ifdef USEFS
#include <FS.h>; #include <FS.h>;
File fsUploadFile; File fsUploadFile;
#endif #endif
//gamma 2.4 lookup table used for color correction //gamma 2.4 lookup table used for color correction
@ -478,64 +479,63 @@ bool oappendi(int i)
//boot starts here //boot starts here
void setup() { void setup() {
wledInit(); wledInit();
} }
//main program loop //main program loop
void loop() { void loop() {
server.handleClient(); server.handleClient();
handleSerial(); handleSerial();
handleNotifications(); handleNotifications();
handleTransitions(); handleTransitions();
userLoop(); userLoop();
yield(); yield();
handleButton(); handleButton();
handleNetworkTime(); handleNetworkTime();
if (!onlyAP) if (!onlyAP)
{ {
handleAlexa(); handleAlexa();
handleMQTT(); handleMQTT();
} }
handleOverlays(); handleOverlays();
yield(); yield();
if (!realtimeActive) //block stuff if WARLS/Adalight is enabled
if (!realtimeActive) //block stuff if WARLS/Adalight is enabled {
{ if (dnsActive) dnsServer.processNextRequest();
if (dnsActive) dnsServer.processNextRequest(); #ifndef WLED_DISABLE_OTA
#ifndef WLED_DISABLE_OTA if (aOtaEnabled) ArduinoOTA.handle();
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 #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
} }

View File

@ -2,60 +2,57 @@
* Sending XML status files to client * Sending XML status files to client
*/ */
//build XML response to HTTP /win API request
void XML_response(bool isHTTP) void XML_response(bool isHTTP)
{ {
olen = 0; olen = 0;
oappend("<?xml version = \"1.0\" ?><vs><ac>"); oappend("<?xml version = \"1.0\" ?><vs><ac>");
if (nightlightActive && nightlightFade) oappendi((nightlightActive && nightlightFade) ? briT : bri);
{ oappend("</ac>");
oappendi(briT);
} else for (int i = 0; i < 3; i++)
{ {
oappendi(bri); oappend("<cl>");
} oappendi(col[i]);
oappend("</ac>"); oappend("</cl>");
}
for (int i = 0; i < 3; i++)
{ oappend("<ns>");
oappend("<cl>"); oappendi(notifyDirect);
oappendi(col[i]); oappend("</ns><nr>");
oappend("</cl>"); oappendi(receiveNotifications);
} oappend("</nr><nl>");
oappend("<ns>"); oappendi(nightlightActive);
oappendi(notifyDirect); oappend("</nl><nf>");
oappend("</ns><nr>"); oappendi(nightlightFade);
oappendi(receiveNotifications); oappend("</nf><nd>");
oappend("</nr><nl>"); oappendi(nightlightDelayMins);
oappendi(nightlightActive); oappend("</nd><nt>");
oappend("</nl><nf>"); oappendi(nightlightTargetBri);
oappendi(nightlightFade); oappend("</nt><fx>");
oappend("</nf><nd>"); oappendi(effectCurrent);
oappendi(nightlightDelayMins); oappend("</fx><sx>");
oappend("</nd><nt>"); oappendi(effectSpeed);
oappendi(nightlightTargetBri); oappend("</sx><ix>");
oappend("</nt><fx>"); oappendi(effectIntensity);
oappendi(effectCurrent); oappend("</ix><fp>");
oappend("</fx><sx>"); oappendi(effectPalette);
oappendi(effectSpeed); oappend("</fp><wv>");
oappend("</sx><ix>"); if (useRGBW && !autoRGBtoRGBW) {
oappendi(effectIntensity); oappendi(white);
oappend("</ix><fp>"); } else {
oappendi(effectPalette); oappend("-1");
oappend("</fp><wv>"); }
if (useRGBW && !autoRGBtoRGBW) { oappend("</wv><md>");
oappendi(white); oappendi(useHSB);
} else { oappend("</md><ds>");
oappend("-1"); oappend(serverDescription);
} oappend("</ds></vs>");
oappend("</wv><md>"); if (isHTTP) server.send(200, "text/xml", obuf);
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."; 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) switch(stype)
{ {
case 's': //string (we can interpret val as char*) case 's': //string (we can interpret val as char*)
oappend("d.Sf."); oappend("d.Sf.");
oappend(key); oappend(key);
oappend(".value=\""); oappend(".value=\"");
oappend(val); oappend(val);
oappend("\";"); oappend("\";");
break; break;
case 'm': //message case 'm': //message
oappend("d.getElementsByClassName"); oappend("d.getElementsByClassName");
oappend(key); oappend(key);
oappend(".innerHTML=\""); oappend(".innerHTML=\"");
oappend(val); oappend(val);
oappend("\";"); oappend("\";");
break; 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 //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec
DEBUG_PRINT("settings resp"); DEBUG_PRINT("settings resp");

View File

@ -61,7 +61,9 @@ void handleSettingsSet(byte subPage)
#endif #endif
useRGBW = server.hasArg("EW"); useRGBW = server.hasArg("EW");
autoRGBtoRGBW = server.hasArg("AW"); 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[0] = col[0];
colS[1] = col[1]; colS[1] = col[1];
@ -170,7 +172,9 @@ void handleSettingsSet(byte subPage)
strcpy(alexaInvocationName, server.arg("AI").c_str()); strcpy(alexaInvocationName, server.arg("AI").c_str());
notifyAlexa = server.hasArg("SA"); 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(mqttServer, server.arg("MS").c_str());
strcpy(mqttDeviceTopic, server.arg("MD").c_str()); strcpy(mqttDeviceTopic, server.arg("MD").c_str());
@ -209,7 +213,9 @@ void handleSettingsSet(byte subPage)
useAMPM = !server.hasArg("CF"); useAMPM = !server.hasArg("CF");
currentTimezone = server.arg("TZ").toInt(); currentTimezone = server.arg("TZ").toInt();
utcOffsetSecs = server.arg("UO").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")){ if (server.hasArg("OL")){
overlayDefault = server.arg("OL").toInt(); overlayDefault = server.arg("OL").toInt();
@ -305,451 +311,453 @@ void handleSettingsSet(byte subPage)
bool handleSet(String req) bool handleSet(String req)
{ {
bool effectUpdated = false; bool effectUpdated = false;
if (!(req.indexOf("win") >= 0)) return false; if (!(req.indexOf("win") >= 0)) return false;
int pos = 0; int pos = 0;
DEBUG_PRINT("API req: "); DEBUG_PRINT("API req: ");
DEBUG_PRINTLN(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);
}
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
}
//save macro, requires &MS=<slot>(<macro>) format //set brigthness
pos = req.indexOf("&MS="); pos = req.indexOf("&A=");
if (pos > 0) { if (pos > 0) {
int i = req.substring(pos + 4).toInt(); bri = req.substring(pos + 3).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
}
//set brigthness
pos = req.indexOf("&A=");
if (pos > 0) {
bri = req.substring(pos + 3).toInt();
}
//set hue //set hue
pos = req.indexOf("HU="); pos = req.indexOf("HU=");
if (pos > 0) { if (pos > 0) {
uint16_t temphue = req.substring(pos + 3).toInt(); uint16_t temphue = req.substring(pos + 3).toInt();
byte tempsat = 255; byte tempsat = 255;
pos = req.indexOf("SA="); pos = req.indexOf("SA=");
if (pos > 0) { if (pos > 0) {
tempsat = req.substring(pos + 3).toInt(); tempsat = req.substring(pos + 3).toInt();
} }
colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col); colorHStoRGB(temphue,tempsat,(req.indexOf("H2")>0)? colSec:col);
} }
//set red value //set red value
pos = req.indexOf("&R="); pos = req.indexOf("&R=");
if (pos > 0) { if (pos > 0) {
col[0] = req.substring(pos + 3).toInt(); col[0] = req.substring(pos + 3).toInt();
} }
//set green value //set green value
pos = req.indexOf("&G="); pos = req.indexOf("&G=");
if (pos > 0) { if (pos > 0) {
col[1] = req.substring(pos + 3).toInt(); col[1] = req.substring(pos + 3).toInt();
} }
//set blue value //set blue value
pos = req.indexOf("&B="); pos = req.indexOf("&B=");
if (pos > 0) { if (pos > 0) {
col[2] = req.substring(pos + 3).toInt(); col[2] = req.substring(pos + 3).toInt();
} }
//set white value //set white value
pos = req.indexOf("&W="); pos = req.indexOf("&W=");
if (pos > 0) { if (pos > 0) {
white = req.substring(pos + 3).toInt(); white = req.substring(pos + 3).toInt();
} }
//set 2nd red value //set 2nd red value
pos = req.indexOf("R2="); pos = req.indexOf("R2=");
if (pos > 0) { if (pos > 0) {
colSec[0] = req.substring(pos + 3).toInt(); colSec[0] = req.substring(pos + 3).toInt();
} }
//set 2nd green value //set 2nd green value
pos = req.indexOf("G2="); pos = req.indexOf("G2=");
if (pos > 0) { if (pos > 0) {
colSec[1] = req.substring(pos + 3).toInt(); colSec[1] = req.substring(pos + 3).toInt();
} }
//set 2nd blue value //set 2nd blue value
pos = req.indexOf("B2="); pos = req.indexOf("B2=");
if (pos > 0) { if (pos > 0) {
colSec[2] = req.substring(pos + 3).toInt(); colSec[2] = req.substring(pos + 3).toInt();
} }
//set 2nd white value //set 2nd white value
pos = req.indexOf("W2="); pos = req.indexOf("W2=");
if (pos > 0) { if (pos > 0) {
whiteSec = req.substring(pos + 3).toInt(); whiteSec = req.substring(pos + 3).toInt();
} }
//set color from HEX or 32bit DEC //set color from HEX or 32bit DEC
pos = req.indexOf("CL="); pos = req.indexOf("CL=");
if (pos > 0) { if (pos > 0) {
colorFromDecOrHexString(col, &white, (char*)req.substring(pos + 3).c_str()); colorFromDecOrHexString(col, &white, (char*)req.substring(pos + 3).c_str());
} }
pos = req.indexOf("C2="); pos = req.indexOf("C2=");
if (pos > 0) { if (pos > 0) {
colorFromDecOrHexString(colSec, &whiteSec, (char*)req.substring(pos + 3).c_str()); colorFromDecOrHexString(colSec, &whiteSec, (char*)req.substring(pos + 3).c_str());
} }
//set 2nd to white //set 2nd to white
pos = req.indexOf("SW"); pos = req.indexOf("SW");
if (pos > 0) { if (pos > 0) {
if(useRGBW) { if(useRGBW) {
whiteSec = 255; 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;
colSec[0] = 0; colSec[0] = 0;
colSec[1] = 0; colSec[1] = 0;
colSec[2] = 0; colSec[2] = 0;
} } else {
colSec[0] = 255;
colSec[1] = 255;
colSec[2] = 255;
}
}
//set to random hue SR=0->1st SR=1->2nd //set 2nd to black
pos = req.indexOf("SR"); pos = req.indexOf("SB");
if (pos > 0) { if (pos > 0) {
_setRandomColor(req.substring(pos + 3).toInt()); whiteSec = 0;
} colSec[0] = 0;
//set 2nd to 1st colSec[1] = 0;
pos = req.indexOf("SP"); colSec[2] = 0;
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 current effect index //set to random hue SR=0->1st SR=1->2nd
pos = req.indexOf("FX="); pos = req.indexOf("SR");
if (pos > 0) { if (pos > 0) {
if (effectCurrent != req.substring(pos + 3).toInt()) _setRandomColor(req.substring(pos + 3).toInt());
{ }
effectCurrent = req.substring(pos + 3).toInt(); //set 2nd to 1st
strip.setMode(effectCurrent); pos = req.indexOf("SP");
effectUpdated = true; if (pos > 0) {
} colSec[0] = col[0];
} colSec[1] = col[1];
//set effect speed colSec[2] = col[2];
pos = req.indexOf("SX="); whiteSec = white;
if (pos > 0) { }
if (effectSpeed != req.substring(pos + 3).toInt()) //swap 2nd & 1st
{ pos = req.indexOf("SC");
effectSpeed = req.substring(pos + 3).toInt(); if (pos > 0) {
strip.setSpeed(effectSpeed); byte _temp[4];
effectUpdated = true; for (int i = 0; i<3; i++)
} {
} _temp[i] = col[i];
//set effect intensity col[i] = colSec[i];
pos = req.indexOf("IX="); colSec[i] = _temp[i];
if (pos > 0) { }
if (effectIntensity != req.substring(pos + 3).toInt()) _temp[3] = white;
{ white = whiteSec;
effectIntensity = req.substring(pos + 3).toInt(); whiteSec = _temp[3];
strip.setIntensity(effectIntensity); }
effectUpdated = true;
} //set current effect index
} pos = req.indexOf("FX=");
//set effect palette (only for FastLED effects) if (pos > 0) {
pos = req.indexOf("FP="); if (effectCurrent != req.substring(pos + 3).toInt())
if (pos > 0) { {
if (effectPalette != req.substring(pos + 3).toInt()) effectCurrent = req.substring(pos + 3).toInt();
{ strip.setMode(effectCurrent);
effectPalette = req.substring(pos + 3).toInt(); effectUpdated = true;
strip.setPalette(effectPalette); }
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 hue polling light: 0 -off //set hue polling light: 0 -off
pos = req.indexOf("HP="); pos = req.indexOf("HP=");
if (pos > 0) { if (pos > 0) {
int id = req.substring(pos + 3).toInt(); int id = req.substring(pos + 3).toInt();
if (id > 0) if (id > 0)
{ {
if (id < 100) huePollLightId = id; if (id < 100) huePollLightId = id;
setupHue(); setupHue();
} else { } else {
huePollingEnabled = false; huePollingEnabled = false;
} }
} }
//set default control mode (0 - RGB, 1 - HSB) //set default control mode (0 - RGB, 1 - HSB)
pos = req.indexOf("MD="); pos = req.indexOf("MD=");
if (pos > 0) { if (pos > 0) {
useHSB = req.substring(pos + 3).toInt(); useHSB = req.substring(pos + 3).toInt();
} }
//set advanced overlay //set advanced overlay
pos = req.indexOf("OL="); pos = req.indexOf("OL=");
if (pos > 0) { if (pos > 0) {
overlayCurrent = req.substring(pos + 3).toInt(); overlayCurrent = req.substring(pos + 3).toInt();
strip.unlockAll(); strip.unlockAll();
} }
//(un)lock pixel (ranges) //(un)lock pixel (ranges)
pos = req.indexOf("&L="); pos = req.indexOf("&L=");
if (pos > 0){ if (pos > 0){
int index = req.substring(pos + 3).toInt(); int index = req.substring(pos + 3).toInt();
pos = req.indexOf("L2="); pos = req.indexOf("L2=");
if (pos > 0){ if (pos > 0){
int index2 = req.substring(pos + 3).toInt(); int index2 = req.substring(pos + 3).toInt();
if (req.indexOf("UL") > 0) if (req.indexOf("UL") > 0)
{ {
strip.unlockRange(index, index2); strip.unlockRange(index, index2);
} else
{
strip.lockRange(index, index2);
}
} else } else
{ {
if (req.indexOf("UL") > 0) strip.lockRange(index, index2);
{
strip.unlock(index);
} else
{
strip.lock(index);
}
} }
} } else
{
if (req.indexOf("UL") > 0)
{
strip.unlock(index);
} else
{
strip.lock(index);
}
}
}
//apply macro //apply macro
pos = req.indexOf("&M="); pos = req.indexOf("&M=");
if (pos > 0) { if (pos > 0) {
applyMacro(req.substring(pos + 3).toInt()); applyMacro(req.substring(pos + 3).toInt());
} }
//toggle send UDP direct notifications //toggle send UDP direct notifications
if (req.indexOf("SN=") > 0) if (req.indexOf("SN=") > 0)
{ {
notifyDirect = true; notifyDirect = true;
if (req.indexOf("SN=0") > 0) if (req.indexOf("SN=0") > 0)
{ {
notifyDirect = false; notifyDirect = false;
} }
} }
//toggle receive UDP direct notifications //toggle receive UDP direct notifications
if (req.indexOf("RN=") > 0) if (req.indexOf("RN=") > 0)
{ {
receiveNotifications = true; receiveNotifications = true;
if (req.indexOf("RN=0") > 0) if (req.indexOf("RN=0") > 0)
{ {
receiveNotifications = false; receiveNotifications = false;
} }
} }
//toggle nightlight mode //toggle nightlight mode
bool aNlDef = false; bool aNlDef = false;
if (req.indexOf("&ND") > 0) aNlDef = true; if (req.indexOf("&ND") > 0) aNlDef = true;
pos = req.indexOf("NL="); pos = req.indexOf("NL=");
if (pos > 0) if (pos > 0)
{ {
if (req.indexOf("NL=0") > 0) if (req.indexOf("NL=0") > 0)
{ {
nightlightActive = false; nightlightActive = false;
bri = briT; bri = briT;
} else { } else {
nightlightActive = true;
if (!aNlDef) nightlightDelayMins = req.substring(pos + 3).toInt();
nightlightStartTime = millis();
}
} else if (aNlDef)
{
nightlightActive = true; nightlightActive = true;
if (!aNlDef) nightlightDelayMins = req.substring(pos + 3).toInt();
nightlightStartTime = millis(); nightlightStartTime = millis();
} }
} else if (aNlDef)
{
nightlightActive = true;
nightlightStartTime = millis();
}
//set nightlight target brightness //set nightlight target brightness
pos = req.indexOf("NT="); pos = req.indexOf("NT=");
if (pos > 0) { if (pos > 0) {
nightlightTargetBri = req.substring(pos + 3).toInt(); nightlightTargetBri = req.substring(pos + 3).toInt();
nightlightActiveOld = false; //re-init nightlightActiveOld = false; //re-init
} }
//toggle nightlight fade //toggle nightlight fade
if (req.indexOf("NF=") > 0) if (req.indexOf("NF=") > 0)
{ {
if (req.indexOf("NF=0") > 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; bri = briLast;
} else { } 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 briLast = bri;
case 1: bri = briLast; break; //on bri = 0;
default: if (bri == 0) //toggle
{
bri = briLast;
} else
{
briLast = bri;
bri = 0;
}
} }
} }
}
//deactivate nightlight if target brightness is reached //deactivate nightlight if target brightness is reached
if (bri == nightlightTargetBri) nightlightActive = false; if (bri == nightlightTargetBri) nightlightActive = false;
//set time (unix timestamp) //set time (unix timestamp)
pos = req.indexOf("ST="); pos = req.indexOf("ST=");
if (pos > 0) { if (pos > 0) {
setTime(req.substring(pos+3).toInt()); setTime(req.substring(pos+3).toInt());
} }
//set countdown goal (unix timestamp) //set countdown goal (unix timestamp)
pos = req.indexOf("CT="); pos = req.indexOf("CT=");
if (pos > 0) { if (pos > 0) {
countdownTime = req.substring(pos+3).toInt(); countdownTime = req.substring(pos+3).toInt();
if (countdownTime - now() > 0) countdownOverTriggered = false; if (countdownTime - now() > 0) countdownOverTriggered = false;
} }
//set presets //set presets
pos = req.indexOf("P1="); //sets first preset for cycle pos = req.indexOf("P1="); //sets first preset for cycle
if (pos > 0) presetCycleMin = req.substring(pos + 3).toInt(); if (pos > 0) presetCycleMin = req.substring(pos + 3).toInt();
pos = req.indexOf("P2="); //sets last preset for cycle pos = req.indexOf("P2="); //sets last preset for cycle
if (pos > 0) presetCycleMax = req.substring(pos + 3).toInt(); if (pos > 0) presetCycleMax = req.substring(pos + 3).toInt();
if (req.indexOf("CY=") > 0) //preset cycle if (req.indexOf("CY=") > 0) //preset cycle
{ {
presetCyclingEnabled = true; presetCyclingEnabled = true;
if (req.indexOf("CY=0") > 0) if (req.indexOf("CY=0") > 0)
{ {
presetCyclingEnabled = false; presetCyclingEnabled = false;
} }
presetCycCurr = presetCycleMin; presetCycCurr = presetCycleMin;
} }
pos = req.indexOf("PT="); //sets cycle time in ms pos = req.indexOf("PT="); //sets cycle time in ms
if (pos > 0) { if (pos > 0) {
int v = req.substring(pos + 3).toInt(); int v = req.substring(pos + 3).toInt();
if (v > 49) presetCycleTime = v; if (v > 49) presetCycleTime = v;
} }
if (req.indexOf("PA=") > 0) //apply brightness from preset if (req.indexOf("PA=") > 0) //apply brightness from preset
{ {
presetApplyBri = true; presetApplyBri = true;
if (req.indexOf("PA=0") > 0) presetApplyBri = false; if (req.indexOf("PA=0") > 0) presetApplyBri = false;
} }
if (req.indexOf("PC=") > 0) //apply color from preset if (req.indexOf("PC=") > 0) //apply color from preset
{ {
presetApplyCol = true; presetApplyCol = true;
if (req.indexOf("PC=0") > 0) presetApplyCol = false; if (req.indexOf("PC=0") > 0) presetApplyCol = false;
} }
if (req.indexOf("PX=") > 0) //apply effects from preset if (req.indexOf("PX=") > 0) //apply effects from preset
{ {
presetApplyFx = true; presetApplyFx = true;
if (req.indexOf("PX=0") > 0) presetApplyFx = false; if (req.indexOf("PX=0") > 0) presetApplyFx = false;
} }
pos = req.indexOf("PS="); //saves current in preset
if (pos > 0) { pos = req.indexOf("PS="); //saves current in preset
savePreset(req.substring(pos + 3).toInt()); if (pos > 0) {
} savePreset(req.substring(pos + 3).toInt());
pos = req.indexOf("PL="); //applies entire preset }
if (pos > 0) { pos = req.indexOf("PL="); //applies entire preset
applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx); if (pos > 0) {
if (presetApplyFx) effectUpdated = true; applyPreset(req.substring(pos + 3).toInt(), presetApplyBri, presetApplyCol, presetApplyFx);
} if (presetApplyFx) effectUpdated = true;
}
//cronixie
pos = req.indexOf("NX="); //sets digits to code //cronixie
if (pos > 0) { pos = req.indexOf("NX="); //sets digits to code
strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str()); if (pos > 0) {
setCronixie(); strcpy(cronixieDisplay,req.substring(pos + 3, pos + 9).c_str());
} setCronixie();
pos = req.indexOf("NM="); //mode, 1 countdown }
if (pos > 0) { pos = req.indexOf("NM="); //mode, 1 countdown
countdownMode = true; if (pos > 0) {
if (req.indexOf("NM=0") > 0) countdownMode = true;
{ if (req.indexOf("NM=0") > 0)
countdownMode = false; {
} countdownMode = false;
} }
if (req.indexOf("NB=") > 0) //sets backlight }
{ if (req.indexOf("NB=") > 0) //sets backlight
cronixieBacklight = true; {
if (req.indexOf("NB=0") > 0) cronixieBacklight = true;
{ if (req.indexOf("NB=0") > 0)
cronixieBacklight = false; {
} cronixieBacklight = false;
if (overlayCurrent == 3) strip.setCronixieBacklight(cronixieBacklight); }
overlayRefreshedTime = 0; 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("U0="); //user var 0
} if (pos > 0) {
pos = req.indexOf("U1="); //user var 1 userVar0 = req.substring(pos + 3).toInt();
if (pos > 0) { }
userVar1 = req.substring(pos + 3).toInt(); pos = req.indexOf("U1="); //user var 1
} if (pos > 0) {
//you can add more if you need userVar1 = req.substring(pos + 3).toInt();
}
//you can add more if you need
//internal call, does not send XML response //internal call, does not send XML response
pos = req.indexOf("IN"); pos = req.indexOf("IN");
if (pos < 1) XML_response(true); if (pos < 1) XML_response(true);
//do not send UDP notifications this time //do not send UDP notifications this time
pos = req.indexOf("NN"); pos = req.indexOf("NN");
if (pos > 0) if (pos > 0)
{ {
colorUpdated(5); colorUpdated(5);
return true; return true;
} }
if (effectUpdated) if (effectUpdated)
{ {
colorUpdated(6); colorUpdated(6);
} else } else
{ {
colorUpdated(1); colorUpdated(1);
} }
return true; return true;
} }

View File

@ -3,36 +3,37 @@
*/ */
void handleSerial() 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); for (byte j=0; j<3; j++)
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++) while (Serial.peek()<0) //no data yet available
{ {
while (Serial.peek()<0) //no data yet available delay(1);
{ to++;
delay(1); if (to>5) {strip.show(); return;} //unexpected end of transmission
to++;
if (to>5) {strip.show(); return;} //unexpected end of transmission
}
to = 0;
sc[j] = Serial.read();
} }
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();
} }
} }

View File

@ -8,7 +8,7 @@ void wledInit()
ledCount = ((EEPROM.read(229) << 0) & 0xFF) + ((EEPROM.read(398) << 8) & 0xFF00); if (ledCount > 1200 || ledCount == 0) ledCount = 10; ledCount = ((EEPROM.read(229) << 0) & 0xFF) + ((EEPROM.read(398) << 8) & 0xFF00); if (ledCount > 1200 || ledCount == 0) ledCount = 10;
//RMT eats up too much RAM //RMT eats up too much RAM
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
if (ledCount > 600) ledCount = 600; if (ledCount > 600) ledCount = 600;
#endif #endif
if (!EEPROM.read(397)) strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //quick init if (!EEPROM.read(397)) strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //quick init
@ -16,7 +16,7 @@ void wledInit()
Serial.setTimeout(50); Serial.setTimeout(50);
#ifdef USEFS #ifdef USEFS
SPIFFS.begin(); SPIFFS.begin();
#endif #endif
DEBUG_PRINTLN("Load EEPROM"); DEBUG_PRINTLN("Load EEPROM");
@ -139,7 +139,9 @@ void initStrip()
if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true); if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true);
colorUpdated(0); 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); WiFi.softAPdisconnect(true);
} }
int fail_count = 0; 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 #ifndef ARDUINO_ARCH_ESP32
WiFi.hostname(serverDescription); WiFi.hostname(serverDescription);
#endif #endif
WiFi.begin(clientSSID, clientPass); WiFi.begin(clientSSID, clientPass);
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WiFi.setHostname(serverDescription); WiFi.setHostname(serverDescription);
#endif #endif
unsigned long lastTry = 0; unsigned long lastTry = 0;
bool con = false; bool con = false;
@ -211,9 +214,9 @@ void initCon()
} }
//fill string buffer with build info
void getBuildInfo() void getBuildInfo()
{ {
//fill string buffer with build info
olen = 0; olen = 0;
oappend("hard-coded build info:\r\n\n"); oappend("hard-coded build info:\r\n\n");
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32

View File

@ -118,135 +118,136 @@ void handleNotifications()
} }
//receive UDP notifications //receive UDP notifications
if(udpConnected && (receiveNotifications || receiveDirect)){ if (!udpConnected || !(receiveNotifications || receiveDirect)) return;
uint16_t packetSize = notifierUdp.parsePacket();
//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);
id++; if (id >= ledCount) break;
}
strip.show();
return;
}
if (packetSize > UDP_IN_MAXSIZE) return; uint16_t packetSize = notifierUdp.parsePacket();
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)
{
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
{
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; //hyperion / raw RGB
} if (!packetSize && udpRgbConnected) {
} else if (udpIn[0] == 3) //drgbw packetSize = rgbUdp.parsePacket();
{ if (!receiveDirect) return;
uint16_t id = 0; if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) return;
for (uint16_t i = 2; i < packetSize -3; i += 4) realtimeIP = rgbUdp.remoteIP();
{ DEBUG_PRINTLN(rgbUdp.remoteIP());
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); olen = 0;
rgbUdp.read(obuf, packetSize);
id++; if (id >= ledCount) break; arlsLock(realtimeTimeoutMs);
} uint16_t id = 0;
} else if (udpIn[0] == 4) //dnrgb for (uint16_t i = 0; i < packetSize -2; i += 3)
{ {
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00); setRealtimePixel(id, obuf[i], obuf[i+1], obuf[i+2], 0);
for (uint16_t i = 4; i < packetSize -2; i += 3)
{ id++; if (id >= ledCount) break;
if (id >= ledCount) break; }
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); strip.show();
id++; return;
} }
}
strip.show(); //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)
{
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
{
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();
}
} }
} }
} }

View File

@ -195,7 +195,7 @@ void handleNightlight()
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs); float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
if (nightlightFade) if (nightlightFade)
{ {
bri = briNlT+((nightlightTargetBri - briNlT)*nper); bri = briNlT + ((nightlightTargetBri - briNlT)*nper);
colorUpdated(5); colorUpdated(5);
} }
if (nper >= 1) if (nper >= 1)

View File

@ -16,35 +16,30 @@ void alexaInit()
{ {
if (alexaEnabled && WiFi.status() == WL_CONNECTED) if (alexaEnabled && WiFi.status() == WL_CONNECTED)
{ {
udpConnected = connectUDP(); alexaUdpConnected = connectUDP();
if (udpConnected) alexaInitPages(); if (alexaUdpConnected) alexaInitPages();
} }
} }
void handleAlexa() void handleAlexa()
{ {
if (alexaEnabled && WiFi.status() == WL_CONNECTED) if (!alexaEnabled || WiFi.status() != WL_CONNECTED || !alexaUdpConnected) return;
{
if(udpConnected){ // if there's data available, read a packet
// if theres data available, read a packet int packetSize = alexaUDP.parsePacket();
int packetSize = alexaUDP.parsePacket(); if(packetSize < 1) return;
if(packetSize>0) {
IPAddress remote = alexaUDP.remoteIP(); IPAddress remote = alexaUDP.remoteIP();
int len = alexaUDP.read(obuf, 254); int len = alexaUDP.read(obuf, 254);
if (len > 0) { if (len > 0) obuf[len] = 0;
obuf[len] = 0;
} if(strstr(obuf,"M-SEARCH") > 0) {
if(strstr(obuf,"upnp:rootdevice") > 0 || strstr(obuf,"device:basic:1") > 0) {
if(strstr(obuf,"M-SEARCH") > 0) { DEBUG_PRINTLN("Responding search req...");
if(strstr(obuf,"upnp:rootdevice") > 0 || strstr(obuf,"device:basic:1") > 0) { respondToSearch();
DEBUG_PRINTLN("Responding search req..."); }
respondToSearch(); }
}
}
}
}
}
} }
void alexaOn() void alexaOn()
@ -94,126 +89,125 @@ void alexaDim(byte briL)
} }
void respondToSearch() { void respondToSearch() {
DEBUG_PRINTLN(""); DEBUG_PRINTLN("");
DEBUG_PRINT("Send resp to "); DEBUG_PRINT("Send resp to ");
DEBUG_PRINTLN(alexaUDP.remoteIP()); DEBUG_PRINTLN(alexaUDP.remoteIP());
DEBUG_PRINT("Port : "); DEBUG_PRINT("Port : ");
DEBUG_PRINTLN(alexaUDP.remotePort()); DEBUG_PRINTLN(alexaUDP.remotePort());
IPAddress localIP = WiFi.localIP(); IPAddress localIP = WiFi.localIP();
char s[16]; char s[16];
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]); sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
olen = 0; olen = 0;
oappend( oappend(
"HTTP/1.1 200 OK\r\n" "HTTP/1.1 200 OK\r\n"
"EXT:\r\n" "EXT:\r\n"
"CACHE-CONTROL: max-age=100\r\n" // SSDP_INTERVAL "CACHE-CONTROL: max-age=100\r\n" // SSDP_INTERVAL
"LOCATION: http://"); "LOCATION: http://");
oappend(s); oappend(s);
oappend(":80/description.xml\r\n" oappend(":80/description.xml\r\n"
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.17.0\r\n" // _modelName, _modelNumber "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.17.0\r\n" // _modelName, _modelNumber
"hue-bridgeid: "); "hue-bridgeid: ");
oappend((char*)escapedMac.c_str()); oappend((char*)escapedMac.c_str());
oappend("\r\n" oappend("\r\n"
"ST: urn:schemas-upnp-org:device:basic:1\r\n" // _deviceType "ST: urn:schemas-upnp-org:device:basic:1\r\n" // _deviceType
"USN: uuid:2f402f80-da50-11e1-9b23-"); "USN: uuid:2f402f80-da50-11e1-9b23-");
oappend((char*)escapedMac.c_str()); oappend((char*)escapedMac.c_str());
oappend("::upnp:rootdevice\r\n" // _uuid::_deviceType oappend("::upnp:rootdevice\r\n" // _uuid::_deviceType
"\r\n"); "\r\n");
alexaUDP.beginPacket(alexaUDP.remoteIP(), alexaUDP.remotePort()); alexaUDP.beginPacket(alexaUDP.remoteIP(), alexaUDP.remotePort());
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
alexaUDP.write((byte*)obuf, olen); alexaUDP.write((byte*)obuf, olen);
#else #else
alexaUDP.write(obuf); alexaUDP.write(obuf);
#endif #endif
alexaUDP.endPacket(); alexaUDP.endPacket();
DEBUG_PRINTLN("Response sent!"); DEBUG_PRINTLN("Response sent!");
} }
void alexaInitPages() { void alexaInitPages() {
server.on("/description.xml", HTTP_GET, [](){ server.on("/description.xml", HTTP_GET, [](){
DEBUG_PRINTLN(" # Responding to description.xml ... #\n"); DEBUG_PRINTLN(" # Responding to description.xml ... #\n");
IPAddress localIP = WiFi.localIP(); IPAddress localIP = WiFi.localIP();
char s[16]; char s[16];
sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]); sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
olen = 0; olen = 0;
oappend("<?xml version=\"1.0\" ?>" oappend("<?xml version=\"1.0\" ?>"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">" "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
"<specVersion><major>1</major><minor>0</minor></specVersion>" "<specVersion><major>1</major><minor>0</minor></specVersion>"
"<URLBase>http://"); "<URLBase>http://");
oappend(s); oappend(s);
oappend(":80/</URLBase>" oappend(":80/</URLBase>"
"<device>" "<device>"
"<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>" "<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>"
"<friendlyName>Philips hue ("); "<friendlyName>Philips hue (");
oappend(s); oappend(s);
oappend(")</friendlyName>" oappend(")</friendlyName>"
"<manufacturer>Royal Philips Electronics</manufacturer>" "<manufacturer>Royal Philips Electronics</manufacturer>"
"<manufacturerURL>http://www.philips.com</manufacturerURL>" "<manufacturerURL>http://www.philips.com</manufacturerURL>"
"<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>" "<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>"
"<modelName>Philips hue bridge 2012</modelName>" "<modelName>Philips hue bridge 2012</modelName>"
"<modelNumber>929000226503</modelNumber>" "<modelNumber>929000226503</modelNumber>"
"<modelURL>http://www.meethue.com</modelURL>" "<modelURL>http://www.meethue.com</modelURL>"
"<serialNumber>"); "<serialNumber>");
oappend((char*)escapedMac.c_str()); oappend((char*)escapedMac.c_str());
oappend("</serialNumber>" oappend("</serialNumber>"
"<UDN>uuid:2f402f80-da50-11e1-9b23-"); "<UDN>uuid:2f402f80-da50-11e1-9b23-");
oappend((char*)escapedMac.c_str()); oappend((char*)escapedMac.c_str());
oappend("</UDN>" oappend("</UDN>"
"<presentationURL>index.html</presentationURL>" "<presentationURL>index.html</presentationURL>"
"<iconList>" "<iconList>"
" <icon>" " <icon>"
" <mimetype>image/png</mimetype>" " <mimetype>image/png</mimetype>"
" <height>48</height>" " <height>48</height>"
" <width>48</width>" " <width>48</width>"
" <depth>24</depth>" " <depth>24</depth>"
" <url>hue_logo_0.png</url>" " <url>hue_logo_0.png</url>"
" </icon>" " </icon>"
" <icon>" " <icon>"
" <mimetype>image/png</mimetype>" " <mimetype>image/png</mimetype>"
" <height>120</height>" " <height>120</height>"
" <width>120</width>" " <width>120</width>"
" <depth>24</depth>" " <depth>24</depth>"
" <url>hue_logo_3.png</url>" " <url>hue_logo_3.png</url>"
" </icon>" " </icon>"
"</iconList>" "</iconList>"
"</device>" "</device>"
"</root>"); "</root>");
server.send(200, "text/xml", obuf);
DEBUG_PRINTLN("Sending setup_xml"); server.send(200, "text/xml", obuf);
});
DEBUG_PRINTLN("Sending setup_xml");
});
// openHAB support // openHAB support
server.on("/on.html", HTTP_GET, [](){ server.on("/on.html", HTTP_GET, [](){
DEBUG_PRINTLN("on req"); DEBUG_PRINTLN("on req");
server.send(200, "text/plain", "turned on"); server.send(200, "text/plain", "turned on");
alexaOn(); alexaOn();
}); });
server.on("/off.html", HTTP_GET, [](){ server.on("/off.html", HTTP_GET, [](){
DEBUG_PRINTLN("off req"); DEBUG_PRINTLN("off req");
server.send(200, "text/plain", "turned off"); server.send(200, "text/plain", "turned off");
alexaOff(); alexaOff();
}); });
server.on("/status.html", HTTP_GET, [](){ server.on("/status.html", HTTP_GET, [](){
DEBUG_PRINTLN("Got status request"); DEBUG_PRINTLN("Got status request");
char statrespone[] = "0"; char statrespone[] = "0";
if (bri > 0) { if (bri > 0) {
statrespone[0] = '1'; statrespone[0] = '1';
} }
server.send(200, "text/plain", statrespone); server.send(200, "text/plain", statrespone);
});
});
} }
String boolString(bool st) String boolString(bool st)
@ -288,9 +282,10 @@ bool connectUDP(){
return state; return state;
} }
#else #else
void alexaInit(){} void alexaInit(){}
void handleAlexa(){} void handleAlexa(){}
void alexaInitPages(){} void alexaInitPages(){}
bool handleAlexaApiCall(String req, String body){return false;} bool handleAlexaApiCall(String req, String body){return false;}
#endif #endif

View File

@ -145,72 +145,72 @@ void setCronixie()
void _overlayCronixie() void _overlayCronixie()
{ {
if (countdownMode) checkCountdown(); if (countdownMode) checkCountdown();
#ifndef WLED_DISABLE_CRONIXIE #ifndef WLED_DISABLE_CRONIXIE
byte h = hour(local); byte h = hour(local);
byte h0 = h; byte h0 = h;
byte m = minute(local); byte m = minute(local);
byte s = second(local); byte s = second(local);
byte d = day(local); byte d = day(local);
byte mi = month(local); byte mi = month(local);
int y = year(local); int y = year(local);
//this has to be changed in time for 22nd century //this has to be changed in time for 22nd century
y -= 2000; if (y<0) y += 30; //makes countdown work y -= 2000; if (y<0) y += 30; //makes countdown work
if (useAMPM && !countdownMode) if (useAMPM && !countdownMode)
{ {
if (h>12) h-=12; if (h>12) h-=12;
else if (h==0) h+=12; else if (h==0) h+=12;
} }
byte _digitOut[]{10,10,10,10,10,10}; byte _digitOut[]{10,10,10,10,10,10};
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if (dP[i] < 12) _digitOut[i] = dP[i]; if (dP[i] < 12) _digitOut[i] = dP[i];
else { else {
if (dP[i] < 65) 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 21: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; i++; break; //HH case 31: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; i++; break; //SS
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 20: _digitOut[i] = h- (h/10)*10; break; //H
case 24: _digitOut[i] = m/10; break; //M case 24: _digitOut[i] = m/10; break; //M
case 30: _digitOut[i] = s/10; break; //S 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 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 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 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 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 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 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 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB
case 14: _digitOut[i] = (h0>11)?1:0; break; //B case 14: _digitOut[i] = (h0>11)?1:0; break; //B
} }
} else } 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 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss
case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI)
case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb
case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI) case 64: _digitOut[i] = (h0>11)?1:10; break; //b
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 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 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 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 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 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 strip.setCronixieDigits(_digitOut);
#endif //strip.trigger(); //this has a drawback, no effects slower than RefreshMs. advantage: Quick update, not dependant on effect time
#endif
} }

View File

@ -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 void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb
{ {
//this is only an approximation using WS2812B with gamma correction enabled //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 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 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 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 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 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 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 rgb[0]=247;rgb[1]=255;rgb[2]=215;//200
} else } else {
{
rgb[0]=237;rgb[1]=255;rgb[2]=239;//150 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 g = (int)255*(-X * 0.707196f + 1.655397f + Z * 0.036152f);
float b = (int)255*(X * 0.051713f - 0.121364f + Z * 1.011530f); float b = (int)255*(X * 0.051713f - 0.121364f + Z * 1.011530f);
if (r > b && r > g && r > 1.0f) { if (r > b && r > g && r > 1.0f) {
// red is too big // red is too big
g = g / r; g = g / r;
b = b / r; b = b / r;
r = 1.0f; r = 1.0f;
} else if (g > b && g > r && g > 1.0f) { } else if (g > b && g > r && g > 1.0f) {
// green is too big // green is too big
r = r / g; r = r / g;
b = b / g; b = b / g;
g = 1.0f; g = 1.0f;
} else if (b > r && b > g && b > 1.0f) { } else if (b > r && b > g && b > 1.0f) {
// blue is too big // blue is too big
r = r / b; r = r / b;
g = g / b; g = g / b;
b = 1.0f; b = 1.0f;
} }
// Apply gamma correction // Apply gamma correction
r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f; 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; b = b <= 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f;
if (r > b && r > g) { if (r > b && r > g) {
// red is biggest // red is biggest
if (r > 1.0f) { if (r > 1.0f) {
g = g / r; g = g / r;
b = b / r; b = b / r;
r = 1.0f; r = 1.0f;
} }
} else if (g > b && g > r) { } else if (g > b && g > r) {
// green is biggest // green is biggest
if (g > 1.0f) { if (g > 1.0f) {
r = r / g; r = r / g;
b = b / g; b = b / g;
g = 1.0f; g = 1.0f;
} }
} else if (b > r && b > g) { } else if (b > r && b > g) {
// blue is biggest // blue is biggest
if (b > 1.0f) { if (b > 1.0f) {
r = r / b; r = r / b;
g = g / b; g = g / b;
b = 1.0f; b = 1.0f;
} }
} }
rgb[0] = 255.0*r; rgb[0] = 255.0*r;
rgb[1] = 255.0*g; rgb[1] = 255.0*g;

View File

@ -40,22 +40,22 @@ void updateBlynk()
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
BLYNK_WRITE(V0) BLYNK_WRITE(V0)
{ {
bri = param.asInt();//bri bri = param.asInt();//bri
colorUpdated(9); colorUpdated(9);
} }
BLYNK_WRITE(V1) BLYNK_WRITE(V1)
{ {
blHue = param.asInt();//hue blHue = param.asInt();//hue
colorHStoRGB(blHue*10,blSat,(false)? colSec:col); colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
colorUpdated(9); colorUpdated(9);
} }
BLYNK_WRITE(V2) BLYNK_WRITE(V2)
{ {
blSat = param.asInt();//sat blSat = param.asInt();//sat
colorHStoRGB(blHue*10,blSat,(false)? colSec:col); colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
colorUpdated(9); colorUpdated(9);
} }
BLYNK_WRITE(V3) BLYNK_WRITE(V3)
@ -65,23 +65,23 @@ BLYNK_WRITE(V3)
BLYNK_WRITE(V4) BLYNK_WRITE(V4)
{ {
effectCurrent = param.asInt()-1;//fx effectCurrent = param.asInt()-1;//fx
strip.setMode(effectCurrent); strip.setMode(effectCurrent);
colorUpdated(6); colorUpdated(6);
} }
BLYNK_WRITE(V5) BLYNK_WRITE(V5)
{ {
effectSpeed = param.asInt();//sx effectSpeed = param.asInt();//sx
strip.setSpeed(effectSpeed); strip.setSpeed(effectSpeed);
colorUpdated(6); colorUpdated(6);
} }
BLYNK_WRITE(V6) BLYNK_WRITE(V6)
{ {
effectIntensity = param.asInt();//ix effectIntensity = param.asInt();//ix
strip.setIntensity(effectIntensity); strip.setIntensity(effectIntensity);
colorUpdated(6); colorUpdated(6);
} }
BLYNK_WRITE(V7) BLYNK_WRITE(V7)

View File

@ -14,6 +14,7 @@ void parseMQTTBriPayload(char* payload)
} }
} }
void callbackMQTT(char* topic, byte* payload, unsigned int length) { void callbackMQTT(char* topic, byte* payload, unsigned int length) {
DEBUG_PRINT("MQTT callb rec: "); DEBUG_PRINT("MQTT callb rec: ");
@ -37,6 +38,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) {
} }
} }
void publishMQTT() void publishMQTT()
{ {
if (mqtt == NULL) return; if (mqtt == NULL) return;
@ -64,6 +66,7 @@ void publishMQTT()
mqtt->publish(subuf, obuf);*/ mqtt->publish(subuf, obuf);*/
} }
bool reconnectMQTT() bool reconnectMQTT()
{ {
if (mqtt->connect(escapedMac.c_str())) if (mqtt->connect(escapedMac.c_str()))
@ -99,6 +102,7 @@ bool reconnectMQTT()
return mqtt->connected(); return mqtt->connected();
} }
bool initMQTT() bool initMQTT()
{ {
if (WiFi.status() != WL_CONNECTED) return false; if (WiFi.status() != WL_CONNECTED) return false;
@ -116,6 +120,7 @@ bool initMQTT()
return true; return true;
} }
void handleMQTT() void handleMQTT()
{ {
if (WiFi.status() != WL_CONNECTED || !mqttInit) return; if (WiFi.status() != WL_CONNECTED || !mqttInit) return;

View File

@ -259,25 +259,26 @@ void serveIndex()
if (uiConfiguration == 0) serveMobile = checkClientIsMobile(server.header("User-Agent")); if (uiConfiguration == 0) serveMobile = checkClientIsMobile(server.header("User-Agent"));
else if (uiConfiguration == 2) serveMobile = true; 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); 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) 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
if (!realtimeActive || enableRealtimeUI) //do not serve while receiving realtime {
{ serveRealtimeError(true);
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage return;
if (subPage == 255) {serveIndex(); return;} }
#endif
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage
int pl0, pl1; if (subPage == 255) {serveIndex(); return;}
switch (subPage) #endif
{
case 1: pl0 = strlen_P(PAGE_settings_wifi0); pl1 = strlen_P(PAGE_settings_wifi1); break; int pl0, pl1;
case 2: pl0 = strlen_P(PAGE_settings_leds0); pl1 = strlen_P(PAGE_settings_leds1); break; switch (subPage) //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec 255: welcomepage
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 1: pl0 = strlen_P(PAGE_settings_wifi0); pl1 = strlen_P(PAGE_settings_wifi1); break;
case 5: pl0 = strlen_P(PAGE_settings_time0); pl1 = strlen_P(PAGE_settings_time1); break; case 2: pl0 = strlen_P(PAGE_settings_leds0); pl1 = strlen_P(PAGE_settings_leds1); break;
case 6: pl0 = strlen_P(PAGE_settings_sec0); pl1 = strlen_P(PAGE_settings_sec1); break; case 3: pl0 = strlen_P(PAGE_settings_ui0); pl1 = strlen_P(PAGE_settings_ui1); break;
case 255: pl0 = strlen_P(PAGE_welcome0); pl1 = strlen_P(PAGE_welcome1); break; case 4: pl0 = strlen_P(PAGE_settings_sync0); pl1 = strlen_P(PAGE_settings_sync1); break;
default: pl0 = strlen_P(PAGE_settings0); pl1 = strlen_P(PAGE_settings1); 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;
getSettingsJS(subPage); default: pl0 = strlen_P(PAGE_settings0); pl1 = strlen_P(PAGE_settings1);
int sCssLength = (subPage >0 && subPage <7)?strlen_P(PAGE_settingsCss):0; }
server.setContentLength(pl0 + cssColorString.length() + olen + sCssLength + pl1); getSettingsJS(subPage);
server.send(200, "text/html", ""); int sCssLength = (subPage >0 && subPage <7)?strlen_P(PAGE_settingsCss):0;
switch (subPage) server.setContentLength(pl0 + cssColorString.length() + olen + sCssLength + pl1);
{ server.send(200, "text/html", "");
case 1: server.sendContent_P(PAGE_settings_wifi0); break;
case 2: server.sendContent_P(PAGE_settings_leds0); break; switch (subPage)
case 3: server.sendContent_P(PAGE_settings_ui0); break; {
case 4: server.sendContent_P(PAGE_settings_sync0); break; case 1: server.sendContent_P(PAGE_settings_wifi0); break;
case 5: server.sendContent_P(PAGE_settings_time0); break; case 2: server.sendContent_P(PAGE_settings_leds0); break;
case 6: server.sendContent_P(PAGE_settings_sec0); break; case 3: server.sendContent_P(PAGE_settings_ui0); break;
case 255: server.sendContent_P(PAGE_welcome0); break; case 4: server.sendContent_P(PAGE_settings_sync0); break;
default: server.sendContent_P(PAGE_settings0); case 5: server.sendContent_P(PAGE_settings_time0); break;
} case 6: server.sendContent_P(PAGE_settings_sec0); break;
server.sendContent(obuf); case 255: server.sendContent_P(PAGE_welcome0); break;
server.sendContent(cssColorString); default: server.sendContent_P(PAGE_settings0);
if (subPage >0 && subPage <7) server.sendContent_P(PAGE_settingsCss); }
switch (subPage) server.sendContent(obuf);
{ server.sendContent(cssColorString);
case 1: server.sendContent_P(PAGE_settings_wifi1); break; if (subPage >0 && subPage <7) server.sendContent_P(PAGE_settingsCss);
case 2: server.sendContent_P(PAGE_settings_leds1); break; switch (subPage)
case 3: server.sendContent_P(PAGE_settings_ui1); break; {
case 4: server.sendContent_P(PAGE_settings_sync1); break; case 1: server.sendContent_P(PAGE_settings_wifi1); break;
case 5: server.sendContent_P(PAGE_settings_time1); break; case 2: server.sendContent_P(PAGE_settings_leds1); break;
case 6: server.sendContent_P(PAGE_settings_sec1); break; case 3: server.sendContent_P(PAGE_settings_ui1); break;
case 255: server.sendContent_P(PAGE_welcome1); break; case 4: server.sendContent_P(PAGE_settings_sync1); break;
default: server.sendContent_P(PAGE_settings1); case 5: server.sendContent_P(PAGE_settings_time1); break;
} case 6: server.sendContent_P(PAGE_settings_sec1); break;
} else { case 255: server.sendContent_P(PAGE_welcome1); break;
serveRealtimeError(true); default: server.sendContent_P(PAGE_settings1);
} }
} }