Merge pull request #2245 from Aircoookie/network-bus

Network bus/virtual WLED instances
This commit is contained in:
Christian Schwinne 2021-10-06 20:05:32 +02:00 committed by GitHub
commit cc87ba4962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1337 additions and 985 deletions

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
//temporary struct for passing bus configuration to bus //temporary struct for passing bus configuration to bus
struct BusConfig { struct BusConfig {
uint8_t type = TYPE_WS2812_RGB; uint8_t type = TYPE_WS2812_RGB;
@ -23,7 +37,8 @@ struct BusConfig {
type = busType; count = len; start = pstart; type = busType; count = len; start = pstart;
colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip;
uint8_t nPins = 1; uint8_t nPins = 1;
if (type > 47) nPins = 2; if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address
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];
} }
@ -135,7 +150,7 @@ class BusDigital : public Bus {
_busPtr = PolyBus::create(_iType, _pins, _len, nr); _busPtr = PolyBus::create(_iType, _pins, _len, nr);
_valid = (_busPtr != nullptr); _valid = (_busPtr != nullptr);
_colorOrder = bc.colorOrder; _colorOrder = bc.colorOrder;
//Serial.printf("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, len, type, pins[0],pins[1],_iType); DEBUG_PRINTF("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, _len, bc.type, _pins[0],_pins[1],_iType);
}; };
inline void show() { inline void show() {
@ -201,7 +216,7 @@ class BusDigital : public Bus {
} }
void cleanup() { void cleanup() {
//Serial.println("Digital Cleanup"); DEBUG_PRINTLN("Digital Cleanup");
PolyBus::cleanup(_busPtr, _iType); PolyBus::cleanup(_busPtr, _iType);
_iType = I_NONE; _iType = I_NONE;
_valid = false; _valid = false;
@ -227,6 +242,7 @@ class BusDigital : public Bus {
class BusPwm : public Bus { class BusPwm : public Bus {
public: public:
BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) { BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) {
_valid = false;
if (!IS_PWM(bc.type)) return; if (!IS_PWM(bc.type)) return;
uint8_t numPins = NUM_PWM_PINS(bc.type); uint8_t numPins = NUM_PWM_PINS(bc.type);
@ -280,10 +296,12 @@ class BusPwm : public Bus {
//does no index check //does no index check
uint32_t getPixelColor(uint16_t pix) { uint32_t getPixelColor(uint16_t pix) {
if (!_valid) return 0;
return ((_data[3] << 24) | (_data[0] << 16) | (_data[1] << 8) | (_data[2])); return ((_data[3] << 24) | (_data[0] << 16) | (_data[1] << 8) | (_data[2]));
} }
void show() { void show() {
if (!_valid) return;
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
for (uint8_t i = 0; i < numPins; i++) { for (uint8_t i = 0; i < numPins; i++) {
uint8_t scaled = (_data[i] * _bri) / 255; uint8_t scaled = (_data[i] * _bri) / 255;
@ -301,6 +319,7 @@ class BusPwm : public Bus {
} }
uint8_t getPins(uint8_t* pinArray) { uint8_t getPins(uint8_t* pinArray) {
if (!_valid) return 0;
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i]; for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i];
return numPins; return numPins;
@ -328,13 +347,13 @@ class BusPwm : public Bus {
void deallocatePins() { void deallocatePins() {
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
for (uint8_t i = 0; i < numPins; i++) { for (uint8_t i = 0; i < numPins; i++) {
pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
if (!pinManager.isPinOk(_pins[i])) continue; if (!pinManager.isPinOk(_pins[i])) continue;
#ifdef ESP8266 #ifdef ESP8266
digitalWrite(_pins[i], LOW); //turn off PWM interrupt digitalWrite(_pins[i], LOW); //turn off PWM interrupt
#else #else
if (_ledcStart < 16) ledcDetachPin(_pins[i]); if (_ledcStart < 16) ledcDetachPin(_pins[i]);
#endif #endif
pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
} }
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
pinManager.deallocateLedc(_ledcStart, numPins); pinManager.deallocateLedc(_ledcStart, numPins);
@ -342,6 +361,116 @@ class BusPwm : public Bus {
} }
}; };
class BusNetwork : public Bus {
public:
BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start) {
_valid = false;
// switch (bc.type) {
// case TYPE_NET_ARTNET_RGB:
// _rgbw = false;
// _UDPtype = 2;
// break;
// case TYPE_NET_E131_RGB:
// _rgbw = false;
// _UDPtype = 1;
// break;
// case TYPE_NET_DDP_RGB:
// _rgbw = false;
// _UDPtype = 0;
// break;
// default:
_rgbw = false;
_UDPtype = bc.type - TYPE_NET_DDP_RGB;
// break;
// }
_UDPchannels = _rgbw ? 4 : 3;
//_rgbw |= bc.rgbwOverride; // RGBW override in bit 7 or can have a special type
_data = (byte *)malloc(bc.count * _UDPchannels);
if (_data == nullptr) return;
memset(_data, 0, bc.count * _UDPchannels);
_len = bc.count;
//_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 * _UDPchannels;
_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 * _UDPchannels;
return (
(_rgbw ? (_data[offset+3] << 24) : 0)
| (_data[offset] << 16)
| (_data[offset+1] << 8)
| (_data[offset+2] )
);
}
void show() {
if (!_valid || !canShow()) return;
_broadcastLock = true;
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
_broadcastLock = false;
}
inline bool canShow() {
// this should be a return value from UDP routine if it is still sending data out
return !_broadcastLock;
}
inline void setBrightness(uint8_t b) {
_bri = 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;
uint8_t _bri = 255;
uint8_t _UDPtype;
uint8_t _UDPchannels;
bool _rgbw;
bool _broadcastLock;
byte *_data;
};
class BusManager { class BusManager {
public: public:
BusManager() { BusManager() {
@ -365,15 +494,16 @@ class BusManager {
return len*6; return len*6;
#endif #endif
} }
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;
} }
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 >= TYPE_NET_DDP_RGB && bc.type < 96) {
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);
@ -402,7 +532,6 @@ class BusManager {
uint16_t bstart = b->getStart(); uint16_t bstart = b->getStart();
if (pix < bstart || pix >= bstart + b->getLength()) continue; if (pix < bstart || pix >= bstart + b->getLength()) continue;
busses[i]->setPixelColor(pix - bstart, c); busses[i]->setPixelColor(pix - bstart, c);
break;
} }
} }
@ -444,6 +573,7 @@ class BusManager {
return len; return len;
} }
// a workaround
static inline bool isRgbw(uint8_t type) { static inline bool isRgbw(uint8_t type) {
return Bus::isRgbw(type); return Bus::isRgbw(type);
} }

View File

@ -263,6 +263,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
JsonObject if_live = interfaces["live"]; JsonObject if_live = interfaces["live"];
CJSON(receiveDirect, if_live["en"]); CJSON(receiveDirect, if_live["en"]);
CJSON(e131Port, if_live["port"]); // 5568 CJSON(e131Port, if_live["port"]); // 5568
if (e131Port == DDP_DEFAULT_PORT) e131Port = E131_DEFAULT_PORT; // prevent double DDP port allocation
CJSON(e131Multicast, if_live[F("mc")]); CJSON(e131Multicast, if_live[F("mc")]);
JsonObject if_live_dmx = if_live[F("dmx")]; JsonObject if_live_dmx = if_live[F("dmx")];

View File

@ -113,13 +113,17 @@
#define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels) #define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels)
#define DMX_MODE_MULTIPLE_RGBW 6 //every LED is addressed with its own RGBW (ledCount * 4 channels) #define DMX_MODE_MULTIPLE_RGBW 6 //every LED is addressed with its own RGBW (ledCount * 4 channels)
//Light capability byte (unused) 0bRRCCTTTT //Light capability byte (unused) 0bRCCCTTTT
//bits 0/1/2/3: specifies a type of LED driver. A single "driver" may have different chip models but must have the same protocol/behavior //bits 0/1/2/3: specifies a type of LED driver. A single "driver" may have different chip models but must have the same protocol/behavior
//bits 4/5: specifies the class of LED driver - 0b00 (dec. 0-15) unconfigured/reserved //bits 4/5/6: specifies the class of LED driver - 0b000 (dec. 0-15) unconfigured/reserved
// - 0b01 (dec. 16-31) digital (data pin only) // - 0b001 (dec. 16-31) digital (data pin only)
// - 0b10 (dec. 32-47) analog (PWM) // - 0b010 (dec. 32-47) analog (PWM)
// - 0b11 (dec. 48-63) digital (data + clock / SPI) // - 0b011 (dec. 48-63) digital (data + clock / SPI)
//bits 6/7 are reserved and set to 0b00 // - 0b100 (dec. 64-79) unused/reserved
// - 0b101 (dec. 80-95) digital (data + clock / SPI)
// - 0b110 (dec. 96-111) unused/reserved
// - 0b111 (dec. 112-127) unused/reserved
//bit 7 is reserved and set to 0
#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
@ -143,6 +147,10 @@
#define TYPE_APA102 51 #define TYPE_APA102 51
#define TYPE_LPD8806 52 #define TYPE_LPD8806 52
#define TYPE_P9813 53 #define TYPE_P9813 53
//Network types (master broadcast) (80-95)
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus)
#define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus)
#define IS_DIGITAL(t) ((t) & 0x10) //digital are 16-31 and 48-63 #define IS_DIGITAL(t) ((t) & 0x10) //digital are 16-31 and 48-63
#define IS_PWM(t) ((t) > 40 && (t) < 46) #define IS_PWM(t) ((t) > 40 && (t) < 46)
@ -242,7 +250,7 @@
#ifndef MAX_LED_MEMORY #ifndef MAX_LED_MEMORY
#ifdef ESP8266 #ifdef ESP8266
#define MAX_LED_MEMORY 5000 #define MAX_LED_MEMORY 4000
#else #else
#define MAX_LED_MEMORY 64000 #define MAX_LED_MEMORY 64000
#endif #endif
@ -283,7 +291,7 @@
// Maximum size of node map (list of other WLED instances) // Maximum size of node map (list of other WLED instances)
#ifdef ESP8266 #ifdef ESP8266
#define WLED_MAX_NODES 15 #define WLED_MAX_NODES 24
#else #else
#define WLED_MAX_NODES 150 #define WLED_MAX_NODES 150
#endif #endif

View File

@ -506,12 +506,12 @@ function populatePresets(fromls)
pJson["0"] = {}; pJson["0"] = {};
localStorage.setItem("wledP", JSON.stringify(pJson)); localStorage.setItem("wledP", JSON.stringify(pJson));
} }
pmtLS = pmt; pmtLS = pmt;
for (var a = 0; a < is.length; a++) { for (var a = 0; a < is.length; a++) {
let i = is[a]; let i = is[a];
if (expanded[i+100]) expand(i+100, true); if (expanded[i+100]) expand(i+100, true);
} }
makePlSel(arr); //makePlSel(arr);
} else { presetError(true); } } else { presetError(true); }
updatePA(); updatePA();
populateQL(); populateQL();
@ -1296,14 +1296,16 @@ var plJson = {"0":{
"end": 0 "end": 0
}}; }};
var plSelContent = ""; //var plSelContent = "";
function makePlSel(arr) { function makePlSel(incPl=false) {
plSelContent = ""; var plSelContent = "";
var arr = Object.entries(pJson);
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var n = arr[i][1].n ? arr[i][1].n : "Preset " + arr[i][0]; var n = arr[i][1].n ? arr[i][1].n : "Preset " + arr[i][0];
if (arr[i][1].playlist && arr[i][1].playlist.ps) continue; //remove playlists, sub-playlists not yet supported if (!incPl && arr[i][1].playlist && arr[i][1].playlist.ps) continue; //remove playlists, sub-playlists not yet supported
plSelContent += `<option value=${arr[i][0]}>${n}</option>` plSelContent += `<option value=${arr[i][0]}>${n}</option>`
} }
return plSelContent;
} }
function refreshPlE(p) { function refreshPlE(p) {
@ -1391,7 +1393,7 @@ function makeP(i,pl) {
End preset:<br> End preset:<br>
<select class="btn sel sel-ple" id="pl${i}selEnd" onchange="plR(${i})" data-val=${plJson[i].end?plJson[i].end:0}> <select class="btn sel sel-ple" id="pl${i}selEnd" onchange="plR(${i})" data-val=${plJson[i].end?plJson[i].end:0}>
<option value=0>None</option> <option value=0>None</option>
${plSelContent} ${makePlSel(true)}
</select> </select>
</div> </div>
<button class="btn btn-i btn-p" onclick="testPl(${i}, this)"><i class='icons btn-icon'>&#xe139;</i>Test</button>`; <button class="btn btn-i btn-p" onclick="testPl(${i}, this)"><i class='icons btn-icon'>&#xe139;</i>Test</button>`;
@ -1449,7 +1451,7 @@ function makePlEntry(p,i) {
return ` return `
<div class="plentry"> <div class="plentry">
<select class="btn sel sel-pl" onchange="plePs(${p},${i},this)" data-val=${plJson[p].ps[i]} data-index=${i}> <select class="btn sel sel-pl" onchange="plePs(${p},${i},this)" data-val=${plJson[p].ps[i]} data-index=${i}>
${plSelContent} ${makePlSel()}
</select> </select>
<button class="btn btn-i btn-xs btn-pl-del" onclick="delPl(${p},${i})"><i class="icons btn-icon">&#xe037;</i></button> <button class="btn btn-i btn-xs btn-pl-del" onclick="delPl(${p},${i})"><i class="icons btn-icon">&#xe037;</i></button>
<div class="h plnl">Duration</div><div class="h plnl">Transition</div><div class="h pli">#${i+1}</div><br> <div class="h plnl">Duration</div><div class="h plnl">Transition</div><div class="h pli">#${i+1}</div><br>

View File

@ -5,10 +5,11 @@
<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=4000,maxPB=4096,maxL=1333,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
function H() var customStarts=false,startsDirty=[];
function H()
{ {
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#led-settings"); window.open("https://kno.wled.ge/features/settings/#led-settings");
} }
function B() function B()
{ {
@ -28,35 +29,49 @@
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,l) {
maxB = b; maxM = m; maxPB = p; maxB = b; maxM = m; maxPB = p; maxL = l;
} }
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);
// ignore IP address
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
var n = LCs[i].name.substring(2);
var t = parseInt(d.getElementsByName("LT"+n)[0].value, 10); // LED type SELECT
if (t>=80) continue;
}
//check for pin conflicts //check for pin conflicts
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" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" && LCs[i].value!="-1") { if (LCs[i].value!="" && LCs[i].value!="-1") {
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 (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;}
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 (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++) for (j=i+1; j<LCs.length; j++)
{ {
var n2 = LCs[j].name.substring(0,2); 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") if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
if (LCs[j].value!="" && LCs[i].value==LCs[j].value) {alert(`Pin conflict between ${nm}/${n2}!`);LCs[j].value="";LCs[j].focus();return false;} if (n2.substring(0,1)==="L") {
var m = LCs[j].name.substring(2);
var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
if (t2<16) continue;
}
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;}
}
} }
} }
} }
return true; return true;
} }
function trySubmit(e) { function trySubmit(e) {
d.Sf.data.value = '';
e.preventDefault(); e.preventDefault();
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server
if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000) msg += "\n\rConsider using an ESP32."; alert(msg);} 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 (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914
} }
function S(){GetV();setABL();} function S(){GetV();checkSi();setABL();}
function enABL() function enABL()
{ {
var en = gId('able').checked; var en = gId('able').checked;
@ -89,21 +104,21 @@
UI(); UI();
} }
//returns mem usage //returns mem usage
function getMem(type, len, p0) { function getMem(t, len, p0) {
if (type < 32) { if (t < 32) {
if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem
if (type > 29) return len*20; //RGBW if (t > 29) return len*20; //RGBW
return len*15; return len*15;
} else if (maxM >= 10000) //ESP32 RMT uses double buffer? } else if (maxM >= 10000) //ESP32 RMT uses double buffer?
{ {
if (type > 29) return len*8; //RGBW if (t > 29) return len*8; //RGBW
return len*6; return len*6;
} }
if (type > 29) return len*4; //RGBW if (t > 29) return len*4; //RGBW
return len*3; return len*3;
} }
if (type > 31 && type < 48) return 5; if (t > 31 && t < 48) return 5;
if (type == 44 || type == 45) return len*4; //RGBW if (t == 44 || t == 45) return len*4; //RGBW
return len*3; return len*3;
} }
function UI(change=false) function UI(change=false)
@ -115,87 +130,124 @@
if (d.Sf.LA.value == 255) laprev = 12; if (d.Sf.LA.value == 255) laprev = 12;
else if (d.Sf.LA.value > 0) laprev = d.Sf.LA.value; else if (d.Sf.LA.value > 0) laprev = d.Sf.LA.value;
// enable/disable LED fields
var s = d.getElementsByTagName("select"); var s = d.getElementsByTagName("select");
for (i=0; i<s.length; i++) { for (i=0; i<s.length; i++) {
// is the field a LED type?
if (s[i].name.substring(0,2)=="LT") { if (s[i].name.substring(0,2)=="LT") {
n=s[i].name.substring(2); var n = s[i].name.substring(2);
var type = parseInt(s[i].value,10); var t = parseInt(s[i].value,10);
gId("p0d"+n).innerHTML = (type > 49) ? "Data:" : (type >41) ? "Pins:" : "Pin:"; gId("p0d"+n).innerHTML = (t>=80 && t<96) ? "IP address:" : (t > 49) ? "Data GPIO:" : (t >41) ? "GPIOs:" : "GPIO:";
gId("p1d"+n).innerHTML = (type > 49) ? "Clk:" : ""; gId("p1d"+n).innerHTML = (t> 49 && t<64) ? "Clk GPIO:" : "";
var LK = d.getElementsByName("L1"+n)[0]; var LK = d.getElementsByName("L1"+n)[0]; // clock pin
memu += getMem(type, d.getElementsByName("LC"+n)[0].value, d.getElementsByName("L0"+n)[0].value); memu += getMem(t, d.getElementsByName("LC"+n)[0].value, d.getElementsByName("L0"+n)[0].value); // calc memory
// enumerate pins
for (p=1; p<5; p++) { for (p=1; p<5; p++) {
var LK = d.getElementsByName("L"+p+n)[0]; var LK = d.getElementsByName("L"+p+n)[0]; // secondary pins
if (!LK) continue; if (!LK) continue;
if ((type>49 && p==1) || (type>41 && type < 50 && (p+40 < type))) // TYPE_xxxx values from const.h if (((t>=80 && t<96) && p<4) || (t>49 && p==1) || (t>41 && t < 50 && (p+40 < t))) // TYPE_xxxx values from const.h
{ {
// display pin field
LK.style.display = "inline"; LK.style.display = "inline";
LK.required = true; LK.required = true;
} else { } else {
// hide pin field
LK.style.display = "none"; LK.style.display = "none";
LK.required = false; LK.required = false;
LK.value=""; LK.value="";
} }
} }
if (type == 30 || type == 31 || (type > 40 && type < 46 && type != 43)) isRGBW = true; if (change) {
gId("dig"+n+"c").style.display = (type > 40 && type < 48) ? "none":"inline"; // hide count for analog if (t > 31 && t < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED
gId("dig"+n+"s").style.display = (type > 40 && type < 48) ? "none":"inline"; // hide skip 1st for virtual & analog }
gId("rev"+n).innerHTML = (type > 40 && type < 48) ? "Inverted":"Reverse (rotated 180°)"; // change reverse text for analog isRGBW |= (t == 30 || t == 31 || (t > 40 && t < 46 && t != 43)); // RGBW checkbox, TYPE_xxxx values from const.h
gId("psd"+n).innerHTML = (type > 31 && type < 48) ? "Index:":"Start:"; gId("co"+n).style.display = ((t>=80 && t<96) || t == 41 || t == 42) ? "none":"inline"; // hide color order for PWM W & WW/CW
gId("dig"+n+"c").style.display = (t > 40 && t < 48) ? "none":"inline"; // hide count for analog
gId("dig"+n+"r").style.display = (t>=80 && t<96) ? "none":"inline"; // hide reversed for virtual
gId("dig"+n+"s").style.display = ((t>=80 && t<96) || (t > 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
gId("rev"+n).innerHTML = (t > 40 && t < 48) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog
gId("psd"+n).innerHTML = (t > 40 && t < 48) ? "Index:":"Start:"; // change analog start description
} }
} }
// display white channel calculation method
var myC = d.querySelectorAll('.wc'), var myC = d.querySelectorAll('.wc'),
l = myC.length; l = myC.length;
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
myC[i].style.display = (isRGBW) ? 'inline':'none'; myC[i].style.display = (isRGBW) ? 'inline':'none';
} }
// check for pin conflicts
if (d.activeElement == d.getElementsByName("LC")[0]) {
var o = d.getElementsByClassName("iST");
var i = o.length;
if (i == 1) d.getElementsByName("LC0")[0].value = d.getElementsByName("LC")[0].value;
}
var LCs = d.getElementsByTagName("input"); var LCs = d.getElementsByTagName("input");
var sLC = 0, maxLC = 0; var sLC = 0, sPC = 0, maxLC = 0;
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); // field name
if (nm=="LC" && LCs[i].name !== "LC") { var n = LCs[i].name.substring(2); // bus number
var n=LCs[i].name.substring(2); // do we have a led count field
if (nm=="LC") {
var c=parseInt(LCs[i].value,10); var c=parseInt(LCs[i].value,10);
if(gId("ls"+n).readOnly) gId("ls"+n).value=sLC; if (!customStarts || !startsDirty[n]) gId("ls"+n).value=sLC;
if(c){sLC+=c;if(c>maxLC)maxLC=c;} gId("ls"+n).disabled = !customStarts;
if(c){
var s = parseInt(gId("ls"+n).value);
if (s+c > sLC) sLC = s+c;
if(c>maxLC)maxLC=c;
var t = parseInt(d.getElementsByName("LT"+n)[0].value); // LED type SELECT
if (t<80) sPC+=c; //virtual out busses do not count towards physical LEDs
} // increase led count
continue; continue;
} }
// do we have led pins for digital leds
if (nm=="L0" || nm=="L1") { if (nm=="L0" || nm=="L1") {
var lc=d.getElementsByName("LC"+LCs[i].name.substring(2))[0]; var lc=d.getElementsByName("LC"+n)[0];
lc.max=maxPB; lc.max=maxPB; // update max led count value
} }
// ignore IP address (stored in pins for virtual busses)
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3") {
var t = parseInt(d.getElementsByName("LT"+n)[0].value); // LED type SELECT
if (t>=80) {
LCs[i].max = 255;
LCs[i].min = 0;
continue; // do not check conflicts
} else {
LCs[i].max = 33;
LCs[i].min = -1;
}
}
// check for pin conflicts
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" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" && LCs[i].value!="-1") { if (LCs[i].value!="" && LCs[i].value!="-1") {
var p = []; var p = []; // used pin array
if (d.um_p && Array.isArray(d.um_p)) for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); 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
for (j=0; j<LCs.length; j++) { for (j=0; j<LCs.length; j++) {
if (i==j) continue; if (i==j) continue;
var n2 = LCs[j].name.substring(0,2); 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") if (n2=="L0" || n2=="L1" || n2=="L2" || n2=="L3" || n2=="L4" || n2=="RL" || n2=="BT" || n2=="IR") {
if (LCs[j].value!="" && LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); if (n2.substring(0,1)==="L") {
var m = LCs[j].name.substring(2);
var t2 = parseInt(d.getElementsByName("LT"+m)[0].value, 10);
if (t2>=80) continue;
}
if (LCs[j].value!="" && LCs[j].value!="-1") p.push(parseInt(LCs[j].value,10)); // add current pin
}
} }
if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color="#fff"; // now check for conflicts
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";
} }
} }
// update total led count
gId("lc").textContent = sLC;
gId("pc").textContent = (sLC == sPC) ? "":"(" + sPC + " physical)";
// memory usage and warnings
gId('m0').innerHTML = memu; gId('m0').innerHTML = memu;
bquot = memu / maxM * 100; bquot = memu / maxM * 100;
gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%%, #444 ${bquot}%% 100%%)`; 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.display = (sLC > maxPB || maxLC > 800 || bquot > 80) ? 'inline':'none';
gId('ledwarning').style.color = (sLC > maxPB || maxLC > maxPB || bquot > 100) ? 'red':'orange'; 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 pin"; gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (<b>ERROR: Using over ${maxM}B!</b>)` : "") : "800 LEDs per output";
// calculate power
var val = Math.ceil((100 + sLC * laprev)/500)/2; var val = Math.ceil((100 + sPC * laprev)/500)/2;
val = (val > 5) ? Math.ceil(val) : val; val = (val > 5) ? Math.ceil(val) : val;
var s = ""; var s = "";
var is12V = (d.Sf.LAsel.value == 30); var is12V = (d.Sf.LAsel.value == 30);
@ -209,7 +261,7 @@
s += val; s += val;
s += "A supply connected to LEDs"; s += "A supply connected to LEDs";
} }
var val2 = Math.ceil((100 + sLC * laprev)/1500)/2; var val2 = Math.ceil((100 + sPC * laprev)/1500)/2;
val2 = (val2 > 5) ? Math.ceil(val2) : val2; val2 = (val2 > 5) ? Math.ceil(val2) : val2;
var s2 = "(for most effects, ~"; var s2 = "(for most effects, ~";
s2 += val2; s2 += val2;
@ -221,15 +273,13 @@
function lastEnd(i) { function lastEnd(i) {
if (i<1) return 0; if (i<1) return 0;
v = parseInt(d.getElementsByName("LS"+(i-1))[0].value) + parseInt(d.getElementsByName("LC"+(i-1))[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); var t = parseInt(d.getElementsByName("LT"+(i-1))[0].value);
if (type > 31 && type < 48) v = 1; //PWM busses if (t > 31 && t < 48) v = 1; //PWM busses
if (isNaN(v)) return 0; if (isNaN(v)) return 0;
return v; return v;
} }
function addLEDs(n) function addLEDs(n,init=true)
{ {
if (n>1) {maxB=n; gId("+").style.display="inline"; return;}
var o = d.getElementsByClassName("iST"); var o = d.getElementsByClassName("iST");
var i = o.length; var i = o.length;
@ -239,10 +289,10 @@
if (n==1) { if (n==1) {
// npm run build has trouble minimizing spaces inside string // npm run build has trouble minimizing spaces inside string
var cn = `<div class="iST"> var cn = `<div class="iST">
${i>0?'<hr style="width:260px">':''} <hr style="width:260px">
${i+1}: ${i+1}:
<select name="LT${i}" onchange="UI()"> <select name="LT${i}" onchange="UI(true)">
<option value="22">WS281x</option> <option value="22" selected>WS281x</option>
<option value="30">SK6812 RGBW</option> <option value="30">SK6812 RGBW</option>
<option value="31">TM1814</option> <option value="31">TM1814</option>
<option value="24">400kHz</option> <option value="24">400kHz</option>
@ -255,8 +305,11 @@ ${i+1}:
<option value="43">PWM RGB</option> <option value="43">PWM RGB</option>
<option value="44">PWM RGBW</option> <option value="44">PWM RGBW</option>
<option value="45">PWM RGBWC</option> <option value="45">PWM RGBWC</option>
<option value="80">DDP RGB (network)</option>
<!--option value="81">E1.31 RGB (network)</option-->
<!--option value="82">ArtNet RGB (network)</option-->
</select>&nbsp; </select>&nbsp;
Color Order: <div id="co${i}" style="display:inline">Color Order:
<select name="CO${i}"> <select name="CO${i}">
<option value="0">GRB</option> <option value="0">GRB</option>
<option value="1">RGB</option> <option value="1">RGB</option>
@ -264,17 +317,18 @@ Color Order:
<option value="3">RBG</option> <option value="3">RBG</option>
<option value="4">BGR</option> <option value="4">BGR</option>
<option value="5">GBR</option> <option value="5">GBR</option>
</select><br> </select></div>
<span id="p0d${i}">Pin:</span> <input type="number" class="xs" name="L0${i}" min="0" max="33" required onchange="UI()"/>
<span id="p1d${i}">Clock:</span> <input type="number" class="xs" name="L1${i}" min="0" max="33" onchange="UI()"/>
<span id="p2d${i}"></span><input type="number" class="xs" name="L2${i}" min="0" max="33" onchange="UI()"/>
<span id="p3d${i}"></span><input type="number" class="xs" name="L3${i}" min="0" max="33" onchange="UI()"/>
<span id="p4d${i}"></span><input type="number" class="xs" name="L4${i}" min="0" max="33" onchange="UI()"/>
<br> <br>
<span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" min="0" max="8191" value="${lastEnd(i)}" required />&nbsp; <span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" class="l starts" min="0" max="8191" value="${lastEnd(i)}" oninput="startsDirty[${i}]=true;UI();" required />&nbsp;
<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> <div id="dig${i}c" style="display:inline">Length: <input type="number" name="LC${i}" class="l" min="1" max="${maxPB}" value="1" required oninput="UI()" /></div>
<br> <br>
<div id="dig${i}r" style="display:inline"><span id="rev${i}">Reverse</span>: <input type="checkbox" name="CV${i}"></div>&nbsp; <span id="p0d${i}">GPIO:</span> <input type="number" name="L0${i}" min="0" max="33" required class="xs" onchange="UI()"/>
<span id="p1d${i}"></span><input type="number" name="L1${i}" min="0" max="33" class="xs" onchange="UI()"/>
<span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="33" class="xs" onchange="UI()"/>
<span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="33" class="xs" onchange="UI()"/>
<span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="33" class="xs" onchange="UI()"/>
<br>
<div id="dig${i}r" style="display:inline"><span id="rev${i}">Reversed</span>: <input type="checkbox" name="CV${i}">&nbsp;</div>
<div id="dig${i}s" style="display:inline">Skip 1<sup>st</sup> LED: <input id="sl${i}" type="checkbox" name="SL${i}"></div> <div id="dig${i}s" style="display:inline">Skip 1<sup>st</sup> LED: <input id="sl${i}" type="checkbox" name="SL${i}"></div>
</div>`; </div>`;
f.insertAdjacentHTML("beforeend", cn); f.insertAdjacentHTML("beforeend", cn);
@ -286,14 +340,14 @@ Color Order:
gId("+").style.display = (i<maxB-1) ? "inline":"none"; gId("+").style.display = (i<maxB-1) ? "inline":"none";
gId("-").style.display = (i>0) ? "inline":"none"; gId("-").style.display = (i>0) ? "inline":"none";
UI(); if (!init) UI();
} }
function addBtn(i,p,t) { function addBtn(i,p,t) {
var c = gId("btns").innerHTML; var c = gId("btns").innerHTML;
var bt = "BT" + i; var bt = "BT" + i;
var be = "BE" + i; var be = "BE" + i;
c += `Button ${i} pin: <input type="number" class="xs" min="-1" max="40" name="${bt}" onchange="UI()" value="${p}">&nbsp;`; c += `Button ${i} GPIO: <input type="number" min="-1" max="40" name="${bt}" onchange="UI()" class="xs" value="${p}">`;
c += `<select name="${be}">` c += `&nbsp;<select name="${be}">`
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`; c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`; c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`; c += `<option value="3" ${t==3?"selected":""}>Push inverted</option>`;
@ -306,6 +360,21 @@ Color Order:
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`; c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
gId("btns").innerHTML = c; gId("btns").innerHTML = c;
} }
function tglSi(cs) {
customStarts = cs;
if (!customStarts) startsDirty = []; //set all starts to clean
UI();
}
function checkSi() { //on load, checks whether there are custom start fields
var cs = false;
for (var i=1; i < d.getElementsByClassName("iST").length; i++) {
var v = parseInt(gId("ls"+(i-1)).value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value);
if (v != parseInt(gId("ls"+i).value)) {cs = true; startsDirty[i] = true;}
}
if (parseInt(gId("ls0").value) != 0) {cs = true; startsDirty[0] = true;}
gId("si").checked = cs;
tglSi(cs);
}
function uploadFile(name) { function uploadFile(name) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.addEventListener('load', function(){showToast(this.responseText,this.status >= 400)}); req.addEventListener('load', function(){showToast(this.responseText,this.status >= 400)});
@ -320,7 +389,7 @@ Color Order:
function GetV() function GetV()
{ {
//values injected by server while sending HTML //values injected by server while sending HTML
//maxM=5000;maxPB=1536;d.um_p=[1,6,7,8,9,10,11];addLEDs(3);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; //d.um_p=[6,7,8,9,10,11,1];bLimits(3,4096,4000,1664);d.Sf.MS.checked=1;addLEDs(1);d.Sf.L00.value=2;d.Sf.LC0.value=30;d.Sf.LT0.value=22;d.Sf.CO0.value=0;d.Sf.LS0.value=15;d.Sf.CV0.checked=1;d.Sf.SL0.checked=0;addLEDs(1);d.Sf.L01.value=10;d.Sf.L11.value=10;d.Sf.L21.value=1;d.Sf.L31.value=10;d.Sf.LC1.value=60;d.Sf.LT1.value=80;d.Sf.CO1.value=1;d.Sf.LS1.value=0;d.Sf.CV1.checked=0;d.Sf.SL1.checked=0;d.Sf.MA.value=850;d.Sf.LA.value=0;d.Sf.CA.value=56;d.Sf.AW.value=3;d.Sf.BO.checked=1;d.Sf.BP.value=80;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=100;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=0;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=12;d.Sf.RM.checked=1;addBtn(0,0,0);addBtn(1,-1,0);d.Sf.TT.value=32;d.Sf.IR.value=-1;d.Sf.IT.value=0;
} }
</script> </script>
<style> <style>
@ -332,7 +401,7 @@ Color Order:
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
<h2>LED &amp; Hardware setup</h2> <h2>LED &amp; Hardware setup</h2>
Total LED count: <input name="LC" id="LC" type="number" min="1" max="8192" oninput="UI()" required><br> Total LEDs: <span id="lc">?</span> <span id="pc"></span><br>
<i>Recommended power supply for brightest white:</i><br> <i>Recommended power supply for brightest white:</i><br>
<b><span id="psu">?</span></b><br> <b><span id="psu">?</span></b><br>
<span id="psu2"><br></span> <span id="psu2"><br></span>
@ -363,19 +432,22 @@ Color Order:
</div> </div>
<h3>Hardware setup</h3> <h3>Hardware setup</h3>
<div id="mLC">LED outputs:</div> <div id="mLC">LED outputs:</div>
<button type="button" id="+" onclick="addLEDs(1)" style="display:none;border-radius:20px;height:36px;">+</button> <hr style="width:260px">
<button type="button" id="-" onclick="addLEDs(-1)" style="display:none;border-radius:20px;width:36px;height:36px;">-</button><br> <button type="button" id="+" onclick="addLEDs(1,false)" style="display:none;border-radius:20px;height:36px;">+</button>
<button type="button" id="-" onclick="addLEDs(-1,false)" style="display:none;border-radius:20px;width:36px;height:36px;">-</button><br>
LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br> LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br>
<div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br> <div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br>
<div id="ledwarning" style="color: orange; display: none;"> <div id="ledwarning" style="color: orange; display: none;">
&#9888; You might run into stability or lag issues.<br> &#9888; You might run into stability or lag issues.<br>
Use less than <span id="wreason">800 LEDs per pin</span> for the best experience!<br> Use less than <span id="wreason">800 LEDs per output</span> for the best experience!<br>
</div> </div>
<hr style="width:260px">
Make a segment for each output: <input type="checkbox" name="MS"> <br> Make a segment for each output: <input type="checkbox" name="MS"> <br>
Custom bus start indices: <input type="checkbox" onchange="tglSi(this.checked)" id="si"> <br>
<hr style="width:260px"> <hr style="width:260px">
<div id="btns"></div> <div id="btns"></div>
Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br> Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br>
IR pin: <input type="number" class="xs" min="-1" max="40" name="IR" onchange="UI()">&nbsp;<select name="IT" onchange="UI()"> IR GPIO: <input type="number" min="-1" max="40" name="IR" onchange="UI()" class="xs"><select name="IT" onchange="UI()">
<option value=0>Remote disabled</option> <option value=0>Remote disabled</option>
<option value=1>24-key RGB</option> <option value=1>24-key RGB</option>
<option value=2>24-key with CT</option> <option value=2>24-key with CT</option>
@ -388,8 +460,8 @@ Color Order:
</select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br> </select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br>
<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> <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>
<div id="toast"></div> <div id="toast"></div>
<a href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">IR info</a><br> <a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br>
Relay pin: <input type="number" class="xs" min="-1" max="33" name="RL" onchange="UI()"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br> Relay GPIO: <input type="number" min="-1" max="33" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br>
<hr style="width:260px"> <hr style="width:260px">
<h3>Defaults</h3> <h3>Defaults</h3>
Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br> Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br>

View File

@ -99,7 +99,6 @@ Type:
<select name=DI onchange="SP(); adj();"> <select name=DI onchange="SP(); adj();">
<option value=5568>E1.31 (sACN)</option> <option value=5568>E1.31 (sACN)</option>
<option value=6454>Art-Net</option> <option value=6454>Art-Net</option>
<option value=4048>DDP</option>
<option value=0 selected>Custom port</option> <option value=0 selected>Custom port</option>
</select><br> </select><br>
<div id=xp>Port: <input name="EP" type="number" min="1" max="65535" value="5568" class="d5" required><br></div> <div id=xp>Port: <input name="EP" type="number" min="1" max="65535" value="5568" class="d5" required><br></div>

View File

@ -35,6 +35,9 @@ input {
font-family: Verdana, sans-serif; font-family: Verdana, sans-serif;
border: 0.5ch solid #333; border: 0.5ch solid #333;
} }
input:disabled {
color: #888;
}
input[type="number"] { input[type="number"] {
width: 4em; width: 4em;
margin: 2px; margin: 2px;

View File

@ -195,6 +195,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, uint8_t bri=255, 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);
@ -224,14 +225,11 @@ class UsermodManager {
public: public:
void loop(); void loop();
void setup(); void setup();
void connected(); void connected();
void addToJsonState(JsonObject& obj); void addToJsonState(JsonObject& obj);
void addToJsonInfo(JsonObject& obj); void addToJsonInfo(JsonObject& obj);
void readFromJsonState(JsonObject& obj); void readFromJsonState(JsonObject& obj);
void addToConfig(JsonObject& obj); void addToConfig(JsonObject& obj);
bool readFromConfig(JsonObject& obj); bool readFromConfig(JsonObject& obj);
void onMqttConnect(bool sessionPresent); void onMqttConnect(bool sessionPresent);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -411,7 +411,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
if (!forPreset) { if (!forPreset) {
if (errorFlag) root[F("error")] = errorFlag; if (errorFlag) root[F("error")] = errorFlag;
root[F("ps")] = currentPreset; root[F("ps")] = (currentPreset > 0) ? currentPreset : -1;
root[F("pl")] = currentPlaylist; root[F("pl")] = currentPlaylist;
usermods.addToJsonState(root); usermods.addToJsonState(root);

View File

@ -111,7 +111,7 @@ void colorUpdated(int callMode)
{ {
effectChanged = false; effectChanged = false;
if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0; if (realtimeTimeout == UINT32_MAX) realtimeTimeout = 0;
currentPreset = -1; //something changed, so we are no longer in the preset currentPreset = 0; //something changed, so we are no longer in the preset
notify(callMode); notify(callMode);

View File

@ -128,12 +128,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (busConfigs[s] != nullptr) delete busConfigs[s]; if (busConfigs[s] != nullptr) delete busConfigs[s];
busConfigs[s] = new BusConfig(type, pins, start, length, colorOrder, request->hasArg(cv), skip); busConfigs[s] = new BusConfig(type, pins, start, length, colorOrder, request->hasArg(cv), skip);
if (!doInitBusses) ledCount = 1;
doInitBusses = true; doInitBusses = true;
uint16_t totalNew = start + length;
if (totalNew > ledCount && totalNew <= MAX_LEDS) ledCount = totalNew; //total is end of last bus (where start + len is max.)
} }
t = request->arg(F("LC")).toInt();
if (t > 0 && t <= MAX_LEDS) ledCount = t;
// upate other pins // upate other pins
int hw_ir_pin = request->arg(F("IR")).toInt(); int hw_ir_pin = request->arg(F("IR")).toInt();
if (pinManager.allocatePin(hw_ir_pin,false, PinOwner::IR)) { if (pinManager.allocatePin(hw_ir_pin,false, PinOwner::IR)) {

View File

@ -89,7 +89,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){
@ -101,6 +100,10 @@ void realtimeLock(uint32_t timeoutMs, byte md)
realtimeTimeout = millis() + timeoutMs; realtimeTimeout = millis() + timeoutMs;
if (timeoutMs == 255001 || timeoutMs == 65000) realtimeTimeout = UINT32_MAX; if (timeoutMs == 255001 || timeoutMs == 65000) realtimeTimeout = UINT32_MAX;
// if strip is off (bri==0) and not already in RTM
if (bri == 0 && !realtimeMode) {
strip.setBrightness(scaledBri(briLast));
}
realtimeMode = md; realtimeMode = md;
if (arlsForceMaxBri && !realtimeOverride) strip.setBrightness(scaledBri(255)); if (arlsForceMaxBri && !realtimeOverride) strip.setBrightness(scaledBri(255));
@ -514,3 +517,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 (0=DDP, 1=E1.31, 2=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, uint8_t bri, 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(scale8(buffer[bufferOffset++], bri)); // R
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B
if (isRGBW) bufferOffset++;
}
if (!ddpUdp.endPacket()) {
DEBUG_PRINTLN(F("WiFiUDP.endPacket returned an error"));
return 1; // problem
}
channel += packetSize;
}
} break;
case 1: //E1.31
{
} break;
case 2: //ArtNet
{
} break;
}
return 0;
}

View File

@ -120,6 +120,10 @@ void WiFiEvent(WiFiEvent_t event)
void WLED::loop() void WLED::loop()
{ {
#ifdef WLED_DEBUG
static unsigned long maxUsermodMillis = 0;
#endif
handleTime(); handleTime();
handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
handleConnection(); handleConnection();
@ -130,7 +134,15 @@ void WLED::loop()
handleDMX(); handleDMX();
#endif #endif
userLoop(); userLoop();
#ifdef WLED_DEBUG
unsigned long usermodMillis = millis();
#endif
usermods.loop(); usermods.loop();
#ifdef WLED_DEBUG
usermodMillis = millis() - usermodMillis;
if (usermodMillis > maxUsermodMillis) maxUsermodMillis = usermodMillis;
#endif
yield(); yield();
handleIO(); handleIO();
@ -159,7 +171,9 @@ void WLED::loop()
yield(); yield();
handleHue(); handleHue();
#ifndef WLED_DISABLE_BLYNK
handleBlynk(); handleBlynk();
#endif
yield(); yield();
@ -222,9 +236,9 @@ void WLED::loop()
handleWs(); handleWs();
handleStatusLED(); handleStatusLED();
// DEBUG serial logging // DEBUG serial logging (every 30s)
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
if (millis() - debugTime > 9999) { if (millis() - debugTime > 29999) {
DEBUG_PRINTLN(F("---DEBUG INFO---")); DEBUG_PRINTLN(F("---DEBUG INFO---"));
DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis()); DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis());
DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime()); DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime());
@ -236,17 +250,19 @@ void WLED::loop()
} else } else
DEBUG_PRINTLN(F("No PSRAM")); DEBUG_PRINTLN(F("No PSRAM"));
#endif #endif
DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status()); DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status());
if (WiFi.status() != lastWifiState) { if (WiFi.status() != lastWifiState) {
wifiStateChangedTime = millis(); wifiStateChangedTime = millis();
} }
lastWifiState = WiFi.status(); lastWifiState = WiFi.status();
DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime); DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime);
DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime); DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime);
DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP()); DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP());
DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 10); DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30);
DEBUG_PRINT(F("Max UM time[ms]: ")); DEBUG_PRINTLN(maxUsermodMillis);
loops = 0; loops = 0;
maxUsermodMillis = 0;
debugTime = millis(); debugTime = millis();
} }
loops++; loops++;
@ -277,7 +293,6 @@ void WLED::setup()
#endif #endif
DEBUG_PRINT(F("heap ")); DEBUG_PRINT(F("heap "));
DEBUG_PRINTLN(ESP.getFreeHeap()); DEBUG_PRINTLN(ESP.getFreeHeap());
registerUsermods();
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
if (psramFound()) { if (psramFound()) {
@ -297,6 +312,9 @@ void WLED::setup()
pinManager.allocatePin(2, true, PinOwner::DMX); pinManager.allocatePin(2, true, PinOwner::DMX);
#endif #endif
DEBUG_PRINTLN(F("Registering usermods ..."));
registerUsermods();
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) btnPin[i] = -1; for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) btnPin[i] = -1;
bool fsinit = false; bool fsinit = false;
@ -329,6 +347,7 @@ void WLED::setup()
DEBUG_PRINTLN(F("Usermods setup")); DEBUG_PRINTLN(F("Usermods setup"));
userSetup(); userSetup();
usermods.setup(); usermods.setup();
if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0) if (strcmp(clientSSID, DEFAULT_CLIENT_SSID) == 0)
showWelcomePage = true; showWelcomePage = true;
WiFi.persistent(false); WiFi.persistent(false);
@ -396,14 +415,15 @@ void WLED::beginStrip()
strip.setBrightness(0); strip.setBrightness(0);
strip.setShowCallback(handleOverlayDraw); strip.setShowCallback(handleOverlayDraw);
if (bootPreset > 0) { if (turnOnAtBoot) {
applyPreset(bootPreset, CALL_MODE_INIT);
} else if (turnOnAtBoot) {
if (briS > 0) bri = briS; if (briS > 0) bri = briS;
else if (bri == 0) bri = 128; else if (bri == 0) bri = 128;
} else { } else {
briLast = briS; bri = 0; briLast = briS; bri = 0;
} }
if (bootPreset > 0) {
applyPreset(bootPreset, CALL_MODE_INIT);
}
colorUpdated(CALL_MODE_INIT); colorUpdated(CALL_MODE_INIT);
// init relay pin // init relay pin
@ -439,6 +459,7 @@ void WLED::initAP(bool resetAP)
udp2Connected = notifier2Udp.begin(udpPort2); udp2Connected = notifier2Udp.begin(udpPort2);
} }
e131.begin(false, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT); e131.begin(false, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT);
ddp.begin(false, DDP_DEFAULT_PORT);
dnsServer.setErrorReplyCode(DNSReplyCode::NoError); dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(53, "*", WiFi.softAPIP()); dnsServer.start(53, "*", WiFi.softAPIP());
@ -591,10 +612,10 @@ void WLED::initConnection()
void WLED::initInterfaces() void WLED::initInterfaces()
{ {
IPAddress ipAddress = Network.localIP();
DEBUG_PRINTLN(F("Init STA interfaces")); DEBUG_PRINTLN(F("Init STA interfaces"));
#ifndef WLED_DISABLE_HUESYNC #ifndef WLED_DISABLE_HUESYNC
IPAddress ipAddress = Network.localIP();
if (hueIP[0] == 0) { if (hueIP[0] == 0) {
hueIP[0] = ipAddress[0]; hueIP[0] = ipAddress[0];
hueIP[1] = ipAddress[1]; hueIP[1] = ipAddress[1];
@ -612,14 +633,13 @@ 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 // "end" must be called before "begin" is called a 2nd time
if (!aOtaEnabled) //ArduinoOTA begins mDNS for us if enabled // see https://github.com/esp8266/Arduino/issues/7213
MDNS.begin(cmDNS); MDNS.end();
#else
MDNS.begin(cmDNS); MDNS.begin(cmDNS);
#endif
DEBUG_PRINTLN(F("mDNS started")); DEBUG_PRINTLN(F("mDNS started"));
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
@ -642,25 +662,27 @@ void WLED::initInterfaces()
initBlynk(blynkApiKey, blynkHost, blynkPort); initBlynk(blynkApiKey, blynkHost, blynkPort);
#endif #endif
e131.begin(e131Multicast, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT); e131.begin(e131Multicast, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT);
ddp.begin(false, DDP_DEFAULT_PORT);
reconnectHue(); reconnectHue();
initMqtt(); initMqtt();
interfacesInited = true; interfacesInited = true;
wasConnected = true; wasConnected = true;
} }
byte stacO = 0;
uint32_t lastHeap;
unsigned long heapTime = 0;
void WLED::handleConnection() void WLED::handleConnection()
{ {
if (millis() < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS)) static byte stacO = 0;
static uint32_t lastHeap = UINT32_MAX;
static unsigned long heapTime = 0;
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! "));
@ -668,7 +690,7 @@ void WLED::handleConnection()
forceReconnect = true; forceReconnect = true;
} }
lastHeap = heap; lastHeap = heap;
heapTime = millis(); heapTime = now;
} }
byte stac = 0; byte stac = 0;
@ -688,7 +710,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
} }
} }
} }
@ -706,9 +728,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

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2109220 #define VERSION 2110021
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG
@ -33,7 +33,9 @@
#endif #endif
#define WLED_ENABLE_ADALIGHT // saves 500b only #define WLED_ENABLE_ADALIGHT // saves 500b only
//#define WLED_ENABLE_DMX // uses 3.5kb (use LEDPIN other than 2) //#define WLED_ENABLE_DMX // uses 3.5kb (use LEDPIN other than 2)
#define WLED_ENABLE_LOXONE // uses 1.2kb #ifndef WLED_DISABLE_LOXONE
#define WLED_ENABLE_LOXONE // uses 1.2kb
#endif
#ifndef WLED_DISABLE_WEBSOCKETS #ifndef WLED_DISABLE_WEBSOCKETS
#define WLED_ENABLE_WEBSOCKETS #define WLED_ENABLE_WEBSOCKETS
#endif #endif
@ -85,6 +87,7 @@
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <DNSServer.h> #include <DNSServer.h>
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
#define NO_OTA_PORT
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#endif #endif
#include <SPIFFSEditor.h> #include <SPIFFSEditor.h>
@ -224,11 +227,7 @@ WLED_GLOBAL bool rlyMde _INIT(true);
WLED_GLOBAL bool rlyMde _INIT(RLYMDE); WLED_GLOBAL bool rlyMde _INIT(RLYMDE);
#endif #endif
#ifndef IRPIN #ifndef IRPIN
#ifdef WLED_DISABLE_INFRARED WLED_GLOBAL int8_t irPin _INIT(-1);
WLED_GLOBAL int8_t irPin _INIT(-1);
#else
WLED_GLOBAL int8_t irPin _INIT(4);
#endif
#else #else
WLED_GLOBAL int8_t irPin _INIT(IRPIN); WLED_GLOBAL int8_t irPin _INIT(IRPIN);
#endif #endif
@ -565,7 +564,7 @@ WLED_GLOBAL JsonDocument* fileDoc;
WLED_GLOBAL bool doCloseFile _INIT(false); WLED_GLOBAL bool doCloseFile _INIT(false);
// presets // presets
WLED_GLOBAL int16_t currentPreset _INIT(-1); WLED_GLOBAL byte currentPreset _INIT(0);
WLED_GLOBAL byte errorFlag _INIT(0); WLED_GLOBAL byte errorFlag _INIT(0);
@ -587,6 +586,7 @@ WLED_GLOBAL AsyncMqttClient* mqtt _INIT(NULL);
WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp, notifier2Udp; WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp, notifier2Udp;
WLED_GLOBAL WiFiUDP ntpUdp; WLED_GLOBAL WiFiUDP ntpUdp;
WLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet))); WLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet)));
WLED_GLOBAL ESPAsyncE131 ddp _INIT_N(((handleE131Packet)));
WLED_GLOBAL bool e131NewData _INIT(false); WLED_GLOBAL bool e131NewData _INIT(false);
// led fx library object // led fx library object
@ -598,7 +598,6 @@ WLED_GLOBAL bool doInitBusses _INIT(false);
// Usermod manager // Usermod manager
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager()); WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
// enable additional debug output // enable additional debug output
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
#ifndef ESP8266 #ifndef ESP8266
@ -628,7 +627,7 @@ WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
WLED_GLOBAL unsigned long debugTime _INIT(0); WLED_GLOBAL unsigned long debugTime _INIT(0);
WLED_GLOBAL int lastWifiState _INIT(3); WLED_GLOBAL int lastWifiState _INIT(3);
WLED_GLOBAL unsigned long wifiStateChangedTime _INIT(0); WLED_GLOBAL unsigned long wifiStateChangedTime _INIT(0);
WLED_GLOBAL int loops _INIT(0); WLED_GLOBAL unsigned long loops _INIT(0);
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32

View File

@ -60,9 +60,9 @@ void XML_response(AsyncWebServerRequest *request, char* dest)
oappend(SET_F("</wv><ws>")); oappend(SET_F("</wv><ws>"));
oappendi(colSec[3]); oappendi(colSec[3]);
oappend(SET_F("</ws><ps>")); oappend(SET_F("</ws><ps>"));
oappendi((currentPreset < 1) ? 0:currentPreset); oappendi(currentPreset);
oappend(SET_F("</ps><cy>")); oappend(SET_F("</ps><cy>"));
oappendi(currentPlaylist > 0); oappendi(currentPlaylist >= 0);
oappend(SET_F("</cy><ds>")); oappend(SET_F("</cy><ds>"));
oappend(serverDescription); oappend(serverDescription);
if (realtimeMode) if (realtimeMode)
@ -198,7 +198,7 @@ void extractPin(JsonObject &obj, const char *key) {
} }
} }
// oappens used pins by scanning JsonObject (1 level deep) // oappend used pins by scanning JsonObject (1 level deep)
void fillUMPins(JsonObject &mods) void fillUMPins(JsonObject &mods)
{ {
for (JsonPair kv : mods) { for (JsonPair kv : mods) {
@ -365,14 +365,10 @@ void getSettingsJS(byte subPage, char* dest)
oappend(SET_F("bLimits(")); oappend(SET_F("bLimits("));
oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(","); oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(",");
oappend(itoa(MAX_LEDS_PER_BUS,nS,10)); oappend(","); oappend(itoa(MAX_LEDS_PER_BUS,nS,10)); oappend(",");
oappend(itoa(MAX_LED_MEMORY,nS,10)); oappend(itoa(MAX_LED_MEMORY,nS,10)); oappend(",");
oappend(itoa(MAX_LEDS,nS,10));
oappend(SET_F(");")); oappend(SET_F(");"));
oappend(SET_F("d.Sf.LC.max=")); //TODO Formula for max LEDs on ESP8266 depending on types. 500 DMA or 1500 UART (about 4kB mem usage)
oappendi(MAX_LEDS);
oappend(";");
sappend('v',SET_F("LC"),ledCount);
sappend('c',SET_F("MS"),autoSegments); sappend('c',SET_F("MS"),autoSegments);
for (uint8_t s=0; s < busses.getNumBusses(); s++) { for (uint8_t s=0; s < busses.getNumBusses(); s++) {
@ -389,7 +385,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()>=TYPE_NET_DDP_RGB) 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());