Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch supported LED types from Bus #4056

Closed
wants to merge 13 commits into from
187 changes: 187 additions & 0 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,86 @@ void BusDigital::cleanup() {
pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
}

std::vector<LEDType> BusDigital::getLEDTypes() {
blazoncek marked this conversation as resolved.
Show resolved Hide resolved
std::vector<LEDType> result;
LEDType ledType;

ledType.type = F("D");

ledType.id = 22;
ledType.name = F("WS281x");
result.push_back(ledType);

ledType.id = 30;
ledType.name = F("SK6812/WS2814 RGBW");
result.push_back(ledType);

ledType.id = 31;
ledType.name = F("TM1814");
result.push_back(ledType);

ledType.id = 24;
ledType.name = F("400kHz");
result.push_back(ledType);

ledType.id = 25;
ledType.name = F("TM1829");
result.push_back(ledType);

ledType.id = 26;
ledType.name = F("UCS8903");
result.push_back(ledType);

ledType.id = 27;
ledType.name = F("APA106/PL9823");
result.push_back(ledType);

ledType.id = 33;
ledType.name = F("TM1914");
result.push_back(ledType);

ledType.id = 28;
ledType.name = F("FW1906 GRBCW");
result.push_back(ledType);

ledType.id = 29;
ledType.name = F("UCS8904 RGBW");
result.push_back(ledType);

ledType.id = 32;
ledType.name = F("WS2805 RGBCW");
result.push_back(ledType);

ledType.id = 19;
ledType.name = F("WS2811 White");
result.push_back(ledType);


ledType.type = F("2P");

ledType.id = 50;
ledType.name = F("WS2801");
result.push_back(ledType);

ledType.id = 51;
ledType.name = F("APA102");
result.push_back(ledType);

ledType.id = 52;
ledType.name = F("LPD8806");
result.push_back(ledType);

ledType.id = 54;
ledType.name = F("LPD6803");
result.push_back(ledType);

ledType.id = 53;
ledType.name = F("PP9813");
result.push_back(ledType);

return result;
}


BusPwm::BusPwm(BusConfig &bc)
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
Expand Down Expand Up @@ -555,6 +635,43 @@ void BusPwm::deallocatePins() {
#endif
}

std::vector<LEDType> BusPwm::getLEDTypes() {
std::vector<LEDType> result;
LEDType ledType;

ledType.id = 41;
ledType.name = F("PWM White");
ledType.type = F("A");
result.push_back(ledType);

ledType.id = 42;
ledType.name = F("PWM CCT");
ledType.type = F("AA");
result.push_back(ledType);

ledType.id = 43;
ledType.name = F("PWM RGB");
ledType.type = F("AAA");
result.push_back(ledType);

ledType.id = 44;
ledType.name = F("PWM RGBW");
ledType.type = F("AAAA");
result.push_back(ledType);

ledType.id = 45;
ledType.name = F("PWM RGB+CCT");
ledType.type = F("AAAAA");
result.push_back(ledType);

// ledType.id = 46;
// ledType.name = F("PWM RGB+DCCT");
// ledType.type = F("AAAAAA");
// result.push_back(ledType);

return result;
}


BusOnOff::BusOnOff(BusConfig &bc)
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
Expand Down Expand Up @@ -599,6 +716,17 @@ uint8_t BusOnOff::getPins(uint8_t* pinArray) {
return 1;
}

std::vector<LEDType> BusOnOff::getLEDTypes() {
std::vector<LEDType> result;
LEDType ledType;
ledType.id = TYPE_ONOFF;
ledType.name = F("On/Off");
ledType.type = "";
result.push_back(ledType);
return result;

}


BusNetwork::BusNetwork(BusConfig &bc)
: Bus(bc.type, bc.start, bc.autoWhite, bc.count)
Expand Down Expand Up @@ -659,6 +787,35 @@ uint8_t BusNetwork::getPins(uint8_t* pinArray) {
return 4;
}

std::vector<LEDType> BusNetwork::getLEDTypes() {
std::vector<LEDType> result;
LEDType ledType;

ledType.type = F("V");

ledType.id = TYPE_NET_DDP_RGB;
ledType.name = F("DDP RGB (network)");
result.push_back(ledType);

// ledType.id = 81";
// ledType.name = F("E1.31 RGB (network)");
// result.push_back(ledType);

ledType.id = TYPE_NET_ARTNET_RGB;
ledType.name = F("Art-Net RGB (network)");
result.push_back(ledType);

ledType.id = TYPE_NET_DDP_RGBW;
ledType.name = F("DDP RGBW (network)");
result.push_back(ledType);

ledType.id = TYPE_NET_ARTNET_RGBW;
ledType.name = F("Art-Net RGBW (network)");
result.push_back(ledType);

return result;
}

void BusNetwork::cleanup() {
_type = I_NONE;
_valid = false;
Expand Down Expand Up @@ -706,6 +863,35 @@ int BusManager::add(BusConfig &bc) {
return numBusses++;
}

String BusManager::getLEDTypes() {
std::vector<LEDType> types;
String json = "[";

std::vector<LEDType> busTypes;

busTypes = BusDigital::getLEDTypes();
types.insert(types.end(), busTypes.begin(), busTypes.end());

busTypes = BusOnOff::getLEDTypes();
types.insert(types.end(), busTypes.begin(), busTypes.end());

busTypes = BusPwm::getLEDTypes();
types.insert(types.end(), busTypes.begin(), busTypes.end());

busTypes = BusNetwork::getLEDTypes();
types.insert(types.end(), busTypes.begin(), busTypes.end());

for(int t = 0; t < types.size(); t++) {
LEDType type = types.at(t);
String id = String(type.id);
json += "{\"i\":"+id+",\"t\":\""+type.type+"\",\"n\":\""+type.name+"\"},";
}

json += "]";
return json;
}


void BusManager::useParallelOutput(void) {
_parallelOutputs = 8; // hardcoded since we use NPB I2S x8 methods
PolyBus::setParallelI2S1Output();
Expand Down Expand Up @@ -859,6 +1045,7 @@ uint16_t BusManager::getTotalLength() {
return len;
}


bool PolyBus::useParallelI2S = false;

// Bus static member definition
Expand Down
11 changes: 11 additions & 0 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "const.h"
#include <vector>

//colors.cpp
uint16_t approximateKelvinFromRGB(uint32_t rgb);
Expand Down Expand Up @@ -103,6 +104,11 @@ struct ColorOrderMap {
ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
};

struct LEDType {
uint8_t id;
String type;
String name;
};

//parent class of BusDigital, BusPwm, and BusNetwork
class Bus {
Expand Down Expand Up @@ -258,6 +264,7 @@ class BusDigital : public Bus {
uint16_t getMaxCurrent() override { return _milliAmpsMax; }
void reinit();
void cleanup();
static std::vector<LEDType> getLEDTypes();

private:
uint8_t _skip;
Expand Down Expand Up @@ -296,6 +303,7 @@ class BusPwm : public Bus {
uint16_t getFrequency() override { return _frequency; }
void show() override;
void cleanup() { deallocatePins(); }
static std::vector<LEDType> getLEDTypes();

private:
uint8_t _pins[5];
Expand All @@ -320,6 +328,7 @@ class BusOnOff : public Bus {
uint8_t getPins(uint8_t* pinArray) override;
void show() override;
void cleanup() { pinManager.deallocatePin(_pin, PinOwner::BusOnOff); }
static std::vector<LEDType> getLEDTypes();

private:
uint8_t _pin;
Expand All @@ -340,6 +349,7 @@ class BusNetwork : public Bus {
uint8_t getPins(uint8_t* pinArray) override;
void show() override;
void cleanup();
static std::vector<LEDType> getLEDTypes();

private:
IPAddress _client;
Expand Down Expand Up @@ -386,6 +396,7 @@ class BusManager {
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
static uint16_t getTotalLength();
static uint8_t getNumBusses() { return numBusses; }
static String getLEDTypes();

static void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); }
static const ColorOrderMap& getColorOrderMap() { return colorOrderMap; }
Expand Down
53 changes: 24 additions & 29 deletions wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@
// maxCO - max Color Order mappings
oMaxB = maxB = b; maxD = d, maxA = a, maxV = v; maxM = m; maxPB = p; maxL = l; maxCO = o;
}
function addLEDTypes(config) {
var config = getLEDTypes();
console.log("addLEDTypes")
console.log(config);
var s = d.getElementsByTagName("select");
for (i=0; i<s.length; i++) {
// is the field a LED type?
if (s[i].name.substring(0,2)=="LT") {
var sel = s[i];
for(var t = 0; t < config.length; t++) {
var type = config[t];
let opt = d.createElement("option");
opt.value = type.i;
opt.text = type.n;
if(type.t != undefined && type.t != "") {
opt.setAttribute('data-type', type.t);
}
sel.appendChild(opt);
}
}
}
}
function pinsOK() {
var ok = true;
var nList = d.Sf.querySelectorAll("#mLC input[name^=L]");
Expand Down Expand Up @@ -408,35 +430,7 @@
<hr class="sml">
${i+1}:
<select name="LT${s}" onchange="UI(true)">${i>=maxB && false ? '' :
'<option value="22" data-type="D">WS281x</option>\
<option value="30" data-type="D">SK6812/WS2814 RGBW</option>\
<option value="31" data-type="D">TM1814</option>\
<option value="24" data-type="D">400kHz</option>\
<option value="25" data-type="D">TM1829</option>\
<option value="26" data-type="D">UCS8903</option>\
<option value="27" data-type="D">APA106/PL9823</option>\
<option value="33" data-type="D">TM1914</option>\
<option value="28" data-type="D">FW1906 GRBCW</option>\
<option value="29" data-type="D">UCS8904 RGBW</option>\
<option value="32" data-type="D">WS2805 RGBCW</option>\
<option value="50" data-type="2P">WS2801</option>\
<option value="51" data-type="2P">APA102</option>\
<option value="52" data-type="2P">LPD8806</option>\
<option value="54" data-type="2P">LPD6803</option>\
<option value="53" data-type="2P">P9813</option>\
<option value="19" data-type="D">WS2811 White</option>\
<option value="40">On/Off</option>\
<option value="41" data-type="A">PWM White</option>\
<option value="42" data-type="AA">PWM CCT</option>\
<option value="43" data-type="AAA">PWM RGB</option>\
<option value="44" data-type="AAAA">PWM RGBW</option>\
<option value="45" data-type="AAAAA">PWM RGB+CCT</option>\
<!--option value="46" data-type="AAAAAA">PWM RGB+DCCT</option-->'}
<option value="80" data-type="V">DDP RGB (network)</option>
<!--option value="81" data-type="V">E1.31 RGB (network)</option-->
<option value="82" data-type="V">Art-Net RGB (network)</option>
<option value="88" data-type="V">DDP RGBW (network)</option>
<option value="89" data-type="V">Art-Net RGBW (network)</option>
''}
</select><br>
<div id="abl${s}">
mA/LED: <select name="LAsel${s}" onchange="enLA(this,'${s}');UI();">
Expand Down Expand Up @@ -476,6 +470,7 @@
<div id="dig${s}a" style="display:inline"><br>Auto-calculate white channel from RGB:<br><select name="AW${s}"><option value=0>None</option><option value=1>Brighter</option><option value=2>Accurate</option><option value=3>Dual</option><option value=4>Max</option></select>&nbsp;</div>
</div>`;
f.insertAdjacentHTML("beforeend", cn);
addLEDTypes();
let sel = d.getElementsByName("LT"+s)[0]
if (i >= maxB || digitalB >= maxD) disable(sel,'option[data-type="D"]');
if (i >= maxB || twopinB >= 1) disable(sel,'option[data-type="2P"]');
Expand Down
2 changes: 2 additions & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("IT"),irEnabled);
#endif
sappend('c',SET_F("MSO"),!irApplyToAllSelected);

oappend(SET_F("} function getLEDTypes(){ return ")); oappend(BusManager::getLEDTypes().c_str()); oappend(SET_F(";"));
}

if (subPage == SUBPAGE_UI)
Expand Down