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 config from Bus #4058

Draft
wants to merge 10 commits into
base: 0_15
Choose a base branch
from
Draft
197 changes: 197 additions & 0 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,89 @@ void BusDigital::cleanup() {
pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
}

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

ledType.type = F("D");
ledType.config = F("{\"pins\":[\"Data GPIO\"]}");

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.config = F("{\"pins\":[\"Data GPIO\",\"Clk GPIO\"]}");


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 +638,47 @@ void BusPwm::deallocatePins() {
#endif
}

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

ledType.config = F("{\"pins\":[\"GPIO Pin\"]}");

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

ledType.config = F("{\"pins\":[\"GPIO Pins\"]}");

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 +723,18 @@ uint8_t BusOnOff::getPins(uint8_t* pinArray) {
return 1;
}

std::vector<LEDType> BusOnOff::getLEDTypes() {
std::vector<LEDType> result;
LEDType ledType;
ledType.id = 40;
ledType.name = F("On/Off");
ledType.type = "";
ledType.config = F("{\"pins\":[\"GPIO Pin\"]}");
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 +795,37 @@ uint8_t BusNetwork::getPins(uint8_t* pinArray) {
return 4;
}

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

ledType.config = F("{\"pins\":[\"IP Address\"]}");

ledType.type = F("V");

ledType.id = 80;
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 = 82;
ledType.name = F("Art-Net RGB (network)");
result.push_back(ledType);

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

ledType.id = 89;
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 +873,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 += "{\"id\":"+id+",\"type\":\""+type.type+"\",\"name\":\""+type.name+"\",\"config\":"+type.config+"},";
}

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 +1055,7 @@ uint16_t BusManager::getTotalLength() {
return len;
}


bool PolyBus::useParallelI2S = false;

// Bus static member definition
Expand Down
12 changes: 12 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,12 @@ struct ColorOrderMap {
ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
};

struct LEDType {
uint8_t id;
String type;
String name;
String config = "{}";
};

//parent class of BusDigital, BusPwm, and BusNetwork
class Bus {
Expand Down Expand Up @@ -258,6 +265,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 +304,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 +329,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 +350,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 +397,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
Loading