feat: Implement configurable color order for WLED

This commit is contained in:
Tobias J. Endres 2025-08-16 15:06:44 +02:00
parent 68333f855b
commit 98212e4f46
3 changed files with 24 additions and 12 deletions

View File

@ -28,6 +28,8 @@ To run the grabber, set the following environment variables and then execute the
export HYPERION_GRABBER_WLED_ADDRESS="<YOUR_WLED_IP_ADDRESS>"
# UDP port of your WLED device for Realtime data (default: 21324)
export HYPERION_GRABBER_WLED_PORT="21324"
# Color order of your WLED device (e.g., RGB, GRB, BGR) (default: GRB)
export HYPERION_GRABBER_WLED_COLOR_ORDER="GRB"
# --- Grabber Settings ---
# Divisor used to scale your screen resolution (e.g., 8)

View File

@ -28,6 +28,23 @@ WledClient::~WledClient()
qDebug() << "WledClient destroyed.";
}
void WledClient::appendColor(QByteArray &datagram, const QColor &color)
{
if (_colorOrder == "GRB") {
datagram.append(color.green());
datagram.append(color.red());
datagram.append(color.blue());
} else if (_colorOrder == "BGR") {
datagram.append(color.blue());
datagram.append(color.green());
datagram.append(color.red());
} else { // Default to RGB
datagram.append(color.red());
datagram.append(color.green());
datagram.append(color.blue());
}
}
void WledClient::sendImage(const QImage &image)
{
if (image.isNull()) {
@ -67,10 +84,7 @@ void WledClient::sendImage(const QImage &image)
int y = pixelIndex / rgbImage.width();
QRgb pixel = rgbImage.pixel(x, y);
// Swap R and G for GRB order
datagram.append(qRed(pixel));
datagram.append(qGreen(pixel));
datagram.append(qBlue(pixel));
appendColor(datagram, QColor(pixel));
}
qint64 bytesSent = _udpSocket->writeDatagram(datagram, _wledHost, _wledPort);
@ -114,10 +128,7 @@ void WledClient::setLedsColor(const QVector<QColor> &colors, int timeout)
for (int j = 0; j < currentLedsInPacket; ++j) {
const QColor &color = colors.at(i + j);
// Swap R and G for GRB order
datagram.append(color.red());
datagram.append(color.green());
datagram.append(color.blue());
appendColor(datagram, color);
}
qint64 bytesSent = _udpSocket->writeDatagram(datagram, _wledHost, _wledPort);
@ -159,10 +170,7 @@ void WledClient::flashLeds(int startIndex, int count, QColor color)
int currentLedsInPacket = qMin(ledsPerPacket, count - i);
for (int j = 0; j < currentLedsInPacket; ++j) {
// Swap R and G for GRB order
datagram.append(color.red());
datagram.append(color.green());
datagram.append(color.blue());
appendColor(datagram, color);
}
qDebug() << "WledClient: Sending flashLeds datagram (hex):" << datagram.toHex();

View File

@ -19,6 +19,8 @@ public:
void flashLeds(int startIndex, int count, QColor color);
private:
void appendColor(QByteArray &datagram, const QColor &color);
QUdpSocket *_udpSocket;
QHostAddress _wledHost;
ushort _wledPort;