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
74 changes: 74 additions & 0 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,30 @@ void BusDigital::cleanup() {
pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
}

std::vector<LEDType> BusDigital::getLEDTypes() {
blazoncek marked this conversation as resolved.
Show resolved Hide resolved
return {
{TYPE_WS2812_RGB, "D", PSTR("WS281x")},
{TYPE_SK6812_RGBW, "D", PSTR("SK6812/WS2814 RGBW")},
{TYPE_TM1814, "D", PSTR("TM1814")},
{TYPE_WS2811_400KHZ, "D", PSTR("400kHz")},
{TYPE_TM1829, "D", PSTR("TM1829")},
{TYPE_UCS8903, "D", PSTR("UCS8903")},
{TYPE_APA106, "D", PSTR("APA106/PL9823")},
{TYPE_TM1914, "D", PSTR("TM1914")},
{TYPE_FW1906, "D", PSTR("FW1906 GRBCW")},
{TYPE_UCS8904, "D", PSTR("UCS8904 RGBW")},
{TYPE_WS2805, "D", PSTR("WS2805 RGBCW")},
{TYPE_WS2812_1CH_X3, "D", PSTR("WS2811 White")},
//{TYPE_WS2812_2CH_X3, "D", PSTR("WS2811 CCT")},
//{TYPE_WS2812_WWA, "D", PSTR("WS2811 WWA")},
{TYPE_WS2801, "2P", PSTR("WS2801")},
{TYPE_APA102, "2P", PSTR("APA102")},
{TYPE_LPD8806, "2P", PSTR("LPD8806")},
{TYPE_LPD6803, "2P", PSTR("LPD6803")},
{TYPE_P9813, "2P", PSTR("PP9813")}
};
}


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

std::vector<LEDType> BusPwm::getLEDTypes() {
return {
{TYPE_ANALOG_1CH, "A", PSTR("PWM White")},
{TYPE_ANALOG_2CH, "AA", PSTR("PWM CCT")},
{TYPE_ANALOG_3CH, "AAA", PSTR("PWM RGB")},
{TYPE_ANALOG_4CH, "AAAA", PSTR("PWM RGBW")},
{TYPE_ANALOG_5CH, "AAAAA", PSTR("PWM RGB+CCT")},
//{TYPE_ANALOG_6CH, "AAAAAA", PSTR("PWM RGB+DCCT")},
};
}


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

std::vector<LEDType> BusOnOff::getLEDTypes() {
return {
{TYPE_ONOFF, "", PSTR("On/Off")}
};
}


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

std::vector<LEDType> BusNetwork::getLEDTypes() {
return {
{TYPE_NET_DDP_RGB, "V", PSTR("DDP RGB (network)")},
{TYPE_NET_ARTNET_RGB, "V", PSTR("Art-Net RGB (network)")},
{TYPE_NET_DDP_RGBW, "V", PSTR("DDP RGBW (network)")},
{TYPE_NET_ARTNET_RGBW, "V", PSTR("Art-Net RGBW (network)")}
};
}

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

static String LEDTypesToJson(const std::vector<LEDType>& types) {
String json;
for(auto& type: types) {
String id = String(type.id);
json += "{i:" + id + F(",t:\"") + FPSTR(type.type) + F("\",n:\"") + FPSTR(type.name) + F("\"},");
}
return json;
}

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

json += LEDTypesToJson(BusDigital::getLEDTypes());
json += LEDTypesToJson(BusOnOff::getLEDTypes());
json += LEDTypesToJson(BusPwm::getLEDTypes());
json += LEDTypesToJson(BusNetwork::getLEDTypes());

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 +932,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];
};

typedef struct {
uint8_t id;
const char *type;
const char *name;
} LEDType;

//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
30 changes: 1 addition & 29 deletions wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -408,35 +408,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