From caa9cc32d74c6ce8354fce01af20284a825e23d6 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 4 Oct 2021 19:41:20 +0200 Subject: [PATCH] Removed double buffer. Moved bri scaling into UDP function. Prevent double DDP port allocation. --- wled00/bus_manager.h | 20 ++------------------ wled00/cfg.cpp | 1 + wled00/fcn_declare.h | 2 +- wled00/udp.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index a39051ef9..23d3ebc08 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -393,7 +393,6 @@ class BusNetwork : public Bus { _client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]); _broadcastLock = false; _valid = true; - _data2 = (byte *)malloc(_len * _UDPchannels); }; void setPixelColor(uint16_t pix, uint32_t c) { @@ -419,20 +418,7 @@ class BusNetwork : public Bus { void show() { if (!_valid || !canShow()) return; _broadcastLock = true; - // apply brightness to second buffer - if (_data2 == nullptr) { - // but display original buffer if memory allocation failed - realtimeBroadcast(_UDPtype, _client, _len, _data, _rgbw); - } else { - for (uint16_t pix=0; pix<_len; pix++) { - uint16_t offset = pix * _UDPchannels; - _data2[offset ] = scale8(_data[offset ], _bri); - _data2[offset+1] = scale8(_data[offset+1], _bri); - _data2[offset+2] = scale8(_data[offset+2], _bri); - if (_rgbw) _data2[offset+3] = scale8(_data[offset+3], _bri); - } - realtimeBroadcast(_UDPtype, _client, _len, _data2, _rgbw); - } + realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw); _broadcastLock = false; } @@ -465,8 +451,6 @@ class BusNetwork : public Bus { _valid = false; if (_data != nullptr) free(_data); _data = nullptr; - if (_data2 != nullptr) free(_data2); - _data2 = nullptr; } ~BusNetwork() { @@ -482,7 +466,7 @@ class BusNetwork : public Bus { uint8_t _UDPchannels; bool _rgbw; bool _broadcastLock; - byte *_data, *_data2; + byte *_data; }; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 8adaac2fe..1a499404b 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -263,6 +263,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { JsonObject if_live = interfaces["live"]; CJSON(receiveDirect, if_live["en"]); 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")]); JsonObject if_live_dmx = if_live[F("dmx")]; diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index 4621f4a31..3b6e45cd1 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -195,7 +195,7 @@ bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte //udp.cpp void notify(byte callMode, bool followUp=false); -uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, bool isRGBW=false); +uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, uint8_t bri=255, bool isRGBW=false); void realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC); void handleNotifications(); void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w); diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 3b093cf0d..2717e3c77 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -552,7 +552,7 @@ void sendSysInfoUDP() uint8_t sequenceNumber = 0; // this needs to be shared across all outputs -uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW) { +uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8_t *buffer, uint8_t bri, bool isRGBW) { if (!interfacesInited) return 1; // network not initialised WiFiUDP ddpUdp; @@ -610,9 +610,9 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8 // write the colors, the write write(const uint8_t *buffer, size_t size) // function is just a loop internally too for (uint16_t i = 0; i < packetSize; i += 3) { - ddpUdp.write(buffer[bufferOffset++]); // R - ddpUdp.write(buffer[bufferOffset++]); // G - ddpUdp.write(buffer[bufferOffset++]); // B + ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R + ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G + ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B if (isRGBW) bufferOffset++; }