Skip to content

Commit

Permalink
Tighten LED types JSON assembly
Browse files Browse the repository at this point in the history
We don't really need to bother building the whole list, just the string.

Saves about 300 bytes of code.
  • Loading branch information
willmmiles committed Aug 21, 2024
1 parent 566c9f0 commit 16716d4
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,29 +756,23 @@ 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 = "[";

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 + F(",t:\"") + FPSTR(type.type) + F("\",n:\"") + FPSTR(type.name) + F("\"},");
}
json += LEDTypesToJson(BusDigital::getLEDTypes());
json += LEDTypesToJson(BusOnOff::getLEDTypes());
json += LEDTypesToJson(BusPwm::getLEDTypes());
json += LEDTypesToJson(BusNetwork::getLEDTypes());

json += "]";
return json;
Expand Down

0 comments on commit 16716d4

Please sign in to comment.