mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
webui: initial support for leddevice options (#232)
* initial support for leddevice options * fix schema and editor init * fix led editor labels and schema * add some led schemas * led config: insert current values. not yet perfect, but it works
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
#include <QResource>
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
#include <json/json.h>
|
||||
|
||||
LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry();
|
||||
std::string LedDevice::_activeDevice = "";
|
||||
|
||||
@@ -10,6 +15,7 @@ LedDevice::LedDevice()
|
||||
, _ledBuffer(0)
|
||||
|
||||
{
|
||||
LedDevice::getLedDeviceSchemas();
|
||||
}
|
||||
|
||||
// dummy implemention
|
||||
@@ -32,4 +38,32 @@ const LedDeviceRegistry& LedDevice::getDeviceMap()
|
||||
void LedDevice::setActiveDevice(std::string dev)
|
||||
{
|
||||
_activeDevice = dev;
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value LedDevice::getLedDeviceSchemas()
|
||||
{
|
||||
// make sure the resources are loaded (they may be left out after static linking)
|
||||
Q_INIT_RESOURCE(LedDeviceSchemas);
|
||||
|
||||
// read the json schema from the resource
|
||||
QDir d(":/leddevices/");
|
||||
QStringList l = d.entryList();
|
||||
Json::Value result;
|
||||
for(QString &item : l)
|
||||
{
|
||||
QResource schemaData(QString(":/leddevices/")+item);
|
||||
std::string devName = item.remove("schema-").toStdString();
|
||||
Json::Value & schemaJson = result[devName];
|
||||
|
||||
Json::Reader jsonReader;
|
||||
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
||||
{
|
||||
Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", item.toUtf8().constData(), jsonReader.getFormattedErrorMessages().c_str() );
|
||||
throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ;
|
||||
}
|
||||
schemaJson["title"] = "LED Device Specific";
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user