Skip to content

Commit

Permalink
Auto-create segments based on configured busses
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Jun 24, 2021
1 parent b73aaec commit 660de0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
6 changes: 6 additions & 0 deletions tools/WLED_ESP32_16MB.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x200000,
app1, app, ota_1, 0x210000,0x200000,
spiffs, data, spiffs, 0x410000,0xBE0000,
4 changes: 3 additions & 1 deletion usermods/EXAMPLE_v2/usermod_v2_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class MyExampleUsermod : public Usermod {
void readFromConfig(JsonObject& root)
{
JsonObject top = root["top"];
userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot)
if (!top.isNull()) {
userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot)
}
}


Expand Down
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ class WS2812FX {
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;

uint16_t _length, _lengthRaw, _virtualSegmentLength;
uint16_t _length, _virtualSegmentLength;
uint16_t _rand16seed;
uint8_t _brightness;
uint16_t _usedSegmentData = 0;
Expand Down
41 changes: 33 additions & 8 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@
#define DEFAULT_LED_TYPE TYPE_WS2812_RGB
#endif

#if MAX_NUM_SEGMENTS < WLED_MAX_BUSSES
#error "Max segments must be at least max number of busses!"
#endif

//do not call this method from system context (network callback)
void WS2812FX::finalizeInit(uint16_t countPixels)
{
RESET_RUNTIME;
_length = countPixels;
_lengthRaw = _length;

//if busses failed to load, add default (FS issue...)
if (busses.getNumBusses() == 0) {
Expand All @@ -77,7 +80,7 @@ void WS2812FX::finalizeInit(uint16_t countPixels)
for (uint8_t i = 0; i < defNumBusses; i++) {
uint8_t defPin[] = {defDataPins[i]};
uint16_t start = prevLen;
uint16_t count = _lengthRaw;
uint16_t count = _length;
if (defNumBusses > 1 && defNumCounts) {
count = defCounts[(i < defNumCounts) ? i : defNumCounts -1];
}
Expand All @@ -89,22 +92,44 @@ void WS2812FX::finalizeInit(uint16_t countPixels)

deserializeMap();

//make segment 0 cover the entire strip
_segments[0].start = 0;
_segments[0].stop = _length;
uint16_t segStarts[MAX_NUM_SEGMENTS] = {0};
uint16_t segStops [MAX_NUM_SEGMENTS] = {0};

setBrightness(_brightness);

#ifdef ESP8266
//TODO make sure segments are only refreshed when bus config actually changed (new settings page)
//make one segment per bus
uint8_t s = 0;
for (uint8_t i = 0; i < busses.getNumBusses(); i++) {
Bus* b = busses.getBus(i);

segStarts[s] = b->getStart();
segStops[s] = segStarts[s] + b->getLength();

//check for overlap with previous segments
for (uint8_t j = 0; j < s; j++) {
if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) {
//segments overlap, merge
segStarts[j] = min(segStarts[s],segStarts[j]);
segStops [j] = max(segStops [s],segStops [j]); segStops[s] = 0;
s--;
}
}
s++;

#ifdef ESP8266
if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue;
uint8_t pins[5];
b->getPins(pins);
BusDigital* bd = static_cast<BusDigital*>(b);
if (pins[0] == 3) bd->reinit();
#endif
}

for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
_segments[i].start = segStarts[i];
_segments[i].stop = segStops [i];
}
#endif
}

void WS2812FX::service() {
Expand Down Expand Up @@ -503,7 +528,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)

if (i < customMappingSize) i = customMappingTable[i];

if (i >= _lengthRaw) return 0;
if (i >= _length) return 0;

return busses.getPixelColor(i);
}
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 2106200
#define VERSION 2106240

//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 660de0b

Please sign in to comment.