feat: Implement and verify WLED configuration retrieval tool

This commit is contained in:
Tobias J. Endres 2025-08-16 00:06:57 +02:00
parent c50aed732e
commit f6dec995f9
3 changed files with 78 additions and 39 deletions

View File

@ -39,7 +39,7 @@ target_link_libraries(Hyperion_Grabber_Wayland_QT
)
add_executable(wled_config_tool
main.cpp
wled_config_tool.cpp
wledconfigclient.cpp
)
@ -59,16 +59,7 @@ target_link_libraries(hyperion-mock
Qt6::Gui
)
add_executable(wled_test
wled_test.cpp
wledclient.cpp
)
target_link_libraries(wled_test
Qt6::Core
Qt6::Network
Qt6::Gui
)
add_executable(screen_capture_test
screen_capture_test.cpp

View File

@ -6,6 +6,8 @@
#include <QJsonDocument>
#include <QJsonObject>
#ifdef WLED_CONFIG_TOOL_BUILD
#include <QCoreApplication>
#include "wledconfigclient.h"
@ -14,6 +16,7 @@
#include "hyperiongrabber.h"
#endif
#ifndef WLED_CONFIG_TOOL_BUILD
static HyperionGrabber *grab;
static QApplication *qapp;
@ -120,7 +123,7 @@ int main(int argc, char *argv[])
delete logFile;
logFile = nullptr;
}
qInstallMessageHandler(customMessageOutput);
qapp = new QApplication(argc, argv);
signal(SIGINT, quit);
@ -143,38 +146,11 @@ int main(int argc, char *argv[])
parser.addOption(QCommandLineOption({"t", "temperature"}, "Adjustment of the LED's color temperature (requires 3 space seperated values between 0 and 255) (ex. \"255,255,250\")", "value"));
parser.addOption(QCommandLineOption({"d", "threshold"}, "Set the threshold of the LED's (requires 3 space seperated values between 0.0 and 1.0) (ex. \"0.0025,0.005,0.01\")", "value"));
parser.addOption(QCommandLineOption({"l", "transform"}, "Adjusts the luminance / saturation of the LED's values are in this order: luminanceGain, luminanceMin, saturationL (requires 3 space seperated values between 0.0 and 1.0) (ex. \"1.0,0.01,1.0\")", "value"));
parser.addOption(QCommandLineOption("flash", "Flash a range of LEDs with a specific color. Usage: --flash <startIndex> <count> <R> <G> <B>", "startIndex count R G B"));
parser.process(*qapp);
#ifndef DEBUG_MODE
if (parser.isSet("flash")) {
QStringList flashArgs = parser.value("flash").split(" ", Qt::SkipEmptyParts);
if (flashArgs.size() == 5) {
int startIndex = flashArgs.at(0).toInt();
int count = flashArgs.at(1).toInt();
int r = flashArgs.at(2).toInt();
int g = flashArgs.at(3).toInt();
int b = flashArgs.at(4).toInt();
// Create a temporary HyperionGrabber to access WledClient
// This is a temporary solution for testing the flash function
// In a real application, you'd want a more robust way to control WledClient
QHash<QString, QString> tempOpts;
// Pass the address and port from command line to tempGrabber
if (parser.isSet("address")) tempOpts.insert("address", parser.value("address"));
if (parser.isSet("port")) tempOpts.insert("port", parser.value("port"));
HyperionGrabber tempGrabber(tempOpts);
tempGrabber._client_p->flashLeds(startIndex, count, QColor(r, g, b));
qDebug() << "Flashing LEDs: startIndex=" << startIndex << ", count=" << count << ", color=" << r << "," << g << "," << b;
return 0; // Exit after flashing
} else {
qWarning() << "Invalid arguments for --flash. Usage: --flash <startIndex> <count> <R> <G> <B>";
return 1;
}
}
#endif
QHash<QString, QString> opts;
for (const auto &optName : parser.optionNames()) {

72
wled_config_tool.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QJsonDocument>
#include <QFile>
#include "wledconfigclient.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("wled_config_tool");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.setApplicationDescription("WLED Configuration Tool");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption addressOption(QStringList() << "a" << "address",
"WLED device IP address or hostname.",
"address");
parser.addOption(addressOption);
QCommandLineOption saveOption(QStringList() << "s" << "save",
"Save configuration to a file.",
"filepath");
parser.addOption(saveOption);
parser.process(app);
if (!parser.isSet(addressOption)) {
qCritical() << "Error: WLED address not specified. Use -a or --address.";
parser.showHelp(1);
}
QString wledAddress = parser.value(addressOption);
QString saveFilePath = parser.value(saveOption);
WledConfigClient client(wledAddress);
QObject::connect(&client, &WledConfigClient::infoReceived, [&](const QJsonObject &info) {
QJsonDocument doc(info);
QFile stdoutFile;
stdoutFile.open(stdout, QFile::WriteOnly);
QTextStream ts(&stdoutFile);
ts << "WLED Configuration Info:\n" << doc.toJson(QJsonDocument::Indented) << Qt::endl;
stdoutFile.close();
QByteArray jsonBytes = doc.toJson(QJsonDocument::Indented); // Keep this for saving to file
if (!saveFilePath.isEmpty()) {
QFile file(saveFilePath);
if (file.open(QIODevice::WriteOnly)) {
file.write(jsonBytes);
file.close();
qDebug() << "Configuration saved to" << saveFilePath;
} else {
qWarning() << "Failed to save configuration to" << saveFilePath << ":" << file.errorString();
}
}
app.quit();
});
QObject::connect(&client, &WledConfigClient::error, [&](const QString &message) {
qCritical() << "Error:" << message;
app.quit();
});
client.getInfo();
return app.exec();
}