mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 08:46:34 +00:00
Network bus changes:
- moved brightness scaling to broadcast fn - removed double buffer - fixed getPixelColor()
This commit is contained in:
parent
5149078f6a
commit
aef53a8753
@ -43,7 +43,7 @@ struct BusConfig {
|
|||||||
type = busType & 0x7F; // bit 7 may be/is hacked to include RGBW info (1=RGBW, 0=RGB)
|
type = busType & 0x7F; // bit 7 may be/is hacked to include RGBW info (1=RGBW, 0=RGB)
|
||||||
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip;
|
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip;
|
||||||
uint8_t nPins = 1;
|
uint8_t nPins = 1;
|
||||||
if (type >= 10 || type <= 15) nPins = 4;
|
if (type >= 10 && type <= 15) nPins = 4; // IP address stored in pins
|
||||||
else if (type > 47) nPins = 2;
|
else if (type > 47) nPins = 2;
|
||||||
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
|
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
|
||||||
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
||||||
@ -401,7 +401,6 @@ class BusNetwork : public Bus {
|
|||||||
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
|
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
|
||||||
_broadcastLock = false;
|
_broadcastLock = false;
|
||||||
_valid = true;
|
_valid = true;
|
||||||
_data2 = (byte *)malloc(_len * _UDPchannels);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c) {
|
void setPixelColor(uint16_t pix, uint32_t c) {
|
||||||
@ -416,32 +415,18 @@ class BusNetwork : public Bus {
|
|||||||
uint32_t getPixelColor(uint16_t pix) {
|
uint32_t getPixelColor(uint16_t pix) {
|
||||||
if (!_valid || pix >= _len) return 0;
|
if (!_valid || pix >= _len) return 0;
|
||||||
uint16_t offset = pix * _UDPchannels;
|
uint16_t offset = pix * _UDPchannels;
|
||||||
// behave as NeoPixelBus
|
|
||||||
return (
|
return (
|
||||||
(_rgbw ? (scale8(_data[offset+3], _bri) << 24) : 0)
|
(_rgbw ? (_data[offset+3] << 24) : 0)
|
||||||
| (scale8(_data[offset] , _bri) << 16)
|
| (_data[offset] << 16)
|
||||||
| (scale8(_data[offset+1], _bri) << 8)
|
| (_data[offset+1] << 8)
|
||||||
| (scale8(_data[offset+2], _bri) )
|
| (_data[offset+2] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show() {
|
void show() {
|
||||||
if (!_valid || !canShow()) return;
|
if (!_valid || !canShow()) return;
|
||||||
_broadcastLock = true;
|
_broadcastLock = true;
|
||||||
// apply brightness to second buffer
|
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
|
||||||
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);
|
|
||||||
}
|
|
||||||
_broadcastLock = false;
|
_broadcastLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,8 +459,6 @@ class BusNetwork : public Bus {
|
|||||||
_valid = false;
|
_valid = false;
|
||||||
if (_data != nullptr) free(_data);
|
if (_data != nullptr) free(_data);
|
||||||
_data = nullptr;
|
_data = nullptr;
|
||||||
if (_data2 != nullptr) free(_data2);
|
|
||||||
_data2 = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~BusNetwork() {
|
~BusNetwork() {
|
||||||
@ -491,7 +474,7 @@ class BusNetwork : public Bus {
|
|||||||
uint8_t _UDPchannels;
|
uint8_t _UDPchannels;
|
||||||
bool _rgbw;
|
bool _rgbw;
|
||||||
bool _broadcastLock;
|
bool _broadcastLock;
|
||||||
byte *_data, *_data2;
|
byte *_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,6 @@
|
|||||||
}
|
}
|
||||||
//returns mem usage
|
//returns mem usage
|
||||||
function getMem(t, len, p0) {
|
function getMem(t, len, p0) {
|
||||||
if (t >= 10 && t <= 12) return len*6; // double buffer for network UDP bus
|
|
||||||
if (t > 15 && t < 32) {
|
if (t > 15 && t < 32) {
|
||||||
if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem
|
if (maxM < 10000 && p0==3) { //8266 DMA uses 5x the mem
|
||||||
if (t > 29) return len*20; //RGBW
|
if (t > 29) return len*20; //RGBW
|
||||||
|
@ -197,7 +197,7 @@ bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte
|
|||||||
|
|
||||||
//udp.cpp
|
//udp.cpp
|
||||||
void notify(byte callMode, bool followUp=false);
|
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 realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC);
|
||||||
void handleNotifications();
|
void handleNotifications();
|
||||||
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);
|
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);
|
||||||
|
File diff suppressed because one or more lines are too long
@ -552,7 +552,7 @@ void sendSysInfoUDP()
|
|||||||
|
|
||||||
uint8_t sequenceNumber = 0; // this needs to be shared across all outputs
|
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
|
if (!interfacesInited) return 1; // network not initialised
|
||||||
|
|
||||||
WiFiUDP ddpUdp;
|
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)
|
// write the colors, the write write(const uint8_t *buffer, size_t size)
|
||||||
// function is just a loop internally too
|
// function is just a loop internally too
|
||||||
for (uint16_t i = 0; i < packetSize; i += 3) {
|
for (uint16_t i = 0; i < packetSize; i += 3) {
|
||||||
ddpUdp.write(buffer[bufferOffset++]); // R
|
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R
|
||||||
ddpUdp.write(buffer[bufferOffset++]); // G
|
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
|
||||||
ddpUdp.write(buffer[bufferOffset++]); // B
|
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B
|
||||||
if (isRGBW) bufferOffset++;
|
if (isRGBW) bufferOffset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user