Per strip "skip first led".

Removed RGBW override from UI.
Saving presets uses rev:1 API if possible.
This commit is contained in:
Blaz Kristan 2021-04-07 21:04:54 +02:00
parent c901512db0
commit 6eafab8286
8 changed files with 61 additions and 33 deletions

View File

@ -26,7 +26,7 @@ struct BusConfig {
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255}; uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0) { BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0) {
rgbwOverride = (bool) GET_BIT(busType,7); rgbwOverride = (bool) GET_BIT(busType,7);
type = busType & 0x7F; // bit 7 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 > 47) nPins = 2;
@ -93,6 +93,12 @@ class Bus {
return _valid; return _valid;
} }
static bool isRgbw(uint8_t type) {
if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true;
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true;
return false;
}
bool reversed = false; bool reversed = false;
protected: protected:
@ -119,7 +125,7 @@ class BusDigital : public Bus {
reversed = bc.reversed; reversed = bc.reversed;
_skip = bc.skipAmount; //sacrificial pixels _skip = bc.skipAmount; //sacrificial pixels
_len = bc.count + _skip; _len = bc.count + _skip;
_rgbw = bc.rgbwOverride; // RGBW override in bit 7 _rgbw = bc.rgbwOverride || Bus::isRgbw(type); // RGBW override in bit 7
_iType = PolyBus::getI(type, _pins, nr, _rgbw); _iType = PolyBus::getI(type, _pins, nr, _rgbw);
if (_iType == I_NONE) return; if (_iType == I_NONE) return;
_busPtr = PolyBus::create(_iType, _pins, _len); _busPtr = PolyBus::create(_iType, _pins, _len);
@ -440,10 +446,9 @@ class BusManager {
return len; return len;
} }
static bool isRgbw(uint8_t type) { // a workaround
if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true; static inline bool isRgbw(uint8_t type) {
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; return Bus::isRgbw(type);
return false;
} }
private: private:

View File

@ -127,8 +127,9 @@ void deserializeConfig() {
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB; uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
bool reversed = elm["rev"]; bool reversed = elm["rev"];
//RGBW mode is enabled if at least one of the strips is RGBW //RGBW mode is enabled if at least one of the strips is RGBW
if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary) // if ((bool)elm[F("rgbw")]) SET_BIT(ledType,7); else UNSET_BIT(ledType,7); // hack bit 7 to indicate RGBW (as an override if necessary)
strip.isRgbw |= (bool)elm[F("rgbw")]; //(strip.isRgbw || BusManager::isRgbw(ledType)); // strip.isRgbw |= (bool)elm[F("rgbw")];
strip.isRgbw = (strip.isRgbw || Bus::isRgbw(ledType));
s++; s++;
lC += length; lC += length;
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);

View File

@ -132,11 +132,11 @@
d.getElementById("ls"+n).readOnly = !(type > 31 && type < 48); // not analog d.getElementById("ls"+n).readOnly = !(type > 31 && type < 48); // not analog
d.getElementById("LC").readOnly = !(type > 31 && type < 48); // not analog d.getElementById("LC").readOnly = !(type > 31 && type < 48); // not analog
if (change) { if (change) {
d.getElementById("ew"+n).checked = (type == 30 || type == 31 || type == 44 || type == 45); // RGBW checkbox, TYPE_xxxx values from const.h // d.getElementById("ew"+n).checked = (type == 30 || type == 31 || type == 44 || type == 45); // RGBW checkbox, TYPE_xxxx values from const.h
d.getElementById("ls"+n).value = n+1; d.getElementById("ls"+n).value = n+1;
} }
d.getElementById("ew"+n).onclick = (type > 31 && type < 48) ? (function(){return false}) : (function(){}); // prevent change for analog // d.getElementById("ew"+n).onclick = (type > 31 && type < 48) ? (function(){return false}) : (function(){}); // prevent change for analog
isRGBW |= d.getElementById("ew"+n).checked; // isRGBW |= d.getElementById("ew"+n).checked;
d.getElementById("dig"+n).style.display = (type > 31 && type < 48) ? "none":"inline"; d.getElementById("dig"+n).style.display = (type > 31 && type < 48) ? "none":"inline";
d.getElementById("psd"+n).innerHTML = (type > 31 && type < 48) ? "Index:":"Start:"; d.getElementById("psd"+n).innerHTML = (type > 31 && type < 48) ? "Index:":"Start:";
} }
@ -255,8 +255,8 @@ Color Order:
<div id="dig${i}" style="display:inline"> <div id="dig${i}" style="display:inline">
Count: <input type="number" name="LC${i}" min="0" max="${maxPB}" value="1" required oninput="UI()" /><br> Count: <input type="number" name="LC${i}" min="0" max="${maxPB}" value="1" required oninput="UI()" /><br>
Reverse (rotated 180°): <input type="checkbox" name="CV${i}"> Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
&nbsp;Skip 1<sup>st</sup> LED: <input id="sl${i}" type="checkbox" name="SL${i}"><br>
</div> </div>
&nbsp;RGBW: <input id="ew${i}" type="checkbox" name="EW${i}"><br>
</div>`; </div>`;
f.insertAdjacentHTML("beforeend", cn); f.insertAdjacentHTML("beforeend", cn);
} }
@ -329,6 +329,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()"><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br> IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()"><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br>
Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br> Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br>
Active high <input type="checkbox" name="RM"> Active high <input type="checkbox" name="RM">
<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>
Default brightness: <input name="CA" type="number" min="0" max="255" required> (0-255)<br><br> Default brightness: <input name="CA" type="number" min="0" max="255" required> (0-255)<br><br>
@ -360,7 +361,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
<option value="2">Linear (never wrap)</option> <option value="2">Linear (never wrap)</option>
<option value="3">None (not recommended)</option> <option value="3">None (not recommended)</option>
</select><br> </select><br>
Skip first LED: <input type="checkbox" name="SL"><br> <!--Skip first LED: <input type="checkbox" name="SL"><br-->
<span class="wc"> <span class="wc">
Auto-calculate white channel from RGB:<br> Auto-calculate white channel from RGB:<br>
<select name="AW"> <select name="AW">

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,15 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
DynamicJsonDocument lDoc(JSON_BUFFER_SIZE); DynamicJsonDocument lDoc(JSON_BUFFER_SIZE);
sObj = lDoc.to<JsonObject>(); sObj = lDoc.to<JsonObject>();
if (pname) sObj["n"] = pname; if (pname) sObj["n"] = pname;
#ifdef ESP8266
// use rev:2 API if more than 12 segments on ESP8266
uint8_t tooMany = 0;
for(uint8_t i=0; i < strip.getMaxSegments(); i++) if ((strip.getSegment(i)).isActive()) tooMany++;
if (tooMany>12)
#endif
sObj.remove("rev");
DEBUGFS_PRINTLN(F("Save current state")); DEBUGFS_PRINTLN(F("Save current state"));
serializeState(sObj, true); serializeState(sObj, true);
currentPreset = index; currentPreset = index;
@ -55,7 +64,15 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
DEBUGFS_PRINTLN(F("Reuse recv buffer")); DEBUGFS_PRINTLN(F("Reuse recv buffer"));
sObj.remove(F("psave")); sObj.remove(F("psave"));
sObj.remove(F("v")); sObj.remove(F("v"));
sObj.remove("rev"); // TODO: use rev:2 if more than 12 segments on ESP8266
// the following is an UGLY construct that does the job
#ifdef ESP8266
// use rev:2 API if more than 12 segments on ESP8266
uint8_t tooMany = 0;
for(uint8_t i=0; i < strip.getMaxSegments(); i++) if ((strip.getSegment(i)).isActive()) tooMany++;
if (tooMany>12)
#endif
sObj.remove("rev");
if (!sObj["o"]) { if (!sObj["o"]) {
DEBUGFS_PRINTLN(F("Save current state")); DEBUGFS_PRINTLN(F("Save current state"));

View File

@ -85,8 +85,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
strip.isRgbw = false; strip.isRgbw = false;
uint8_t skip = request->hasArg(F("SL")) ? LED_SKIP_AMOUNT : 0; // uint8_t skip = request->hasArg(F("SL")) ? LED_SKIP_AMOUNT : 0;
uint8_t colorOrder, type; uint8_t colorOrder, type, skip;
uint16_t length, start; uint16_t length, start;
uint8_t pins[5] = {255, 255, 255, 255, 255}; uint8_t pins[5] = {255, 255, 255, 255, 255};
@ -97,7 +97,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override char sl[4] = "SL"; sl[2] = 48+s; sl[3] = 0; //skip 1st LED
// char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override
if (!request->hasArg(lp)) { if (!request->hasArg(lp)) {
DEBUG_PRINTLN(F("No data.")); break; DEBUG_PRINTLN(F("No data.")); break;
} }
@ -107,8 +108,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
pins[i] = (request->arg(lp).length() > 0) ? request->arg(lp).toInt() : 255; pins[i] = (request->arg(lp).length() > 0) ? request->arg(lp).toInt() : 255;
} }
type = request->arg(lt).toInt(); type = request->arg(lt).toInt();
if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary) // if (request->hasArg(ew)) SET_BIT(type,7); else UNSET_BIT(type,7); // hack bit 7 to indicate RGBW (as a LED type override if necessary)
strip.isRgbw = strip.isRgbw || request->hasArg(ew); // strip.isRgbw = strip.isRgbw || request->hasArg(ew);
strip.isRgbw = strip.isRgbw || Bus::isRgbw(type);
skip = request->hasArg(sl) ? LED_SKIP_AMOUNT : 0;
colorOrder = request->arg(co).toInt(); colorOrder = request->arg(co).toInt();
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : t; start = (request->hasArg(ls)) ? request->arg(ls).toInt() : t;

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2104061 #define VERSION 2104071
//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

View File

@ -322,7 +322,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("LC"),ledCount); sappend('v',SET_F("LC"),ledCount);
bool skip = false; // bool skip = false;
for (uint8_t s=0; s < busses.getNumBusses(); s++) { for (uint8_t s=0; s < busses.getNumBusses(); s++) {
Bus* bus = busses.getBus(s); Bus* bus = busses.getBus(s);
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
@ -331,7 +331,8 @@ void getSettingsJS(byte subPage, char* dest)
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override char sl[4] = "SL"; sl[2] = 48+s; sl[3] = 0; //skip 1st LED
// char ew[4] = "EW"; ew[2] = 48+s; ew[3] = 0; //strip RGBW override
oappend(SET_F("addLEDs(1);")); oappend(SET_F("addLEDs(1);"));
uint8_t pins[5]; uint8_t pins[5];
uint8_t nPins = bus->getPins(pins); uint8_t nPins = bus->getPins(pins);
@ -344,8 +345,9 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',co,bus->getColorOrder()); sappend('v',co,bus->getColorOrder());
sappend('v',ls,bus->getStart()); sappend('v',ls,bus->getStart());
sappend('c',cv,bus->reversed); sappend('c',cv,bus->reversed);
sappend('c',ew,bus->isRgbw()); sappend('c',sl,bus->skipFirstLed());
if (!skip) skip = bus->skipFirstLed()>0; // sappend('c',ew,bus->isRgbw());
// if (!skip) skip = bus->skipFirstLed()>0;
} }
sappend('v',SET_F("MA"),strip.ablMilliampsMax); sappend('v',SET_F("MA"),strip.ablMilliampsMax);
sappend('v',SET_F("LA"),strip.milliampsPerLed); sappend('v',SET_F("LA"),strip.milliampsPerLed);
@ -373,7 +375,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("TL"),nightlightDelayMinsDefault); sappend('v',SET_F("TL"),nightlightDelayMinsDefault);
sappend('v',SET_F("TW"),nightlightMode); sappend('v',SET_F("TW"),nightlightMode);
sappend('i',SET_F("PB"),strip.paletteBlend); sappend('i',SET_F("PB"),strip.paletteBlend);
sappend('c',SET_F("SL"),skip); // sappend('c',SET_F("SL"),skip);
sappend('v',SET_F("RL"),rlyPin); sappend('v',SET_F("RL"),rlyPin);
sappend('c',SET_F("RM"),rlyMde); sappend('c',SET_F("RM"),rlyMde);
sappend('v',SET_F("BT"),btnPin); sappend('v',SET_F("BT"),btnPin);