Skip to content

Commit

Permalink
Revert "Merge branch 'W5500+Art-Net_Improvements' into W5500_Support"
Browse files Browse the repository at this point in the history
This reverts commit b7acc6a, reversing
changes made to f51290c.
  • Loading branch information
troyhacks committed Apr 19, 2024
1 parent b7acc6a commit df2d327
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 139 deletions.
61 changes: 8 additions & 53 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ uint8_t BusOnOff::getPins(uint8_t* pinArray) {
return 1;
}

BusNetwork::BusNetwork(BusConfig &bc, const ColorOrderMap &com) : Bus(bc.type, bc.start, bc.autoWhite), _colorOrderMap(com) {

BusNetwork::BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
_valid = false;
switch (bc.type) {
case TYPE_NET_ARTNET_RGB:
Expand Down Expand Up @@ -424,62 +425,16 @@ void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
if (hasWhite()) c = autoWhiteCalc(c);
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
uint16_t offset = pix * _UDPchannels;
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
if (_colorOrder != co) {
if (co == COL_ORDER_GRB) {
_data[offset] = G(c);
_data[offset+1] = R(c);
_data[offset+2] = B(c);
} else if (co == COL_ORDER_RGB) {
_data[offset] = R(c);
_data[offset+1] = G(c);
_data[offset+2] = B(c);
} else if (co == COL_ORDER_BRG) {
_data[offset] = B(c);
_data[offset+1] = R(c);
_data[offset+2] = G(c);
} else if (co == COL_ORDER_RBG) {
_data[offset] = R(c);
_data[offset+1] = B(c);
_data[offset+2] = G(c);
} else if (co == COL_ORDER_GBR) {
_data[offset] = G(c);
_data[offset+1] = B(c);
_data[offset+2] = R(c);
} else if (co == COL_ORDER_BGR) {
_data[offset] = B(c);
_data[offset+1] = G(c);
_data[offset+2] = R(c);
}
if (_rgbw) _data[offset+3] = W(c);
} else {
_data[offset] = R(c);
_data[offset+1] = G(c);
_data[offset+2] = B(c);
if (_rgbw) _data[offset+3] = W(c);
}
_data[offset] = R(c);
_data[offset+1] = G(c);
_data[offset+2] = B(c);
if (_rgbw) _data[offset+3] = W(c);
}

uint32_t BusNetwork::getPixelColor(uint16_t pix) {
if (!_valid || pix >= _len) return 0;
uint16_t offset = pix * _UDPchannels;
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
if (_colorOrder != co) {
if (co == COL_ORDER_GRB) {
return RGBW32(_data[offset+1], _data[offset+0], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
} else if (co == COL_ORDER_RGB) {
return RGBW32(_data[offset+0], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
} else if (co == COL_ORDER_BRG) {
return RGBW32(_data[offset+2], _data[offset+0], _data[offset+1], _rgbw ? (_data[offset+3] << 24) : 0);
} else if (co == COL_ORDER_RBG) {
return RGBW32(_data[offset+0], _data[offset+2], _data[offset+1], _rgbw ? (_data[offset+3] << 24) : 0);
} else if (co == COL_ORDER_GBR) {
return RGBW32(_data[offset+1], _data[offset+2], _data[offset+0], _rgbw ? (_data[offset+3] << 24) : 0);
} else if (co == COL_ORDER_BGR) {
return RGBW32(_data[offset+2], _data[offset+1], _data[offset+0], _rgbw ? (_data[offset+3] << 24) : 0);
}
}
return RGBW32(_data[offset+0], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
return RGBW32(_data[offset], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
}

void BusNetwork::show() {
Expand Down Expand Up @@ -756,7 +711,7 @@ int BusManager::add(BusConfig &bc) {
if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
USER_PRINTF("BusManager::add(bc.type=%u)\n", bc.type);
if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) {
busses[numBusses] = new BusNetwork(bc,colorOrderMap);
busses[numBusses] = new BusNetwork(bc);
#ifdef WLED_ENABLE_HUB75MATRIX
} else if (bc.type >= TYPE_HUB75MATRIX && bc.type <= (TYPE_HUB75MATRIX + 10)) {
USER_PRINTLN("BusManager::add - Adding BusHub75Matrix");
Expand Down
8 changes: 1 addition & 7 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class BusOnOff : public Bus {

class BusNetwork : public Bus {
public:
BusNetwork(BusConfig &bc, const ColorOrderMap &com);
BusNetwork(BusConfig &bc);

uint16_t getMaxPixels() override { return 4096; };
bool hasRGB() { return true; }
Expand All @@ -318,10 +318,6 @@ class BusNetwork : public Bus {
return _len;
}

uint8_t getColorOrder() {
return _colorOrder;
}

void cleanup();

~BusNetwork() {
Expand All @@ -335,8 +331,6 @@ class BusNetwork : public Bus {
bool _rgbw;
bool _broadcastLock;
byte *_data;
uint8_t _colorOrder = COL_ORDER_RGB;
const ColorOrderMap &_colorOrderMap;
};

#ifdef WLED_ENABLE_HUB75MATRIX
Expand Down
1 change: 1 addition & 0 deletions wled00/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void WiFiEvent(WiFiEvent_t event) {
DEBUG_PRINTLN(F("WiFi Connected. No ETH"));
}
break;

#ifdef WLED_USE_ETHERNET
case ARDUINO_EVENT_ETH_GOT_IP:
if (!apActive) {
Expand Down
117 changes: 38 additions & 79 deletions wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,6 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8
switch (type) {
case 0: // DDP
{
#if defined WLED_USE_ETHERNET && !defined ESP8266
ddpUdp.begin(Network.localIP(),DDP_DEFAULT_PORT); // in case we have Ethernet on ESP32, this forces that source IP/routing.
#endif

// calculate the number of UDP packets we need to send
size_t channelCount = length * (isRGBW? 4:3); // 1 channel for every R,G,B value
size_t packetCount = ((channelCount-1) / DDP_CHANNELS_PER_PACKET) +1;
Expand Down Expand Up @@ -842,95 +838,58 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8

case 2: //ArtNet
{
#if defined WLED_USE_ETHERNET && !defined ESP8266
ddpUdp.begin(Network.localIP(),ARTNET_DEFAULT_PORT); // in case we have Ethernet on ESP32, this forces that source IP/routing.
#endif
/*
We don't really care about the number of universes - just how many hardware outputs we have.
WLED rendering Art-Net data considers itself to be 1 hardware output with many universes - but
many Art-Net controllers like the H807SA can be manually set to "X universes per output."
We need to know the channels per output so we can break the pixel data across physically attached universes.
The H807SA obeys the "510 channels for RGB" rule like WLED and xLights - some other controllers do not care,
but we're not supporting those here. If you run into one of these, override ARTNET_CHANNELS_PER_PACKET to 512.
We're expecting equal numbers of channels per output, common for controllers like the H807SA - at some point
we could consider an Art-Net mapping system to adjust universe starts for weird wiring situations.
*/
// calculate the number of UDP packets we need to send
const size_t channelCount = length * (isRGBW?4:3); // 1 channel for every R,G,B,(W?) value
const size_t ARTNET_CHANNELS_PER_PACKET = isRGBW?512:510; // 512/4=128 RGBW LEDs, 510/3=170 RGB LEDs
const size_t packetCount = ((channelCount-1)/ARTNET_CHANNELS_PER_PACKET)+1;

// Default WLED-to-WLED Art-Net output
//
// const size_t hardware_outputs[1] = { length }; // specified in LED counts. "length" = all LEDs
// const size_t hardware_outputs_universe_start[1] = { 0 }; // universe start # per output

// Example of more than 1 output, currently you can only hard-code this kind of setup here.
// You get 170 RGB LEDs per universe (128 RGBW) so the receiving hardware needs to be configured correctly.
// The H807SA, for example, only allows one global setting of Art-Net universes-per-output.
//
const size_t hardware_outputs[4] = { 256,256,256,256 }; // specified in LED counts
const size_t hardware_outputs_universe_start[4] = { 0,2,4,6 }; // universe start # per output

uint32_t channel = 0;
size_t bufferOffset = 0;
size_t hardware_output_universe = 0;

sequenceNumber++;

if (sequenceNumber == 0) sequenceNumber = 1; // just in case, as 0 is considered "Sequence not in use"
if (sequenceNumber > 255) sequenceNumber = 1;
sequenceNumber++;

for (size_t hardware_output = 0; hardware_output < sizeof(hardware_outputs)/sizeof(size_t); hardware_output++) {

if (bufferOffset > length * (isRGBW?4:3)) return 1; // stop when we hit end of LEDs
for (size_t currentPacket = 0; currentPacket < packetCount; currentPacket++) {

hardware_output_universe = hardware_outputs_universe_start[hardware_output];
if (sequenceNumber > 255) sequenceNumber = 0;

size_t channels_remaining = hardware_outputs[hardware_output] * (isRGBW?4:3);
if (!ddpUdp.beginPacket(client, ARTNET_DEFAULT_PORT)) {
DEBUG_PRINTLN(F("Art-Net WiFiUDP.beginPacket returned an error"));
return 1; // borked
}

while (channels_remaining > 0) {
size_t packetSize = ARTNET_CHANNELS_PER_PACKET;

if (!ddpUdp.beginPacket(client, ARTNET_DEFAULT_PORT)) {
DEBUG_PRINTLN(F("Art-Net WiFiUDP.beginPacket returned an error"));
return 1; // borked
if (currentPacket == (packetCount - 1U)) {
// last packet
if (channelCount % ARTNET_CHANNELS_PER_PACKET) {
packetSize = channelCount % ARTNET_CHANNELS_PER_PACKET;
}
}

size_t packetSize = ARTNET_CHANNELS_PER_PACKET;

if (channels_remaining < ARTNET_CHANNELS_PER_PACKET) {
packetSize = channels_remaining;
channels_remaining = 0;
} else {
channels_remaining -= packetSize;
}
byte header_buffer[ART_NET_HEADER_SIZE];
memcpy_P(header_buffer, ART_NET_HEADER, ART_NET_HEADER_SIZE);
ddpUdp.write(header_buffer, ART_NET_HEADER_SIZE); // This doesn't change. Hard coded ID, OpCode, and protocol version.
ddpUdp.write(sequenceNumber & 0xFF); // sequence number. 1..255
ddpUdp.write(0x00); // physical - more an FYI, not really used for anything. 0..3
ddpUdp.write((currentPacket) & 0xFF); // Universe LSB. 1 full packet == 1 full universe, so just use current packet number.
ddpUdp.write(0x00); // Universe MSB, unused.
ddpUdp.write(0xFF & (packetSize >> 8)); // 16-bit length of channel data, MSB
ddpUdp.write(0xFF & (packetSize )); // 16-bit length of channel data, LSB

byte header_buffer[ART_NET_HEADER_SIZE];
memcpy_P(header_buffer, ART_NET_HEADER, ART_NET_HEADER_SIZE);
ddpUdp.write(header_buffer, ART_NET_HEADER_SIZE); // This doesn't change. Hard coded ID, OpCode, and protocol version.
ddpUdp.write(sequenceNumber & 0xFF); // sequence number. 1..255
ddpUdp.write(0x00); // physical - more an FYI, not really used for anything. 0..3
ddpUdp.write(hardware_output_universe & 0xFF); // Universe LSB. 1 full packet == 1 full universe.
ddpUdp.write(0x00); // Universe MSB, unused.
ddpUdp.write(0xFF & (packetSize >> 8)); // 16-bit length of channel data, MSB
ddpUdp.write(0xFF & (packetSize )); // 16-bit length of channel data, LSB

for (size_t i = 0; i < packetSize; i += (isRGBW?4:3)) {
// "Color Order Override" works on top of this if you need to change the color order before sending.
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B
if (isRGBW) ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // W
}
for (size_t i = 0; i < packetSize; i += (isRGBW?4:3)) {
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B
if (isRGBW) ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // W
}

if (!ddpUdp.endPacket()) {
DEBUG_PRINTLN(F("Art-Net WiFiUDP.endPacket returned an error"));
return 1; // borked
}
hardware_output_universe++;
if (!ddpUdp.endPacket()) {
DEBUG_PRINTLN(F("Art-Net WiFiUDP.endPacket returned an error"));
return 1; // borked
}
} break;
}
channel += packetSize;
}
} break;
}
return 0;
}

0 comments on commit df2d327

Please sign in to comment.