fix spelling error, be smarter how we write data to udp
This commit is contained in:
parent
ea69957ed1
commit
cc661b26fa
@ -386,7 +386,7 @@ class BusVirtual : public Bus {
|
|||||||
void show() {
|
void show() {
|
||||||
if (!_valid || _broadcastLock) return;
|
if (!_valid || _broadcastLock) return;
|
||||||
_broadcastLock = true;
|
_broadcastLock = true;
|
||||||
realtimeBoroadcast(_client, _len, _data, _rgbw);
|
realtimeBroadcast(_client, _len, _data, _rgbw);
|
||||||
_broadcastLock = false;
|
_broadcastLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
void realtimeBoroadcast(IPAddress client, uint16_t length, byte *buffer, bool isRGBW);
|
uint8_t realtimeBroadcast(IPAddress client, uint16_t length, byte *buffer, bool isRGBW);
|
||||||
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);
|
||||||
|
@ -90,13 +90,6 @@ void notify(byte callMode, bool followUp)
|
|||||||
notificationTwoRequired = (followUp)? false:notifyTwice;
|
notificationTwoRequired = (followUp)? false:notifyTwice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void realtimeBoroadcast(IPAddress client, uint16_t length, byte *buffer, bool isRGBW)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void realtimeLock(uint32_t timeoutMs, byte md)
|
void realtimeLock(uint32_t timeoutMs, byte md)
|
||||||
{
|
{
|
||||||
if (!realtimeMode && !realtimeOverride){
|
if (!realtimeMode && !realtimeOverride){
|
||||||
@ -546,24 +539,29 @@ void sendSysInfoUDP()
|
|||||||
// 1440 channels per packet
|
// 1440 channels per packet
|
||||||
#define DDP_CHANNELS_PER_PACKET 1440 // 480 leds
|
#define DDP_CHANNELS_PER_PACKET 1440 // 480 leds
|
||||||
|
|
||||||
//
|
|
||||||
// copies a 4 byte rgbw buffer to a 3 byte rgb buffer (skipping the w channel)
|
|
||||||
//
|
|
||||||
// Parameters:
|
|
||||||
// destination - the buffer to write to must be able to hold length*3 bytes
|
|
||||||
// source - the buffer to read from
|
|
||||||
// length - the number of 4 byte channels in the source buffer
|
|
||||||
// Returns:
|
|
||||||
// the pointer in the source where we have copied up to
|
|
||||||
//
|
|
||||||
uint8_t* copyRgbwToRgb(uint8_t *destination, uint8_t *source, uint16_t length) {
|
|
||||||
|
|
||||||
|
uint8_t *writeRgbwTo(WiFiUDP ddpUdp, uint8_t *source, uint16_t length) {
|
||||||
|
// Note: WiFiUDP.write(buffer, size) is just a wrapper around WiFiUDP.write(byte)
|
||||||
|
// No benefit to copy to another buffer
|
||||||
while (length--)
|
while (length--)
|
||||||
{
|
{
|
||||||
*(destination++) = *(source++); // R
|
ddpUdp.write(*(source++)); // R
|
||||||
*(destination++) = *(source++); // G
|
ddpUdp.write(*(source++)); // G
|
||||||
*(destination++) = *(source++); // B
|
ddpUdp.write(*(source++)); // B
|
||||||
source++; // W
|
source++; // W
|
||||||
|
}
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *writeRgbTo(WiFiUDP ddpUdp, uint8_t *source, uint16_t length) {
|
||||||
|
// Note: WiFiUDP.write(buffer, size) is just a wrapper around WiFiUDP.write(byte)
|
||||||
|
// No benefit to copy to another buffer
|
||||||
|
while (length--)
|
||||||
|
{
|
||||||
|
ddpUdp.write(*(source++)); // R
|
||||||
|
ddpUdp.write(*(source++)); // G
|
||||||
|
ddpUdp.write(*(source++)); // B
|
||||||
}
|
}
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@ -577,7 +575,12 @@ uint8_t* copyRgbwToRgb(uint8_t *destination, uint8_t *source, uint16_t length) {
|
|||||||
// buffer - a buffer of at least length*4 bytes long
|
// buffer - a buffer of at least length*4 bytes long
|
||||||
// isRGBW - true if the buffer contains 4 components per pixel
|
// isRGBW - true if the buffer contains 4 components per pixel
|
||||||
//
|
//
|
||||||
void realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW) {
|
uint8_t realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW) {
|
||||||
|
|
||||||
|
// function to write the bytes into WiFiUDP
|
||||||
|
uint8_t *(*writeTo)(WiFiUDP, uint8_t *, uint16_t) = isRGBW
|
||||||
|
? &writeRgbwTo
|
||||||
|
: &writeRgbTo;
|
||||||
|
|
||||||
WiFiUDP ddpUdp;
|
WiFiUDP ddpUdp;
|
||||||
|
|
||||||
@ -589,7 +592,7 @@ void realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allocatea buffer on the stack for the UDP packet
|
// allocatea buffer on the stack for the UDP packet
|
||||||
uint8_t packet[DDP_HEADER_LEN + DDP_CHANNELS_PER_PACKET] = { 0 };
|
uint8_t packet[DDP_HEADER_LEN] = { 0 };
|
||||||
|
|
||||||
// set common header values
|
// set common header values
|
||||||
packet[0] = DDP_FLAGS1_VER1;
|
packet[0] = DDP_FLAGS1_VER1;
|
||||||
@ -624,21 +627,21 @@ void realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool
|
|||||||
packet[8] = (packetSize & 0xFF00) >> 8;
|
packet[8] = (packetSize & 0xFF00) >> 8;
|
||||||
packet[9] = packetSize & 0xFF;
|
packet[9] = packetSize & 0xFF;
|
||||||
|
|
||||||
if (isRGBW) {
|
int rc = ddpUdp.beginPacket(client, DDP_PORT);
|
||||||
// copy the data from the source buffer into our packet
|
if (rc == 0) {
|
||||||
buffer = copyRgbwToRgb(&packet[DDP_HEADER_LEN], buffer, packetSize);
|
return 1; // problem
|
||||||
ddpUdp.beginPacket(client, DDP_PORT);
|
}
|
||||||
ddpUdp.write(packet, DDP_HEADER_LEN + packetSize);
|
// write the header
|
||||||
ddpUdp.endPacket();
|
ddpUdp.write(packet, DDP_HEADER_LEN + packetSize);
|
||||||
} else {
|
// write the colors, and adjust buffer to point at end of data written
|
||||||
// write the rgb values directly from the user supplied buffer
|
buffer = (*writeTo)(ddpUdp, buffer, packetSize);
|
||||||
ddpUdp.beginPacket(client, DDP_PORT);
|
rc = ddpUdp.endPacket();
|
||||||
ddpUdp.write(packet, DDP_HEADER_LEN);
|
if (rc == 0) {
|
||||||
ddpUdp.write(buffer, packetSize);
|
return 1; // problem
|
||||||
ddpUdp.endPacket();
|
|
||||||
buffer += packetSize; // advance the buffer over the written bytes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel += packetSize;
|
channel += packetSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ void sendSysInfoUDP();
|
|||||||
// buffer - a buffer of at least length*3 or length*4 bytes long
|
// buffer - a buffer of at least length*3 or length*4 bytes long
|
||||||
// length - the number of pixels
|
// length - the number of pixels
|
||||||
// isRGBW - true if the buffer contains 4 components per pixel
|
// isRGBW - true if the buffer contains 4 components per pixel
|
||||||
void realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW);
|
uint8_t realtimeBroadcast(IPAddress client, uint16_t length, uint8_t *buffer, bool isRGBW);
|
||||||
|
|
||||||
#define DDP_PORT 4048
|
#define DDP_PORT 4048
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user