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

En-/disable LED maps when receiving realtime data #3554

Merged
merged 8 commits into from
Jan 10, 2024
3 changes: 2 additions & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ class WS2812FX { // 96 bytes
currentMilliamps,
getLengthPhysical(void),
getLengthTotal(void), // will include virtual/nonexistent pixels in matrix
getFps();
getFps(),
getMappedPixelIndex(uint16_t index);

inline uint16_t getFrameTime(void) { return _frametime; }
inline uint16_t getMinShowDelay(void) { return MIN_SHOW_DELAY; }
Expand Down
16 changes: 11 additions & 5 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,7 @@ void Segment::refreshLightCapabilities() {
if (start < Segment::maxWidth * Segment::maxHeight) {
// we are withing 2D matrix (includes 1D segments)
for (int y = startY; y < stopY; y++) for (int x = start; x < stop; x++) {
uint16_t index = x + Segment::maxWidth * y;
if (index < strip.customMappingSize) index = strip.customMappingTable[index]; // convert logical address to physical
uint16_t index = strip.getMappedPixelIndex(x + Segment::maxWidth * y); // convert logical address to physical
if (index < 0xFFFFU) {
if (segStartIdx > index) segStartIdx = index;
if (segStopIdx < index) segStopIdx = index;
Expand Down Expand Up @@ -1214,13 +1213,13 @@ void WS2812FX::service() {
}

void IRAM_ATTR WS2812FX::setPixelColor(int i, uint32_t col) {
if (i < customMappingSize) i = customMappingTable[i];
i = getMappedPixelIndex(i);
if (i >= _length) return;
busses.setPixelColor(i, col);
}

uint32_t IRAM_ATTR WS2812FX::getPixelColor(uint16_t i) {
if (i < customMappingSize) i = customMappingTable[i];
i = getMappedPixelIndex(i);
if (i >= _length) return 0;
return busses.getPixelColor(i);
}
Expand Down Expand Up @@ -1435,7 +1434,7 @@ void WS2812FX::setSegment(uint8_t segId, uint16_t i1, uint16_t i2, uint8_t group
DEBUG_PRINT(F("Segment queued: ")); DEBUG_PRINTLN(segId);
return; // queued changes are applied immediately after effect function returns
}

_segments[segId].setUp(i1, i2, grouping, spacing, offset, startY, stopY);
if (segId > 0 && segId == getSegmentsNum()-1 && i2 <= i1) _segments.pop_back(); // if last segment was deleted remove it from vector
}
Expand Down Expand Up @@ -1701,6 +1700,13 @@ bool WS2812FX::deserializeMap(uint8_t n) {
return true;
}

uint16_t WS2812FX::getMappedPixelIndex(uint16_t index) {
ezcGman marked this conversation as resolved.
Show resolved Hide resolved
if ((realtimeMode == REALTIME_MODE_INACTIVE || realtimeRespectLedMaps)
&& index < customMappingSize) index = strip.customMappingTable[index]; // convert logical address to physical
ezcGman marked this conversation as resolved.
Show resolved Hide resolved

return index;
}


WS2812FX* WS2812FX::instance = nullptr;

Expand Down
2 changes: 2 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
JsonObject if_live = interfaces["live"];
CJSON(receiveDirect, if_live["en"]); // UDP/Hyperion realtime
CJSON(useMainSegmentOnly, if_live[F("mso")]);
CJSON(realtimeRespectLedMaps, if_live[F("rlm")]);
CJSON(e131Port, if_live["port"]); // 5568
if (e131Port == DDP_DEFAULT_PORT) e131Port = E131_DEFAULT_PORT; // prevent double DDP port allocation
CJSON(e131Multicast, if_live[F("mc")]);
Expand Down Expand Up @@ -898,6 +899,7 @@ void serializeConfig() {
JsonObject if_live = interfaces.createNestedObject("live");
if_live["en"] = receiveDirect; // UDP/Hyperion realtime
if_live[F("mso")] = useMainSegmentOnly;
if_live[F("rlm")] = realtimeRespectLedMaps;
if_live["port"] = e131Port;
if_live[F("mc")] = e131Multicast;

Expand Down
5 changes: 3 additions & 2 deletions wled00/data/settings_sync.htm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV();SetVal();
Expand Down Expand Up @@ -156,7 +156,8 @@ <h3>Instance List</h3>
<hr class="sml">
<h3>Realtime</h3>
Receive UDP realtime: <input type="checkbox" name="RD"><br>
Use main segment only: <input type="checkbox" name="MO"><br><br>
Use main segment only: <input type="checkbox" name="MO"><br>
Respect LED Maps: <input type="checkbox" name="RLM"><br><br>
<i>Network DMX input</i><br>
Type:
<select name=DI onchange="SP(); adj();">
Expand Down
471 changes: 236 additions & 235 deletions wled00/html_settings.h

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)

receiveDirect = request->hasArg(F("RD")); // UDP realtime
useMainSegmentOnly = request->hasArg(F("MO"));
realtimeRespectLedMaps = request->hasArg(F("RLM"));
e131SkipOutOfSequence = request->hasArg(F("ES"));
e131Multicast = request->hasArg(F("EM"));
t = request->arg(F("EP")).toInt();
Expand Down Expand Up @@ -1036,6 +1037,10 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
pos = req.indexOf(F("RD="));
if (pos > 0) receiveDirect = (req.charAt(pos+3) != '0');

// Respect LED maps when receiving realtime data
pos = req.indexOf(F("RLM="));
ezcGman marked this conversation as resolved.
Show resolved Hide resolved
if (pos > 0) realtimeRespectLedMaps = (req.charAt(pos+4) != '0');

//main toggle on/off (parse before nightlight, #1214)
pos = req.indexOf(F("&T="));
if (pos > 0) {
Expand Down
7 changes: 4 additions & 3 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#ifndef WLED_DISABLE_MQTT
#define WLED_ENABLE_MQTT // saves 12kb
#endif
#ifndef WLED_DISABLE_ADALIGHT // can be used to disable reading commands from serial RX pin (see issue #3128).
#define WLED_ENABLE_ADALIGHT // disable saves 5Kb (uses GPIO3 (RX) for serial). Related serial protocols: Adalight/TPM2, Improv, Serial JSON, Continuous Serial Streaming
#ifndef WLED_DISABLE_ADALIGHT // can be used to disable reading commands from serial RX pin (see issue #3128).
#define WLED_ENABLE_ADALIGHT // disable saves 5Kb (uses GPIO3 (RX) for serial). Related serial protocols: Adalight/TPM2, Improv, Serial JSON, Continuous Serial Streaming
#else
#undef WLED_ENABLE_ADALIGHT // disable has priority over enable
#endif
Expand All @@ -44,7 +44,7 @@
#define WLED_ENABLE_WEBSOCKETS
#endif

//#define WLED_DISABLE_ESPNOW // Removes dependence on esp now
//#define WLED_DISABLE_ESPNOW // Removes dependence on esp now

#define WLED_ENABLE_FS_EDITOR // enable /edit page for editing FS content. Will also be disabled with OTA lock

Expand Down Expand Up @@ -634,6 +634,7 @@ WLED_GLOBAL unsigned long realtimeTimeout _INIT(0);
WLED_GLOBAL uint8_t tpmPacketCount _INIT(0);
WLED_GLOBAL uint16_t tpmPayloadFrameSize _INIT(0);
WLED_GLOBAL bool useMainSegmentOnly _INIT(false);
WLED_GLOBAL bool realtimeRespectLedMaps _INIT(true); // Respect LED maps when receiving realtime data

WLED_GLOBAL unsigned long lastInterfaceUpdate _INIT(0);
WLED_GLOBAL byte interfaceUpdateCallMode _INIT(CALL_MODE_INIT);
Expand Down
1 change: 1 addition & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void getSettingsJS(byte subPage, char* dest)

sappend('c',SET_F("RD"),receiveDirect);
sappend('c',SET_F("MO"),useMainSegmentOnly);
sappend('c',SET_F("RLM"),realtimeRespectLedMaps);
sappend('v',SET_F("EP"),e131Port);
sappend('c',SET_F("ES"),e131SkipOutOfSequence);
sappend('c',SET_F("EM"),e131Multicast);
Expand Down
Loading