Skip to content

Commit caa9cc3

Browse files
committed
Removed double buffer.
Moved bri scaling into UDP function. Prevent double DDP port allocation.
1 parent 330da13 commit caa9cc3

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

wled00/bus_manager.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ class BusNetwork : public Bus {
393393
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
394394
_broadcastLock = false;
395395
_valid = true;
396-
_data2 = (byte *)malloc(_len * _UDPchannels);
397396
};
398397

399398
void setPixelColor(uint16_t pix, uint32_t c) {
@@ -419,20 +418,7 @@ class BusNetwork : public Bus {
419418
void show() {
420419
if (!_valid || !canShow()) return;
421420
_broadcastLock = true;
422-
// apply brightness to second buffer
423-
if (_data2 == nullptr) {
424-
// but display original buffer if memory allocation failed
425-
realtimeBroadcast(_UDPtype, _client, _len, _data, _rgbw);
426-
} else {
427-
for (uint16_t pix=0; pix<_len; pix++) {
428-
uint16_t offset = pix * _UDPchannels;
429-
_data2[offset ] = scale8(_data[offset ], _bri);
430-
_data2[offset+1] = scale8(_data[offset+1], _bri);
431-
_data2[offset+2] = scale8(_data[offset+2], _bri);
432-
if (_rgbw) _data2[offset+3] = scale8(_data[offset+3], _bri);
433-
}
434-
realtimeBroadcast(_UDPtype, _client, _len, _data2, _rgbw);
435-
}
421+
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
436422
_broadcastLock = false;
437423
}
438424

@@ -465,8 +451,6 @@ class BusNetwork : public Bus {
465451
_valid = false;
466452
if (_data != nullptr) free(_data);
467453
_data = nullptr;
468-
if (_data2 != nullptr) free(_data2);
469-
_data2 = nullptr;
470454
}
471455

472456
~BusNetwork() {
@@ -482,7 +466,7 @@ class BusNetwork : public Bus {
482466
uint8_t _UDPchannels;
483467
bool _rgbw;
484468
bool _broadcastLock;
485-
byte *_data, *_data2;
469+
byte *_data;
486470
};
487471

488472

wled00/cfg.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
263263
JsonObject if_live = interfaces["live"];
264264
CJSON(receiveDirect, if_live["en"]);
265265
CJSON(e131Port, if_live["port"]); // 5568
266+
if (e131Port == DDP_DEFAULT_PORT) e131Port = E131_DEFAULT_PORT; // prevent double DDP port allocation
266267
CJSON(e131Multicast, if_live[F("mc")]);
267268

268269
JsonObject if_live_dmx = if_live[F("dmx")];

wled00/fcn_declare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte
195195

196196
//udp.cpp
197197
void notify(byte callMode, bool followUp=false);
198-
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, bool isRGBW=false);
198+
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, uint8_t bri=255, bool isRGBW=false);
199199
void realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC);
200200
void handleNotifications();
201201
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);

wled00/udp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void sendSysInfoUDP()
552552

553553
uint8_t sequenceNumber = 0; // this needs to be shared across all outputs
554554

555-
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW) {
555+
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8_t *buffer, uint8_t bri, bool isRGBW) {
556556
if (!interfacesInited) return 1; // network not initialised
557557

558558
WiFiUDP ddpUdp;
@@ -610,9 +610,9 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8
610610
// write the colors, the write write(const uint8_t *buffer, size_t size)
611611
// function is just a loop internally too
612612
for (uint16_t i = 0; i < packetSize; i += 3) {
613-
ddpUdp.write(buffer[bufferOffset++]); // R
614-
ddpUdp.write(buffer[bufferOffset++]); // G
615-
ddpUdp.write(buffer[bufferOffset++]); // B
613+
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R
614+
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
615+
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B
616616
if (isRGBW) bufferOffset++;
617617
}
618618

0 commit comments

Comments
 (0)