Merge branch 'virtual-bus' into dev

This commit is contained in:
Blaz Kristan 2021-09-23 21:16:59 +02:00
commit a9666a9f6e
12 changed files with 2657 additions and 2368 deletions

View File

@ -53,13 +53,14 @@ extra_configs =
arduino_core_2_6_3 = espressif8266@2.3.3 arduino_core_2_6_3 = espressif8266@2.3.3
arduino_core_2_7_4 = espressif8266@2.6.2 arduino_core_2_7_4 = espressif8266@2.6.2
arduino_core_3_0_0 = espressif8266@3.0.0 arduino_core_3_0_0 = espressif8266@3.0.0
arduino_core_3_2_0 = espressif8266@3.2.0
# Development platforms # Development platforms
arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop
arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage
# Platform to use for ESP8266 # Platform to use for ESP8266
platform_wled_default = ${common.arduino_core_2_7_4} platform_wled_default = ${common.arduino_core_3_2_0}
# We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization # We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization
platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7 platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7
platformio/toolchain-xtensa @ ~2.40802.200502 platformio/toolchain-xtensa @ ~2.40802.200502

View File

@ -10,6 +10,20 @@
#include "bus_wrapper.h" #include "bus_wrapper.h"
#include <Arduino.h> #include <Arduino.h>
// enable additional debug output
#ifdef WLED_DEBUG
#ifndef ESP8266
#include <rom/rtc.h>
#endif
#define DEBUG_PRINT(x) Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define DEBUG_PRINTF(x...) Serial.printf(x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINTF(x...)
#endif
#define GET_BIT(var,bit) (((var)>>(bit))&0x01) #define GET_BIT(var,bit) (((var)>>(bit))&0x01)
#define SET_BIT(var,bit) ((var)|=(uint16_t)(0x0001<<(bit))) #define SET_BIT(var,bit) ((var)|=(uint16_t)(0x0001<<(bit)))
#define UNSET_BIT(var,bit) ((var)&=(~(uint16_t)(0x0001<<(bit)))) #define UNSET_BIT(var,bit) ((var)&=(~(uint16_t)(0x0001<<(bit))))
@ -29,7 +43,8 @@ struct BusConfig {
type = busType & 0x7F; // bit 7 may be/is hacked to include RGBW info (1=RGBW, 0=RGB) type = busType & 0x7F; // bit 7 may be/is hacked to include RGBW info (1=RGBW, 0=RGB)
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip;
uint8_t nPins = 1; uint8_t nPins = 1;
if (type > 47) nPins = 2; if (type >= 10 || type <= 15) nPins = 4;
else if (type > 47) nPins = 2;
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type); else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i]; for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
} }
@ -353,6 +368,103 @@ class BusPwm : public Bus {
} }
}; };
class BusNetwork : public Bus {
public:
BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start) {
_valid = false;
_data = (byte *)malloc(bc.count * (_rgbw ? 4 : 3));
if (_data == nullptr) return;
memset(_data, 0, bc.count * (_rgbw ? 4 : 3));
_len = bc.count;
_rgbw = false;
//_rgbw = bc.rgbwOverride; // RGBW override in bit 7 or can have a special type
_colorOrder = bc.colorOrder;
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
_broadcastLock = false;
_valid = true;
};
void setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid || pix >= _len) return;
uint16_t offset = pix*(_rgbw?4:3);
_data[offset] = 0xFF & (c >> 16);
_data[offset+1] = 0xFF & (c >> 8);
_data[offset+2] = 0xFF & (c );
if (_rgbw) _data[offset+3] = 0xFF & (c >> 24);
}
uint32_t getPixelColor(uint16_t pix) {
if (!_valid || pix >= _len) return 0;
uint16_t offset = pix*(_rgbw?4:3);
return ((_rgbw?(_data[offset+3] << 24):0) | (_data[offset] << 16) | (_data[offset+1] << 8) | (_data[offset+2]));
}
void show() {
uint8_t type;
if (!_valid || _broadcastLock) return;
_broadcastLock = true;
switch (_type) {
case TYPE_NET_ARTNET_RGB: type = 2; break;
case TYPE_NET_E131_RGB: type = 1; break;
case TYPE_NET_DDP_RGB:
default: type = 0; break;
}
realtimeBroadcast(type, _client, _len, _data, _rgbw);
_broadcastLock = false;
}
inline bool canShow() {
return !_broadcastLock;
}
inline void setBrightness(uint8_t b) {
// not sure if this is correctly implemented
for (uint16_t pix=0; pix<_len; pix++) {
uint16_t offset = pix*(_rgbw?4:3);
_data[offset ] = scale8(_data[offset ], b);
_data[offset+1] = scale8(_data[offset+1], b);
_data[offset+2] = scale8(_data[offset+2], b);
if (_rgbw) _data[offset+3] = scale8(_data[offset+3], b);
}
}
uint8_t getPins(uint8_t* pinArray) {
for (uint8_t i = 0; i < 4; i++) {
pinArray[i] = _client[i];
}
return 4;
}
inline bool isRgbw() {
return _rgbw;
}
inline uint16_t getLength() {
return _len;
}
void cleanup() {
_type = I_NONE;
_valid = false;
if (_data != nullptr) free(_data);
_data = nullptr;
}
~BusNetwork() {
cleanup();
}
private:
IPAddress _client;
uint16_t _len = 0;
uint8_t _colorOrder;
bool _rgbw;
bool _broadcastLock;
byte* _data;
};
class BusManager { class BusManager {
public: public:
BusManager() { BusManager() {
@ -363,7 +475,7 @@ class BusManager {
static uint32_t memUsage(BusConfig &bc) { static uint32_t memUsage(BusConfig &bc) {
uint8_t type = bc.type; uint8_t type = bc.type;
uint16_t len = bc.count; uint16_t len = bc.count;
if (type < 32) { if (type > 15 && type < 32) {
#ifdef ESP8266 #ifdef ESP8266
if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
if (type > 29) return len*20; //RGBW if (type > 29) return len*20; //RGBW
@ -379,12 +491,14 @@ class BusManager {
if (type > 31 && type < 48) return 5; if (type > 31 && type < 48) return 5;
if (type == 44 || type == 45) return len*4; //RGBW if (type == 44 || type == 45) return len*4; //RGBW
return len*3; return len*3; //RGB
} }
int add(BusConfig &bc) { int add(BusConfig &bc) {
if (numBusses >= WLED_MAX_BUSSES) return -1; if (numBusses >= WLED_MAX_BUSSES) return -1;
if (IS_DIGITAL(bc.type)) { if (bc.type>=10 && bc.type<=15) {
busses[numBusses] = new BusNetwork(bc);
} else if (IS_DIGITAL(bc.type)) {
busses[numBusses] = new BusDigital(bc, numBusses); busses[numBusses] = new BusDigital(bc, numBusses);
} else { } else {
busses[numBusses] = new BusPwm(bc); busses[numBusses] = new BusPwm(bc);

View File

@ -122,6 +122,10 @@
#define TYPE_NONE 0 //light is not configured #define TYPE_NONE 0 //light is not configured
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light #define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
//network types (master broadcast) (10-15)
#define TYPE_NET_DDP_RGB 10 //network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 11 //network E131 RGB bus (master broadcast bus)
#define TYPE_NET_ARTNET_RGB 12 //network ArtNet RGB bus (master broadcast bus)
//Digital types (data pin only) (16-31) //Digital types (data pin only) (16-31)
#define TYPE_WS2812_1CH 20 //white-only chips #define TYPE_WS2812_1CH 20 //white-only chips
#define TYPE_WS2812_WWA 21 //amber + warm + cold white #define TYPE_WS2812_WWA 21 //amber + warm + cold white

View File

@ -419,11 +419,11 @@ button {
overflow: auto; overflow: auto;
} }
#info { #info, #nodes {
z-index: 3; z-index: 3;
} }
#rover, #nodes { #rover {
z-index: 2; z-index: 2;
} }

View File

@ -1,459 +1,501 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<title>LED Settings</title> <title>LED Settings</title>
<script> <script>
var d=document,laprev=55,maxB=1,maxM=5000,maxPB=4096,bquot=0; //maximum bytes for LED allocation: 5kB for 8266, 32kB for 32 var d=document,laprev=55,maxB=1,maxM=5000,maxPB=4096,bquot=0; //maximum bytes for LED allocation: 5kB for 8266, 32kB for 32
function H() function H()
{ {
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#led-settings"); window.open("https://github.com/Aircoookie/WLED/wiki/Settings#led-settings");
} }
function B() function B()
{ {
window.open("/settings","_self"); window.open("/settings","_self");
} }
function gId(n){return d.getElementById(n);} function gId(n){return d.getElementById(n);}
function off(n){ function off(n){
d.getElementsByName(n)[0].value = -1; d.getElementsByName(n)[0].value = -1;
} }
var timeout; var timeout;
function showToast(text, error = false) function showToast(text, error = false)
{ {
var x = gId("toast"); var x = gId("toast");
x.innerHTML = text; x.innerHTML = text;
x.className = error ? "error":"show"; x.className = error ? "error":"show";
clearTimeout(timeout); clearTimeout(timeout);
x.style.animation = 'none'; x.style.animation = 'none';
timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900); timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900);
} }
function bLimits(b,p,m) { function bLimits(b,p,m) {
maxB = b; maxM = m; maxPB = p; maxB = b; maxM = m; maxPB = p;
} }
function pinsOK() { function pinsOK() {
var LCs = d.getElementsByTagName("input"); var LCs = d.getElementsByTagName("input");
for (i=0; i<LCs.length; i++) { for (i=0; i<LCs.length; i++) {
var nm = LCs[i].name.substring(0,2); var nm = LCs[i].name.substring(0,2);
//check for pin conflicts // ignore IP address
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR") if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
if (LCs[i].value!="" && LCs[i].value!="-1") { var n = LCs[i].name.substring(2);
if (d.um_p && d.um_p.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(d.um_p)} can't be used.`);LCs[i].value="";LCs[i].focus();return false;} var t = parseInt(d.getElementsByName("LT"+n)[0].value, 10); // LED type SELECT
else if (LCs[i].value > 5 && LCs[i].value < 12) {alert("Sorry, pins 6-11 can not be used.");LCs[i].value="";LCs[i].focus();return false;} if (t<16) continue;
else if (!(nm == "IR" || nm=="BT") && LCs[i].value > 33) {alert("Sorry, pins >33 are input only.");LCs[i].value="";LCs[i].focus();return false;} }
for (j=i+1; j<LCs.length; j++) //check for pin conflicts
{ if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
var n2 = LCs[j].name.substring(0,2); if (LCs[i].value!="" && LCs[i].value!="-1") {
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") if (d.um_p && d.um_p.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(d.um_p)} can't be used.`);LCs[i].value="";LCs[i].focus();return false;}
if (LCs[j].value!="" && LCs[i].value==LCs[j].value) {alert(`Pin conflict between ${LCs[i].name}/${LCs[j].name}!`);LCs[j].value="";LCs[j].focus();return false;} else if (LCs[i].value > 5 && LCs[i].value < 12) {alert("Sorry, pins 6-11 can not be used.");LCs[i].value="";LCs[i].focus();return false;}
} else if (!(nm == "IR" || nm=="BT") && LCs[i].value > 33) {alert("Sorry, pins >33 are input only.");LCs[i].value="";LCs[i].focus();return false;}
} for (j=i+1; j<LCs.length; j++)
} {
return true; var n2 = LCs[j].name.substring(0,2);
} if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
function trySubmit(e) { if (n2.substring(0,1)==="L") {
d.Sf.data.value = ''; var m = LCs[j].name.substring(2);
e.preventDefault(); var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server if (t2<16) continue;
if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000) msg += "\n\rConsider using an ESP32."; alert(msg);} }
if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914 if (LCs[j].value!="" && LCs[i].value==LCs[j].value) {alert(`Pin conflict between ${LCs[i].name}/${LCs[j].name}!`);LCs[j].value="";LCs[j].focus();return false;}
} }
function S(){GetV();setABL();} }
function enABL() }
{ }
var en = gId('able').checked; return true;
d.Sf.LA.value = (en) ? laprev:0; }
gId('abl').style.display = (en) ? 'inline':'none'; function trySubmit(e) {
gId('psu2').style.display = (en) ? 'inline':'none'; d.Sf.data.value = '';
if (d.Sf.LA.value > 0) setABL(); e.preventDefault();
} if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server
function enLA() if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000) msg += "\n\rConsider using an ESP32."; alert(msg);}
{ if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914
var val = d.Sf.LAsel.value; }
d.Sf.LA.value = val; function S(){GetV();setABL();}
gId('LAdis').style.display = (val == 50) ? 'inline':'none'; function enABL()
UI(); {
} var en = gId('able').checked;
function setABL() d.Sf.LA.value = (en) ? laprev:0;
{ gId('abl').style.display = (en) ? 'inline':'none';
gId('able').checked = true; gId('psu2').style.display = (en) ? 'inline':'none';
d.Sf.LAsel.value = 50; if (d.Sf.LA.value > 0) setABL();
switch (parseInt(d.Sf.LA.value)) { }
case 0: gId('able').checked = false; enABL(); break; function enLA()
case 30: d.Sf.LAsel.value = 30; break; {
case 35: d.Sf.LAsel.value = 35; break; var val = d.Sf.LAsel.value;
case 55: d.Sf.LAsel.value = 55; break; d.Sf.LA.value = val;
case 255: d.Sf.LAsel.value = 255; break; gId('LAdis').style.display = (val == 50) ? 'inline':'none';
default: gId('LAdis').style.display = 'inline'; UI();
} }
gId('m1').innerHTML = maxM; function setABL()
d.getElementsByName("Sf")[0].addEventListener("submit", trySubmit); {
UI(); gId('able').checked = true;
} d.Sf.LAsel.value = 50;
//returns mem usage switch (parseInt(d.Sf.LA.value)) {
function getMem(type, len, p0) { case 0: gId('able').checked = false; enABL(); break;
if (type < 32) { case 30: d.Sf.LAsel.value = 30; break;
if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem case 35: d.Sf.LAsel.value = 35; break;
if (type > 29) return len*20; //RGBW case 55: d.Sf.LAsel.value = 55; break;
return len*15; case 255: d.Sf.LAsel.value = 255; break;
} else if (maxM >= 10000) //ESP32 RMT uses double buffer? default: gId('LAdis').style.display = 'inline';
{ }
if (type > 29) return len*8; //RGBW gId('m1').innerHTML = maxM;
return len*6; d.getElementsByName("Sf")[0].addEventListener("submit", trySubmit);
} UI();
if (type > 29) return len*4; //RGBW }
return len*3; //returns mem usage
} function getMem(t, len, p0) {
if (type > 31 && type < 48) return 5; if (t==2 || t==3) {
if (type == 44 || type == 45) return len*4; //RGBW return len*(t+1);
return len*3; }
} if (t > 15 && t < 32) {
function UI(change=false) if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem
{ if (t > 29) return len*20; //RGBW
var isRGBW = false, memu = 0; return len*15;
} else if (maxM >= 10000) //ESP32 RMT uses double buffer?
gId('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none'; {
if (t > 29) return len*8; //RGBW
if (d.Sf.LA.value == 255) laprev = 12; return len*6;
else if (d.Sf.LA.value > 0) laprev = d.Sf.LA.value; }
if (t > 29) return len*4; //RGBW
// enable/disable LED fields return len*3;
var s = d.getElementsByTagName("select"); }
for (i=0; i<s.length; i++) { if (t > 31 && t < 48) return 5;
// is the field a LED type? if (t == 44 || t == 45) return len*4; //RGBW
if (s[i].name.substring(0,2)=="LT") { return len*3;
n=s[i].name.substring(2); }
var type = parseInt(s[i].value,10); function UI(change=false)
gId("p0d"+n).innerHTML = (type > 49) ? "Data GPIO:" : (type >41) ? "GPIOs:" : "GPIO:"; {
gId("p1d"+n).innerHTML = (type > 49) ? "Clk GPIO:" : ""; var isRGBW = false, memu = 0;
var LK = d.getElementsByName("L1"+n)[0]; // clock pin
gId('ampwarning').style.display = (d.Sf.MA.value > 7200) ? 'inline':'none';
memu += getMem(type, d.getElementsByName("LC"+n)[0].value, d.getElementsByName("L0"+n)[0].value); // calc memory
if (d.Sf.LA.value == 255) laprev = 12;
// enumerate pins else if (d.Sf.LA.value > 0) laprev = d.Sf.LA.value;
for (p=1; p<5; p++) {
var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins // enable/disable LED fields
if (!LK) continue; var s = d.getElementsByTagName("select");
if ((type>49 && p==1) || (type>41 && type < 50 && (p+40 < type))) // TYPE_xxxx values from const.h for (i=0; i<s.length; i++) {
{ // is the field a LED type?
// display pin field if (s[i].name.substring(0,2)=="LT") {
LK.style.display = "inline"; var n = s[i].name.substring(2);
LK.required = true; var t = parseInt(s[i].value,10);
} else { gId("p0d"+n).innerHTML = (t>=10 && t<=15) ? "IP address:" : (t > 49) ? "Data GPIO:" : (t >41) ? "GPIOs:" : "GPIO:";
// hide pin field gId("p1d"+n).innerHTML = (t > 49) ? "Clk GPIO:" : "";
LK.style.display = "none"; var LK = d.getElementsByName("L1"+n)[0]; // clock pin
LK.required = false;
LK.value=""; memu += getMem(t, d.getElementsByName("LC"+n)[0].value, d.getElementsByName("L0"+n)[0].value); // calc memory
}
} // enumerate pins
if (change) { for (p=1; p<5; p++) {
// // blazoncek experimental extension var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins
// gId("ew"+n).checked = (type == 30 || type == 31 || type == 44 || type == 45); // RGBW checkbox, TYPE_xxxx values from const.h if (!LK) continue;
gId("ls"+n).value = n+1; // set LED start if (((t>=10 && t<=15) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
if (type > 31 && type < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED {
} // display pin field
// // blazoncek experimental extension LK.style.display = "inline";
// gId("ew"+n).onclick = (type > 31 && type < 48) ? (function(){return false}) : (function(){}); // prevent change for analog LK.required = true;
// isRGBW |= gId("ew"+n).checked; } else {
isRGBW |= (type == 30 || type == 31 || (type > 40 && type < 46 && type != 43)); // RGBW checkbox, TYPE_xxxx values from const.h // hide pin field
gId("co"+n).style.display = (type == 41 || type == 42) ? "none":"inline"; // hide color order for PWM W & WW/CW LK.style.display = "none";
gId("dig"+n+"c").style.display = (type > 40 && type < 48) ? "none":"inline"; // hide skip 1st & count for analog LK.required = false;
gId("dig"+n+"s").style.display = (type > 40 && type < 48) ? "none":"inline"; // hide skip 1st & count for analog LK.value="";
gId("rev"+n).innerHTML = (type > 40 && type < 48) ? "Inverted":"Reverse (rotated 180°)"; // change reverse text for analog }
gId("psd"+n).innerHTML = (type > 40 && type < 48) ? "Index:":"Start:"; // change analog start description }
} if (change) {
} // // blazoncek experimental extension
// display white channel calculation method // gId("ew"+n).checked = (t == 30 || t == 31 || t == 44 || t == 45); // RGBW checkbox, TYPE_xxxx values from const.h
var myC = d.querySelectorAll('.wc'), gId("ls"+n).value = n+1; // set LED start
l = myC.length; if (t > 31 && t < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED
for (i = 0; i < l; i++) { }
myC[i].style.display = (isRGBW) ? 'inline':'none'; // // blazoncek experimental extension
} // gId("ew"+n).onclick = (t > 31 && t < 48) ? (function(){return false}) : (function(){}); // prevent change for analog
// check for pin conflicts // isRGBW |= gId("ew"+n).checked;
var LCs = d.getElementsByTagName("input"); isRGBW |= (t == 30 || t == 31 || (t > 40 && t < 46 && t != 43)); // RGBW checkbox, TYPE_xxxx values from const.h
var sLC = 0, maxLC = 0; gId("co"+n).style.display = (t<16 || t == 41 || t == 42) ? "none":"inline"; // hide color order for PWM W & WW/CW
for (i=0; i<LCs.length; i++) { gId("dig"+n+"c").style.display = (t > 40 && t < 48) ? "none":"inline"; // hide count for analog
var nm = LCs[i].name.substring(0,2); gId("dig"+n+"r").style.display = (t<16) ? "none":"inline"; // hide reversed for virtual
// do we have a led count field but not total led count gId("dig"+n+"s").style.display = (t<16 || (t > 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
if (nm=="LC" && LCs[i].name !== "LC") { gId("rev"+n).innerHTML = (t > 40 && t < 48) ? "Inverted":"Reverse (rotated 180°)"; // change reverse text for analog
var n=LCs[i].name.substring(2); gId("psd"+n).innerHTML = (t > 40 && t < 48) ? "Index:":"Start:"; // change analog start description
var c=parseInt(LCs[i].value,10); }
/*if(gId("ls"+n).readOnly)*/ gId("ls"+n).value=sLC; // update led start field }
if(c){sLC+=c;if(c>maxLC)maxLC=c;} // increase led count // display white channel calculation method
continue; var myC = d.querySelectorAll('.wc'),
} l = myC.length;
// do we have led pins for digital leds for (i = 0; i < l; i++) {
if (nm=="L0" || nm=="L1") { myC[i].style.display = (isRGBW) ? 'inline':'none';
var lc=d.getElementsByName("LC"+LCs[i].name.substring(2))[0]; }
lc.max=maxPB; // update max led count value // check for pin conflicts
} var LCs = d.getElementsByTagName("input");
// for pins check conflicts var sLC = 0, maxLC = 0;
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR") for (i=0; i<LCs.length; i++) {
if (LCs[i].value!="" && LCs[i].value!="-1") { var nm = LCs[i].name.substring(0,2); // field name
var p = []; // used pin array var n = LCs[i].name.substring(2); // bus number
if (d.um_p && Array.isArray(d.um_p)) for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); // fill with reservations // do we have a led count field but not total led count
for (j=0; j<LCs.length; j++) { if (nm=="LC" && LCs[i].name !== "LC") {
if (i==j) continue; var c=parseInt(LCs[i].value,10);
var n2 = LCs[j].name.substring(0,2); /*if(gId("ls"+n).readOnly)*/ gId("ls"+n).value=sLC; // update led start field
if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") if(c){sLC+=c;if(c>maxLC)maxLC=c;} // increase led count
if (LCs[j].value!="" && LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); // add current pin continue;
} }
// now check for conflicts // do we have led pins for digital leds
if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color=parseInt(LCs[i].value,10)>33?"orange":"#fff"; if (nm=="L0" || nm=="L1") {
} var lc=d.getElementsByName("LC"+n)[0];
} lc.max=maxPB; // update max led count value
// update total led count }
if (gId("LC").readOnly) d.getElementsByName("LC")[0].value = sLC; // ignore IP address
// if we are changing total led count update led count for 1st strip if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
if (d.activeElement == d.getElementsByName("LC")[0]) { var t = parseInt(d.getElementsByName("LT"+n)[0].value, 10); // LED type SELECT
var o = d.getElementsByClassName("iST"); if (t<16) {
var i = o.length; LCs[i].max = 255;
if (i == 1) d.getElementsByName("LC0")[0].value = d.getElementsByName("LC")[0].value; LCs[i].min = 0;
} continue; // do not check conflicts
// memory usage and warnings } else {
gId('m0').innerHTML = memu; LCs[i].max = 33;
bquot = memu / maxM * 100; LCs[i].min = -1;
gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%%, #444 ${bquot}%% 100%%)`; }
gId('ledwarning').style.display = (sLC > maxPB || maxLC > 800 || bquot > 80) ? 'inline':'none'; }
gId('ledwarning').style.color = (sLC > maxPB || maxLC > maxPB || bquot > 100) ? 'red':'orange'; // check for pin conflicts
gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (<b>WARNING: Using over ${maxM}B!</b>)` : "") : "800 LEDs per GPIO"; if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
// calculate power if (LCs[i].value!="" && LCs[i].value!="-1") {
var val = Math.ceil((100 + sLC * laprev)/500)/2; var p = []; // used pin array
val = (val > 5) ? Math.ceil(val) : val; if (d.um_p && Array.isArray(d.um_p)) for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); // fill with reservations
var s = ""; for (j=0; j<LCs.length; j++) {
var is12V = (d.Sf.LAsel.value == 30); if (i==j) continue;
var isWS2815 = (d.Sf.LAsel.value == 255); var n2 = LCs[j].name.substring(0,2);
if (val < 1.02 && !is12V && !isWS2815) if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
{ if (n2.substring(0,1)==="L") {
s = "ESP 5V pin with 1A USB supply"; var m = LCs[j].name.substring(2);
} else var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
{ if (t2<16) continue;
s += is12V ? "12V ": isWS2815 ? "WS2815 12V " : "5V "; }
s += val; if (LCs[j].value!="" && LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); // add current pin
s += "A supply connected to LEDs"; }
} }
var val2 = Math.ceil((100 + sLC * laprev)/1500)/2; // now check for conflicts
val2 = (val2 > 5) ? Math.ceil(val2) : val2; if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color=parseInt(LCs[i].value,10)>33?"orange":"#fff";
var s2 = "(for most effects, ~"; }
s2 += val2; }
s2 += "A is enough)<br>"; // update total led count
gId('psu').innerHTML = s; if (gId("LC").readOnly) d.getElementsByName("LC")[0].value = sLC;
gId('psu2').innerHTML = isWS2815 ? "" : s2; // if we are changing total led count update led count for 1st strip
gId("json").style.display = d.Sf.IT.value==8 ? "" : "none"; if (d.activeElement == d.getElementsByName("LC")[0]) {
} var o = d.getElementsByClassName("iST");
function lastEnd(i) { var i = o.length;
if (i<1) return 0; if (i == 1) d.getElementsByName("LC0")[0].value = d.getElementsByName("LC")[0].value;
v = parseInt(d.getElementsByName("LS"+(i-1))[0].value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value); }
var type = parseInt(d.getElementsByName("LT"+(i-1))[0].value); // memory usage and warnings
if (type > 31 && type < 48) v = 1; //PWM busses gId('m0').innerHTML = memu;
if (isNaN(v)) return 0; bquot = memu / maxM * 100;
return v; gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%%, #444 ${bquot}%% 100%%)`;
} gId('ledwarning').style.display = (sLC > maxPB || maxLC > 800 || bquot > 80) ? 'inline':'none';
function addLEDs(n) gId('ledwarning').style.color = (sLC > maxPB || maxLC > maxPB || bquot > 100) ? 'red':'orange';
{ gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (<b>WARNING: Using over ${maxM}B!</b>)` : "") : "800 LEDs per GPIO";
if (n>1) {maxB=n; gId("+").style.display="inline"; return;} // calculate power
var val = Math.ceil((100 + sLC * laprev)/500)/2;
var o = d.getElementsByClassName("iST"); val = (val > 5) ? Math.ceil(val) : val;
var i = o.length; var s = "";
var is12V = (d.Sf.LAsel.value == 30);
if ((n==1 && i>=maxB) || (n==-1 && i==0)) return; var isWS2815 = (d.Sf.LAsel.value == 255);
if (val < 1.02 && !is12V && !isWS2815)
var f = gId("mLC"); {
if (n==1) { s = "ESP 5V pin with 1A USB supply";
// npm run build has trouble minimizing spaces inside string } else
var cn = `<div class="iST"> {
${i>0?'<hr style="width:260px">':''} s += is12V ? "12V ": isWS2815 ? "WS2815 12V " : "5V ";
${i+1}: s += val;
<select name="LT${i}" onchange="UI(true)"> s += "A supply connected to LEDs";
<option value="22">WS281x</option> }
<option value="30">SK6812 RGBW</option> var val2 = Math.ceil((100 + sLC * laprev)/1500)/2;
<option value="31">TM1814</option> val2 = (val2 > 5) ? Math.ceil(val2) : val2;
<option value="24">400kHz</option> var s2 = "(for most effects, ~";
<option value="50">WS2801</option> s2 += val2;
<option value="51">APA102</option> s2 += "A is enough)<br>";
<option value="52">LPD8806</option> gId('psu').innerHTML = s;
<option value="53">P9813</option> gId('psu2').innerHTML = isWS2815 ? "" : s2;
<option value="41">PWM White</option> gId("json").style.display = d.Sf.IT.value==8 ? "" : "none";
<option value="42">PWM WWCW</option> }
<option value="43">PWM RGB</option> function lastEnd(i) {
<option value="44">PWM RGBW</option> if (i<1) return 0;
<option value="45">PWM RGBWC</option> v = parseInt(d.getElementsByName("LS"+(i-1))[0].value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value);
</select>&nbsp; var t = parseInt(d.getElementsByName("LT"+(i-1))[0].value);
<div id="co${i}" style="display:inline">Color Order: if (t > 31 && t < 48) v = 1; //PWM busses
<select name="CO${i}"> if (isNaN(v)) return 0;
<option value="0">GRB</option> return v;
<option value="1">RGB</option> }
<option value="2">BRG</option> function addLEDs(n)
<option value="3">RBG</option> {
<option value="4">BGR</option> if (n>1) {maxB=n; gId("+").style.display="inline"; return;}
<option value="5">GBR</option>
</select></div><br> var o = d.getElementsByClassName("iST");
<span id="p0d${i}">GPIO:</span><input type="number" name="L0${i}" min="0" max="33" required class="s" onchange="UI()"/> var i = o.length;
<span id="p1d${i}"></span><input type="number" name="L1${i}" min="0" max="33" class="s" onchange="UI()"/>
<span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="33" class="s" onchange="UI()"/> if ((n==1 && i>=maxB) || (n==-1 && i==0)) return;
<span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="33" class="s" onchange="UI()"/>
<span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="33" class="s" onchange="UI()"/> var f = gId("mLC");
<br> if (n==1) {
<span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" class="l" min="0" max="8191" value="${lastEnd(i)}" readonly required />&nbsp; // npm run build has trouble minimizing spaces inside string
<div id="dig${i}c" style="display:inline">Count: <input type="number" name="LC${i}" class="l" min="0" max="${maxPB}" value="1" required oninput="UI()" /></div><br> var cn = `<div class="iST">
<span id="rev${i}">Reverse (rotated 180°)</span>: <input type="checkbox" name="CV${i}"> <hr style="width:260px">
<div id="dig${i}s" style="display:inline">&nbsp;Skip 1<sup>st</sup> LED: <input id="sl${i}" type="checkbox" name="SL${i}"></div><br> ${i+1}:
</div>`; <select name="LT${i}" onchange="UI(true)">
f.insertAdjacentHTML("beforeend", cn); <option value="22" selected>WS281x</option>
} <option value="30">SK6812 RGBW</option>
if (n==-1) { <option value="31">TM1814</option>
o[--i].remove();--i; <option value="24">400kHz</option>
} <option value="50">WS2801</option>
<option value="51">APA102</option>
gId("+").style.display = (i<maxB-1) ? "inline":"none"; <option value="52">LPD8806</option>
gId("-").style.display = (i>0) ? "inline":"none"; <option value="53">P9813</option>
<option value="41">PWM White</option>
UI(); <option value="42">PWM WWCW</option>
} <option value="43">PWM RGB</option>
function addBtn(i,p,t) { <option value="44">PWM RGBW</option>
var c = gId("btns").innerHTML; <option value="45">PWM RGBWC</option>
var bt = "BT" + i; <option value="10">DDP RGB (network)</option>
var be = "BE" + i; <option value="11">E1.31 RGB (network)</option>
c += `Button ${i} GPIO: <input type="number" min="-1" max="40" name="${bt}" onchange="UI()" class="s" value="${p}">`; <option value="12">ArtNet RGB (network)</option>
c += `<select name="${be}">` </select>&nbsp;
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`; <div id="co${i}" style="display:inline">Color Order:
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`; <select name="CO${i}">
c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`; <option value="0">GRB</option>
c += `<option value="4" ${t==4?"selected":""}>Switch</option>`; <option value="1">RGB</option>
c += `<option value="5" ${t==5?"selected":""}>PIR sensor</option>`; <option value="2">BRG</option>
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`; <option value="3">RBG</option>
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`; <option value="4">BGR</option>
c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`; <option value="5">GBR</option>
c += `</select>`; </select></div>
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`; <br>
gId("btns").innerHTML = c; <span id="p0d${i}">GPIO:</span><input type="number" name="L0${i}" min="0" max="33" required class="s" onchange="UI()"/>
} <span id="p1d${i}"></span><input type="number" name="L1${i}" min="0" max="33" class="s" onchange="UI()"/>
function uploadFile(name) { <span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="33" class="s" onchange="UI()"/>
var req = new XMLHttpRequest(); <span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="33" class="s" onchange="UI()"/>
req.addEventListener('load', function(){showToast(this.responseText,this.status >= 400)}); <span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="33" class="s" onchange="UI()"/>
req.addEventListener('error', function(e){showToast(e.stack,true);}); <br>
req.open("POST", "/upload"); <span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" class="l" min="0" max="8191" value="${lastEnd(i)}" disabled readonly required />&nbsp;
var formData = new FormData(); <div id="dig${i}c" style="display:inline">Count: <input type="number" name="LC${i}" class="l" min="0" max="${maxPB}" value="1" required oninput="UI()" /></div>
formData.append("data", d.Sf.data.files[0], name); <br>
req.send(formData); <div id="dig${i}r" style="display:inline"><span id="rev${i}">Reversed</span>: <input type="checkbox" name="CV${i}"></div>&nbsp;
d.Sf.data.value = ''; <div id="dig${i}s" style="display:inline">Skip 1<sup>st</sup> LED: <input id="sl${i}" type="checkbox" name="SL${i}"></div>
return false; <br>
} </div>`;
function GetV() f.insertAdjacentHTML("beforeend", cn);
{ }
//values injected by server while sending HTML if (n==-1) {
//maxM=5000;maxPB=1536;d.um_p=[1,6,7,8,9,10,11];addLEDs(5);d.Sf.LC.value=250;addLEDs(1);d.Sf.L00.value=2;d.Sf.L10.value=0;d.Sf.LC0.value=250;d.Sf.LT0.value=22;d.Sf.CO0.value=0;d.Sf.LS0.value=0;d.Sf.LS0.checked=0;d.Sf.MA.value=5400;d.Sf.LA.value=55;d.getElementsByClassName("pow")[0].innerHTML="350mA";d.Sf.CA.value=40;d.Sf.AW.value=3;d.Sf.BO.checked=0;d.Sf.BP.value=3;d.Sf.GB.checked=0;d.Sf.GC.checked=1;d.Sf.TF.checked=1;d.Sf.TD.value=700;d.Sf.PF.checked=0;d.Sf.BF.value=64;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=1;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=12;d.Sf.RM.checked=0;addBtn(0,0,2);addBtn(1,3,4);addBtn(2,-1,0);d.Sf.IR.value=-1; o[--i].remove();--i;
} }
</script>
<style>@import url("style.css");</style> gId("+").style.display = (i<maxB-1) ? "inline":"none";
</head> gId("-").style.display = (i>0) ? "inline":"none";
<body onload="S()">
<form id="form_s" name="Sf" method="post"> UI();
<div class="toprow"> }
<div class="helpB"><button type="button" onclick="H()">?</button></div> function addBtn(i,p,t) {
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> var c = gId("btns").innerHTML;
</div> var bt = "BT" + i;
<h2>LED &amp; Hardware setup</h2> var be = "BE" + i;
Total LED count: <input name="LC" id="LC" type="number" min="1" max="8192" oninput="UI()" required readonly><br> c += `Button ${i} GPIO: <input type="number" min="-1" max="40" name="${bt}" onchange="UI()" class="s" value="${p}">`;
<i>Recommended power supply for brightest white:</i><br> c += `<select name="${be}">`
<b><span id="psu">?</span></b><br> c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
<span id="psu2"><br></span> c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
<br> c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`;
Enable automatic brightness limiter: <input type="checkbox" name="ABen" onchange="enABL()" id="able"><br> c += `<option value="4" ${t==4?"selected":""}>Switch</option>`;
<div id="abl"> c += `<option value="5" ${t==5?"selected":""}>PIR sensor</option>`;
Maximum Current: <input name="MA" type="number" class="l" min="250" max="65000" oninput="UI()" required> mA<br> c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
<div id="ampwarning" style="color: orange; display: none;"> c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
&#9888; Your power supply provides high current.<br> c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`;
To improve the safety of your setup,<br> c += `</select>`;
please use thick cables,<br> c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
multiple power injection points and a fuse!<br> gId("btns").innerHTML = c;
</div> }
<i>Automatically limits brightness to stay close to the limit.<br> function uploadFile(name) {
Keep at &lt;1A if powering LEDs directly from the ESP 5V pin!<br> var req = new XMLHttpRequest();
If you are using an external power supply, enter its rating.<br> req.addEventListener('load', function(){showToast(this.responseText,this.status >= 400)});
(Current estimated usage: <span class="pow">unknown</span>)</i><br><br> req.addEventListener('error', function(e){showToast(e.stack,true);});
LED voltage (Max. current for a single LED):<br> req.open("POST", "/upload");
<select name="LAsel" onchange="enLA()"> var formData = new FormData();
<option value="55" selected>5V default (55mA)</option> formData.append("data", d.Sf.data.files[0], name);
<option value="35">5V efficient (35mA)</option> req.send(formData);
<option value="30">12V (30mA)</option> d.Sf.data.value = '';
<option value="255">WS2815 (12mA)</option> return false;
<option value="50">Custom</option> }
</select><br> function GetV()
<span id="LAdis" style="display: none;">Custom max. current per LED: <input name="LA" type="number" min="0" max="255" id="la" oninput="UI()" required> mA<br></span> {
<i>Keep at default if you are unsure about your type of LEDs.</i><br> //values injected by server while sending HTML
</div> //maxM=5000;maxPB=1536;d.um_p=[1,6,7,8,9,10,11];addLEDs(5);d.Sf.LC.value=250;addLEDs(1);d.Sf.L00.value=2;d.Sf.L10.value=0;d.Sf.LC0.value=250;d.Sf.LT0.value=22;d.Sf.CO0.value=0;d.Sf.LS0.value=0;d.Sf.LS0.checked=0;d.Sf.MA.value=5400;d.Sf.LA.value=55;d.getElementsByClassName("pow")[0].innerHTML="350mA";d.Sf.CA.value=40;d.Sf.AW.value=3;d.Sf.BO.checked=0;d.Sf.BP.value=3;d.Sf.GB.checked=0;d.Sf.GC.checked=1;d.Sf.TF.checked=1;d.Sf.TD.value=700;d.Sf.PF.checked=0;d.Sf.BF.value=64;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=1;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=12;d.Sf.RM.checked=0;addBtn(0,0,2);addBtn(1,3,4);addBtn(2,-1,0);d.Sf.IR.value=-1;
<h3>Hardware setup</h3> }
<div id="mLC">LED outputs:</div> </script>
<button type="button" id="+" onclick="addLEDs(1)">+</button> <style>@import url("style.css");</style>
<button type="button" id="-" onclick="addLEDs(-1)">-</button><br> </head>
LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br> <body onload="S()">
<div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br> <form id="form_s" name="Sf" method="post">
<div id="ledwarning" style="color: orange; display: none;"> <div class="toprow">
&#9888; You might run into stability or lag issues.<br> <div class="helpB"><button type="button" onclick="H()">?</button></div>
Use less than <span id="wreason">800 LEDs per pin</span> for the best experience!<br> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div> </div>
Make a segment for each output: <input type="checkbox" name="MS"> <br> <h2>LED &amp; Hardware setup</h2>
<hr style="width:260px"> Total LED count: <input name="LC" id="LC" type="number" min="1" max="8192" oninput="UI()" disabled required readonly><br>
<div id="btns"></div> <i>Recommended power supply for brightest white:</i><br>
Touch threshold: <input type="number" min="0" max="100" name="TT" required><br> <b><span id="psu">?</span></b><br>
IR GPIO: <input type="number" min="-1" max="40" name="IR" onchange="UI()" class="s"><select name="IT" onchange="UI()"> <span id="psu2"><br></span>
<option value=0>Remote disabled</option> <br>
<option value=1>24-key RGB</option> Enable automatic brightness limiter: <input type="checkbox" name="ABen" onchange="enABL()" id="able"><br>
<option value=2>24-key with CT</option> <div id="abl">
<option value=3>40-key blue</option> Maximum Current: <input name="MA" type="number" class="l" min="250" max="65000" oninput="UI()" required> mA<br>
<option value=4>44-key RGB</option> <div id="ampwarning" style="color: orange; display: none;">
<option value=5>21-key RGB</option> &#9888; Your power supply provides high current.<br>
<option value=6>6-key black</option> To improve the safety of your setup,<br>
<option value=7>9-key red</option> please use thick cables,<br>
<option value=8>JSON remote</option> multiple power injection points and a fuse!<br>
</select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br> </div>
<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"> <input type="button" value="Upload" onclick="uploadFile('/ir.json');"><br></div> <i>Automatically limits brightness to stay close to the limit.<br>
<div id="toast"></div> Keep at &lt;1A if powering LEDs directly from the ESP 5V pin!<br>
<a href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">IR info</a><br> If you are using an external power supply, enter its rating.<br>
Relay GPIO: <input type="number" min="-1" max="33" name="RL" onchange="UI()" class="s"> invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br> (Current estimated usage: <span class="pow">unknown</span>)</i><br><br>
<hr style="width:260px"> LED voltage (Max. current for a single LED):<br>
<h3>Defaults</h3> <select name="LAsel" onchange="enLA()">
Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br> <option value="55" selected>5V default (55mA)</option>
Default brightness: <input name="CA" type="number" class="m" min="0" max="255" required> (0-255)<br><br> <option value="35">5V efficient (35mA)</option>
Apply preset <input name="BP" type="number" class="m" min="0" max="250" required> at boot (0 uses defaults) <option value="30">12V (30mA)</option>
<br><br> <option value="255">WS2815 (12mA)</option>
Use Gamma correction for color: <input type="checkbox" name="GC"> (strongly recommended)<br> <option value="50">Custom</option>
Use Gamma correction for brightness: <input type="checkbox" name="GB"> (not recommended)<br><br> </select><br>
Brightness factor: <input name="BF" type="number" class="m" min="1" max="255" required> % <span id="LAdis" style="display: none;">Custom max. current per LED: <input name="LA" type="number" min="0" max="255" id="la" oninput="UI()" required> mA<br></span>
<h3>Transitions</h3> <i>Keep at default if you are unsure about your type of LEDs.</i><br>
Crossfade: <input type="checkbox" name="TF"><br> </div>
Transition Time: <input name="TD" type="number" class="xl" min="0" max="65500"> ms<br> <h3>Hardware setup</h3>
Enable Palette transitions: <input type="checkbox" name="PF"> <div id="mLC">LED outputs:</div>
<h3>Timed light</h3> <hr style="width:260px">
Default Duration: <input name="TL" type="number" class="m" min="1" max="255" required> min<br> <button type="button" id="+" onclick="addLEDs(1)">+</button>
Default Target brightness: <input name="TB" type="number" class="m" min="0" max="255" required><br> <button type="button" id="-" onclick="addLEDs(-1)">-</button><br>
Mode: LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br>
<select name="TW"> <div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br>
<option value="0">Wait and set</option> <div id="ledwarning" style="color: orange; display: none;">
<option value="1">Fade</option> &#9888; You might run into stability or lag issues.<br>
<option value="2">Fade Color</option> Use less than <span id="wreason">800 LEDs per pin</span> for the best experience!<br>
<option value="3">Sunrise</option> </div>
</select> <hr style="width:260px">
<h3>Advanced</h3> Create a segment for each output: <input type="checkbox" name="MS"> <br>
Palette blending: <hr style="width:260px">
<select name="PB"> <div id="btns"></div>
<option value="0">Linear (wrap if moving)</option> Touch threshold: <input type="number" min="0" max="100" name="TT" required><br>
<option value="1">Linear (always wrap)</option> IR GPIO: <input type="number" min="-1" max="40" name="IR" onchange="UI()" class="s"><select name="IT" onchange="UI()">
<option value="2">Linear (never wrap)</option> <option value=0>Remote disabled</option>
<option value="3">None (not recommended)</option> <option value=1>24-key RGB</option>
</select><br> <option value=2>24-key with CT</option>
<span class="wc"> <option value=3>40-key blue</option>
Auto-calculate white channel from RGB:<br> <option value=4>44-key RGB</option>
<select name="AW"> <option value=5>21-key RGB</option>
<option value=0>None</option> <option value=6>6-key black</option>
<option value=1>Brighter</option> <option value=7>9-key red</option>
<option value=2>Accurate</option> <option value=8>JSON remote</option>
<option value=3>Dual</option> </select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br>
<option value=4>Legacy</option> <div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"> <input type="button" value="Upload" onclick="uploadFile('/ir.json');"><br></div>
</select> <div id="toast"></div>
<br></span><hr> <a href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">IR info</a><br>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button> Relay GPIO: <input type="number" min="-1" max="33" name="RL" onchange="UI()" class="s"> invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br>
</form> <hr style="width:260px">
</body> <h3>Defaults</h3>
</html> Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br>
Default brightness: <input name="CA" type="number" class="m" min="0" max="255" required> (0-255)<br><br>
Apply preset <input name="BP" type="number" class="m" min="0" max="250" required> at boot (0 uses defaults)
<br><br>
Use Gamma correction for color: <input type="checkbox" name="GC"> (strongly recommended)<br>
Use Gamma correction for brightness: <input type="checkbox" name="GB"> (not recommended)<br><br>
Brightness factor: <input name="BF" type="number" class="m" min="1" max="255" required> %
<h3>Transitions</h3>
Crossfade: <input type="checkbox" name="TF"><br>
Transition Time: <input name="TD" type="number" class="xl" min="0" max="65500"> ms<br>
Enable Palette transitions: <input type="checkbox" name="PF">
<h3>Timed light</h3>
Default Duration: <input name="TL" type="number" class="m" min="1" max="255" required> min<br>
Default Target brightness: <input name="TB" type="number" class="m" min="0" max="255" required><br>
Mode:
<select name="TW">
<option value="0">Wait and set</option>
<option value="1">Fade</option>
<option value="2">Fade Color</option>
<option value="3">Sunrise</option>
</select>
<h3>Advanced</h3>
Palette blending:
<select name="PB">
<option value="0">Linear (wrap if moving)</option>
<option value="1">Linear (always wrap)</option>
<option value="2">Linear (never wrap)</option>
<option value="3">None (not recommended)</option>
</select><br>
<span class="wc">
Auto-calculate white channel from RGB:<br>
<select name="AW">
<option value=0>None</option>
<option value=1>Brighter</option>
<option value=2>Accurate</option>
<option value=3>Dual</option>
<option value=4>Legacy</option>
</select>
<br></span><hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>
</html>

View File

@ -197,6 +197,7 @@ bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte
//udp.cpp //udp.cpp
void notify(byte callMode, bool followUp=false); void notify(byte callMode, bool followUp=false);
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, bool isRGBW=false);
void realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); void realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC);
void handleNotifications(); void handleNotifications();
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -601,9 +601,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
} }
uint16_t startI = mainseg.start; uint16_t startI = mainseg.start;
uint16_t stopI = mainseg.stop; uint16_t stopI = mainseg.stop;
uint8_t grpI = mainseg.grouping; uint8_t grpI = mainseg.grouping;
uint16_t spcI = mainseg.spacing; uint16_t spcI = mainseg.spacing;
pos = req.indexOf(F("&S=")); //segment start pos = req.indexOf(F("&S=")); //segment start
if (pos > 0) { if (pos > 0) {
startI = getNumVal(&req, pos); startI = getNumVal(&req, pos);
@ -623,6 +623,30 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
} }
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI); strip.setSegment(selectedSeg, startI, stopI, grpI, spcI);
pos = req.indexOf(F("RV=")); //Segment reverse
if (pos > 0) mainseg.setOption(SEG_OPTION_REVERSED, req.charAt(pos+3) != '0');
pos = req.indexOf(F("MI=")); //Segment mirror
if (pos > 0) mainseg.setOption(SEG_OPTION_MIRROR, req.charAt(pos+3) != '0');
pos = req.indexOf(F("SB=")); //Segment brightness/opacity
if (pos > 0) {
byte segbri = getNumVal(&req, pos);
mainseg.setOption(SEG_OPTION_ON, segbri, selectedSeg);
if (segbri) {
mainseg.setOpacity(segbri, selectedSeg);
}
}
pos = req.indexOf(F("SW=")); //segment power
if (pos > 0) {
switch (getNumVal(&req, pos)) {
case 0: mainseg.setOption(SEG_OPTION_ON, false); break;
case 1: mainseg.setOption(SEG_OPTION_ON, true); break;
default: mainseg.setOption(SEG_OPTION_ON, !mainseg.getOption(SEG_OPTION_ON)); break;
}
}
pos = req.indexOf(F("PS=")); //saves current in preset pos = req.indexOf(F("PS=")); //saves current in preset
if (pos > 0) savePreset(getNumVal(&req, pos)); if (pos > 0) savePreset(getNumVal(&req, pos));
@ -713,7 +737,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
strip.applyToAllSelected = true; strip.applyToAllSelected = true;
strip.setColor(2, t[0], t[1], t[2], t[3]); strip.setColor(2, t[0], t[1], t[2], t[3]);
} else { } else {
strip.getSegment(selectedSeg).setColor(2,((t[0] << 16) + (t[1] << 8) + t[2] + (t[3] << 24)), selectedSeg); mainseg.setColor(2,((t[0] << 16) + (t[1] << 8) + t[2] + (t[3] << 24)), selectedSeg);
} }
} }
@ -817,24 +841,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
pos = req.indexOf(F("TT=")); pos = req.indexOf(F("TT="));
if (pos > 0) transitionDelay = getNumVal(&req, pos); if (pos > 0) transitionDelay = getNumVal(&req, pos);
//Segment reverse
pos = req.indexOf(F("RV="));
if (pos > 0) strip.getSegment(selectedSeg).setOption(SEG_OPTION_REVERSED, req.charAt(pos+3) != '0');
//Segment reverse
pos = req.indexOf(F("MI="));
if (pos > 0) strip.getSegment(selectedSeg).setOption(SEG_OPTION_MIRROR, req.charAt(pos+3) != '0');
//Segment brightness/opacity
pos = req.indexOf(F("SB="));
if (pos > 0) {
byte segbri = getNumVal(&req, pos);
strip.getSegment(selectedSeg).setOption(SEG_OPTION_ON, segbri, selectedSeg);
if (segbri) {
strip.getSegment(selectedSeg).setOpacity(segbri, selectedSeg);
}
}
//set time (unix timestamp) //set time (unix timestamp)
pos = req.indexOf(F("ST=")); pos = req.indexOf(F("ST="));
if (pos > 0) { if (pos > 0) {

View File

@ -1,4 +1,5 @@
#include "wled.h" #include "wled.h"
#include "src/dependencies/json/ArduinoJson-v6.h"
/* /*
* UDP sync notifier / Realtime / Hyperion / TPM2.NET * UDP sync notifier / Realtime / Hyperion / TPM2.NET
@ -89,7 +90,6 @@ void notify(byte callMode, bool followUp)
notificationTwoRequired = (followUp)? false:notifyTwice; notificationTwoRequired = (followUp)? false:notifyTwice;
} }
void realtimeLock(uint32_t timeoutMs, byte md) void realtimeLock(uint32_t timeoutMs, byte md)
{ {
if (!realtimeMode && !realtimeOverride){ if (!realtimeMode && !realtimeOverride){
@ -518,3 +518,121 @@ void sendSysInfoUDP()
notifier2Udp.write(data, sizeof(data)); notifier2Udp.write(data, sizeof(data));
notifier2Udp.endPacket(); notifier2Udp.endPacket();
} }
/*********************************************************************************************\
* Art-Net, DDP, E131 output - work in progress
\*********************************************************************************************/
#define DDP_HEADER_LEN 10
#define DDP_SYNCPACKET_LEN 10
#define DDP_FLAGS1_VER 0xc0 // version mask
#define DDP_FLAGS1_VER1 0x40 // version=1
#define DDP_FLAGS1_PUSH 0x01
#define DDP_FLAGS1_QUERY 0x02
#define DDP_FLAGS1_REPLY 0x04
#define DDP_FLAGS1_STORAGE 0x08
#define DDP_FLAGS1_TIME 0x10
#define DDP_ID_DISPLAY 1
#define DDP_ID_CONFIG 250
#define DDP_ID_STATUS 251
// 1440 channels per packet
#define DDP_CHANNELS_PER_PACKET 1440 // 480 leds
//
// Send real time UDP updates to the specified client
//
// type - protocol type (1=DDP, 2=E1.31, 3=ArtNet)
// client - the IP address to send to
// length - the number of pixels
// buffer - a buffer of at least length*4 bytes long
// isRGBW - true if the buffer contains 4 components per pixel
uint8_t sequenceNumber = 0; // this needs to be shared across all outputs
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW) {
if (!interfacesInited) return 1; // network not initialised
WiFiUDP ddpUdp;
switch (type) {
case 0: // DDP
{
// calclate the number of UDP packets we need to send
uint16_t channelCount = length * 3; // 1 channel for every R,G,B value
uint16_t packetCount = channelCount / DDP_CHANNELS_PER_PACKET;
if (channelCount % DDP_CHANNELS_PER_PACKET) {
packetCount++;
}
// there are 3 channels per RGB pixel
uint32_t channel = 0; // TODO: allow specifying the start channel
// the current position in the buffer
uint16_t bufferOffset = 0;
for (uint16_t currentPacket = 0; currentPacket < packetCount; currentPacket++) {
if (sequenceNumber > 15) sequenceNumber = 0;
if (!ddpUdp.beginPacket(client, DDP_DEFAULT_PORT)) { // port defined in ESPAsyncE131.h
DEBUG_PRINTLN(F("WiFiUDP.beginPacket returned an error"));
return 1; // problem
}
// the amount of data is AFTER the header in the current packet
uint16_t packetSize = DDP_CHANNELS_PER_PACKET;
uint8_t flags = DDP_FLAGS1_VER1;
if (currentPacket == (packetCount - 1)) {
// last packet, set the push flag
// TODO: determine if we want to send an empty push packet to each destination after sending the pixel data
flags = DDP_FLAGS1_VER1 | DDP_FLAGS1_PUSH;
if (channelCount % DDP_CHANNELS_PER_PACKET) {
packetSize = channelCount % DDP_CHANNELS_PER_PACKET;
}
}
// write the header
/*0*/ddpUdp.write(flags);
/*1*/ddpUdp.write(sequenceNumber++ & 0x0F); // sequence may be unnecessary unless we are sending twice (as requested in Sync settings)
/*2*/ddpUdp.write(0);
/*3*/ddpUdp.write(DDP_ID_DISPLAY);
// data offset in bytes, 32-bit number, MSB first
/*4*/ddpUdp.write(0xFF & (channel >> 24));
/*5*/ddpUdp.write(0xFF & (channel >> 16));
/*6*/ddpUdp.write(0xFF & (channel >> 8));
/*7*/ddpUdp.write(0xFF & (channel ));
// data length in bytes, 16-bit number, MSB first
/*8*/ddpUdp.write(0xFF & (packetSize >> 8));
/*9*/ddpUdp.write(0xFF & (packetSize ));
// write the colors, the write write(const uint8_t *buffer, size_t size)
// function is just a loop internally too
for (uint16_t i = 0; i < packetSize; i += 3) {
ddpUdp.write(buffer[bufferOffset++]); // R
ddpUdp.write(buffer[bufferOffset++]); // G
ddpUdp.write(buffer[bufferOffset++]); // B
if (isRGBW) bufferOffset++;
}
if (!ddpUdp.endPacket()) {
DEBUG_PRINTLN("WiFiUDP.endPacket returned an error");
return 1; // problem
}
channel += packetSize;
}
} break;
case 1: //E1.31
{
} break;
case 2: //ArtNet
{
} break;
}
return 0;
}

View File

@ -707,6 +707,7 @@ void WLED::initInterfaces()
#endif #endif
strip.service(); strip.service();
// Set up mDNS responder: // Set up mDNS responder:
if (strlen(cmDNS) > 0) { if (strlen(cmDNS) > 0) {
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
@ -749,13 +750,15 @@ unsigned long heapTime = 0;
void WLED::handleConnection() void WLED::handleConnection()
{ {
if (millis() < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS)) unsigned long now = millis();
if (now < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS))
return; return;
if (lastReconnectAttempt == 0) if (lastReconnectAttempt == 0)
initConnection(); initConnection();
// reconnect WiFi to clear stale allocations if heap gets too low // reconnect WiFi to clear stale allocations if heap gets too low
if (millis() - heapTime > 5000) { if (now - heapTime > 5000) {
uint32_t heap = ESP.getFreeHeap(); uint32_t heap = ESP.getFreeHeap();
if (heap < JSON_BUFFER_SIZE+512 && lastHeap < JSON_BUFFER_SIZE+512) { if (heap < JSON_BUFFER_SIZE+512 && lastHeap < JSON_BUFFER_SIZE+512) {
DEBUG_PRINT(F("Heap too low! ")); DEBUG_PRINT(F("Heap too low! "));
@ -763,7 +766,7 @@ void WLED::handleConnection()
forceReconnect = true; forceReconnect = true;
} }
lastHeap = heap; lastHeap = heap;
heapTime = millis(); heapTime = now;
} }
byte stac = 0; byte stac = 0;
@ -783,7 +786,7 @@ void WLED::handleConnection()
if (stac) if (stac)
WiFi.disconnect(); // disable search so that AP can work WiFi.disconnect(); // disable search so that AP can work
else else
initConnection(); // restart search initConnection(); // restart search
} }
} }
} }
@ -801,9 +804,9 @@ void WLED::handleConnection()
interfacesInited = false; interfacesInited = false;
initConnection(); initConnection();
} }
if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) if (now - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED)
initConnection(); initConnection();
if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) if (!apActive && now - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN))
initAP(); initAP();
} else if (!interfacesInited) { // newly connected } else if (!interfacesInited) { // newly connected
DEBUG_PRINTLN(""); DEBUG_PRINTLN("");

View File

@ -397,7 +397,7 @@ void getSettingsJS(byte subPage, char* dest)
uint8_t nPins = bus->getPins(pins); uint8_t nPins = bus->getPins(pins);
for (uint8_t i = 0; i < nPins; i++) { for (uint8_t i = 0; i < nPins; i++) {
lp[1] = 48+i; lp[1] = 48+i;
if (pinManager.isPinOk(pins[i])) sappend('v',lp,pins[i]); if (pinManager.isPinOk(pins[i]) || bus->getType()<20) sappend('v',lp,pins[i]);
} }
sappend('v',lc,bus->getLength()); sappend('v',lc,bus->getLength());
sappend('v',lt,bus->getType()); sappend('v',lt,bus->getType());