Skip to content

Commit

Permalink
Busses extend total configured LEDs if required (closes Aircoookie#2056
Browse files Browse the repository at this point in the history
… )

Fixed extra button pins defaulting to 0 on first boot
  • Loading branch information
Aircoookie committed Jul 9, 2021
1 parent e04b965 commit 5da4763
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

### Builds after release 0.12.0

#### Build 2107090

- Busses extend total configured LEDs if required
- Fixed extra button pins defaulting to 0 on first boot

#### Build 2107080

- Made Peek use the main websocket connection instead of opening a second one
Expand Down
12 changes: 12 additions & 0 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ struct BusConfig {
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
}

//validates start and length and extends total if needed
bool adjustBounds(uint16_t& total) {
if (!count) count = 1;
if (count > MAX_LEDS_PER_BUS) count = MAX_LEDS_PER_BUS;
if (start >= MAX_LEDS) return false;
//limit length of strip if it would exceed total permissible LEDs
if (start + count > MAX_LEDS) count = MAX_LEDS - start;
//extend total count accordingly
if (start + count > total) total = start + count;
return true;
}
};

//parent class of BusDigital and BusPwm
Expand Down
51 changes: 20 additions & 31 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (fromFS || !ins.isNull()) {
uint8_t s = 0; //bus iterator
strip.isRgbw = false;
strip.isOffRefreshRequred = false;
busses.removeAll();
uint32_t mem = 0;
for (JsonObject elm : ins) {
Expand All @@ -99,25 +100,23 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (i>4) break;
}

uint16_t length = elm[F("len")];
if (length==0) continue;
uint16_t length = elm[F("len")] | 1;
uint8_t colorOrder = (int)elm[F("order")];
//only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
uint8_t skipFirst = elm[F("skip")];
uint16_t start = elm[F("start")] | 0;
if (start >= ledCount) continue;
//limit length of strip if it would exceed total configured LEDs
if (start + length > ledCount) length = ledCount - start;
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
bool reversed = elm["rev"];
//RGBW mode is enabled if at least one of the strips is RGBW
strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(ledType));
//refresh is required to remain off if at least one of the strips requires the refresh.
strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(ledType);
s++;

BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
mem += busses.memUsage(bc);
if (mem <= MAX_LED_MEMORY) busses.add(bc);
if (bc.adjustBounds(ledCount)) {
//RGBW mode is enabled if at least one of the strips is RGBW
strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(ledType));
//refresh is required to remain off if at least one of the strips requires the refresh.
strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(ledType);
s++;
mem += busses.memUsage(bc);
if (mem <= MAX_LED_MEMORY) busses.add(bc);
}
}
strip.finalizeInit(ledCount);
}
Expand Down Expand Up @@ -153,7 +152,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
}
} else {
// new install/missing configuration (button 0 has defaults)
if (fromFS)
if (fromFS)
for (uint8_t s=1; s<WLED_MAX_BUTTONS; s++) {
btnPin[s] = -1;
buttonType[s] = BTN_TYPE_NONE;
Expand Down Expand Up @@ -482,7 +481,7 @@ void serializeConfig() {

JsonObject wifi = doc.createNestedObject("wifi");
wifi[F("sleep")] = !noWifiSleep;
wifi[F("phy")] = 1;
//wifi[F("phy")] = 1;

#ifdef WLED_USE_ETHERNET
JsonObject ethernet = doc.createNestedObject("eth");
Expand Down Expand Up @@ -520,28 +519,18 @@ void serializeConfig() {
hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used)
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");

// there is always at least one button
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
hw_btn_ins_0["type"] = buttonType[0];
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
hw_btn_ins_0_pin.add(btnPin[0]);
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
hw_btn_ins_0_macros.add(macroButton[0]);
hw_btn_ins_0_macros.add(macroLongPress[0]);
hw_btn_ins_0_macros.add(macroDoublePress[0]);

// additional buttons
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) {
//if (btnPin[i]<0) continue;
hw_btn_ins_0 = hw_btn_ins.createNestedObject();
// configuration for all buttons
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
hw_btn_ins_0["type"] = buttonType[i];
hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
hw_btn_ins_0_pin.add(btnPin[i]);
hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
hw_btn_ins_0_macros.add(macroButton[i]);
hw_btn_ins_0_macros.add(macroLongPress[i]);
hw_btn_ins_0_macros.add(macroDoublePress[i]);
}

hw_btn[F("tt")] = touchThreshold;
hw_btn["mqtt"] = buttonPublishMqtt;

Expand Down
17 changes: 13 additions & 4 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,17 @@ void WLED::loop()
strip.isRgbw = false;
for (uint8_t i = 0; i < WLED_MAX_BUSSES; i++) {
if (busConfigs[i] == nullptr) break;
mem += busses.memUsage(*busConfigs[i]);
if (mem <= MAX_LED_MEMORY) busses.add(*busConfigs[i]);
//if (BusManager::isRgbw(busConfigs[i]->type)) strip.isRgbw = true;
strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(busConfigs[i]->type));

if (busConfigs[i]->adjustBounds(ledCount)) {
mem += busses.memUsage(*busConfigs[i]);
if (mem <= MAX_LED_MEMORY) {
busses.add(*busConfigs[i]);
//RGBW mode is enabled if at least one of the strips is RGBW
strip.isRgbw = (strip.isRgbw || BusManager::isRgbw(busConfigs[i]->type));
//refresh is required to remain off if at least one of the strips requires the refresh.
strip.isOffRefreshRequred |= BusManager::isOffRefreshRequred(busConfigs[i]->type);
}
}
delete busConfigs[i]; busConfigs[i] = nullptr;
}
strip.finalizeInit(ledCount);
Expand Down Expand Up @@ -284,6 +291,8 @@ void WLED::setup()
pinManager.allocatePin(2);
#endif

for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) btnPin[i] = -1;

bool fsinit = false;
DEBUGFS_PRINTLN(F("Mount FS"));
#ifdef ARDUINO_ARCH_ESP32
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2107080
#define VERSION 2107090

//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
Expand Down

0 comments on commit 5da4763

Please sign in to comment.