From 817dabae8c6817debc22659f6da291fcbfcdfeda Mon Sep 17 00:00:00 2001 From: redPanther Date: Sat, 6 Aug 2016 08:28:42 +0200 Subject: [PATCH] sourceOff feature + small json refactoring (#151) * add --sourceOff to hyperion-remote - this will select "off" source and set all leds to black refactor new json stuff make schema checker not so strict, do not require values that have defaults (not finished yet) initialEffect config: effect is always an array, regardless if it is a color or an effect name * make off source visible in active priority list * transform initialeffect to qjson (except part of effect-args, this needs effectengine transformed to qjson) * remove unneeded comment * add web ui for source selection. call http://hyperion_host:8099/select/index.html current example needed json server on port 19444 --- assets/webconfig/select/index.html | 98 +++++++++++ assets/webconfig/select/starter-template.css | 8 + config/hyperion.config.json.commented | 8 +- config/hyperion.config.json.default | 4 +- include/hyperion/PriorityMuxer.h | 5 +- libsrc/hyperion/Hyperion.cpp | 9 +- libsrc/hyperion/PriorityMuxer.cpp | 23 +-- libsrc/hyperion/hyperion.schema.json | 172 +++++++++---------- libsrc/jsonserver/JsonClientConnection.cpp | 3 +- src/hyperion-remote/hyperion-remote.cpp | 8 +- src/hyperiond/hyperiond.cpp | 102 +++++------ src/hyperiond/hyperiond.h | 3 +- src/hyperiond/main.cpp | 3 +- 13 files changed, 269 insertions(+), 177 deletions(-) create mode 100644 assets/webconfig/select/index.html create mode 100644 assets/webconfig/select/starter-template.css diff --git a/assets/webconfig/select/index.html b/assets/webconfig/select/index.html new file mode 100644 index 00000000..82924b24 --- /dev/null +++ b/assets/webconfig/select/index.html @@ -0,0 +1,98 @@ + + + + + + + + Hyperion web control + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + + + + diff --git a/assets/webconfig/select/starter-template.css b/assets/webconfig/select/starter-template.css new file mode 100644 index 00000000..e83f68ad --- /dev/null +++ b/assets/webconfig/select/starter-template.css @@ -0,0 +1,8 @@ +body { + padding-top: 50px; +} +.starter-template { + padding: 40px 15px; + text-align: center; +} + diff --git a/config/hyperion.config.json.commented b/config/hyperion.config.json.commented index 52816c88..3b689754 100644 --- a/config/hyperion.config.json.commented +++ b/config/hyperion.config.json.commented @@ -268,18 +268,18 @@ }, /// Initial Effect sets a "booteffect" or "color" (foreground-effect) and optional set a "effect" or "color" during inactive grabbers and network receivers (background-effect) - /// * background-effect : 2 options: set a effect (example: "Rainbow swirl fast") or set a color (RGB) (example: [255,134,0]) + /// * background-effect : 2 options: set a effect (example: ["Rainbow swirl fast"]) or set a color (RGB) (example: [255,134,0]) /// * background-effect-args : Set optional effect arguments (Have a look at the select effect to get the possible values), define it only when needed - /// * foreground-effect : 2 options: set a effect (example: "Rainbow swirl fast") or set a color (RGB) (example: [255,134,0]) + /// * foreground-effect : 2 options: set a effect (example: ["Rainbow swirl fast"]) or set a color (RGB) (example: [255,134,0]) /// * foreground-effect-args : Set optional effect arguments (Have a look at the select effect to get the possible values), define it only when needed /// * foreground-duration_ms : The duration of the selected foreground-effect or color (0=endless) /// HINT: "foreground-effect" starts always with priority 0, so it blocks all remotes and grabbers if the loop is endless /// HINT: Set a empty value if you want to disable a component (example: "") "initialEffect" : { - "background-effect" : "Full color mood blobs", + "background-effect" : ["Full color mood blobs"], //"background-effect-args" : {}, - "foreground-effect" : "Rainbow swirl fast", + "foreground-effect" : ["Rainbow swirl fast"], //"foreground-effect-args" : {}, "foreground-duration_ms" : 3000 }, diff --git a/config/hyperion.config.json.default b/config/hyperion.config.json.default index 9e791019..23fd3638 100644 --- a/config/hyperion.config.json.default +++ b/config/hyperion.config.json.default @@ -150,8 +150,8 @@ "initialEffect" : { - "background-effect" : "Full color mood blobs", - "foreground-effect" : "Rainbow swirl fast", + "background-effect" : ["Full color mood blobs"], + "foreground-effect" : ["Rainbow swirl fast"], "foreground-duration_ms" : 3000 }, diff --git a/include/hyperion/PriorityMuxer.h b/include/hyperion/PriorityMuxer.h index 79342c5f..f5295e0c 100644 --- a/include/hyperion/PriorityMuxer.h +++ b/include/hyperion/PriorityMuxer.h @@ -34,6 +34,9 @@ public: std::vector ledColors; }; + /// The lowest possible priority, which is used when no priority channels are active + const static int LOWEST_PRIORITY = std::numeric_limits::max(); + /// /// Constructs the PriorityMuxer for the given number of leds (used to switch to black when /// there are no priority channels @@ -118,6 +121,4 @@ private: /// The information of the lowest priority channel InputInfo _lowestPriorityInfo; - /// The lowest possible priority, which is used when no priority channels are active - const static int LOWEST_PRIORITY = std::numeric_limits::max(); }; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index df5b7936..f35bb27b 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -557,6 +557,8 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) , _hwLedCount(_ledString.leds().size()) , _sourceAutoSelectEnabled(true) { + registerPriority("Off", PriorityMuxer::LOWEST_PRIORITY); + if (!_raw2ledAdjustment->verifyAdjustments()) { throw std::runtime_error("Color adjustment incorrectly set"); @@ -679,14 +681,15 @@ void Hyperion::setComponentState(const Components component, const bool state) break; case KODICHECKER: { - KODIVideoChecker* _kodiVideoChecker = KODIVideoChecker::getInstance(); - if (_kodiVideoChecker != nullptr) - state ? _kodiVideoChecker->start() : _kodiVideoChecker->stop(); + KODIVideoChecker* kodiVideoChecker = KODIVideoChecker::getInstance(); + if (kodiVideoChecker != nullptr) + state ? kodiVideoChecker->start() : kodiVideoChecker->stop(); else Debug(_log, "Can't get instance from: '%s'", componentToString(component)); break; } case FORWARDER: + //_messageForwarder break; case UDPLISTENER: break; diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp index 39718891..7943f745 100644 --- a/libsrc/hyperion/PriorityMuxer.cpp +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -14,6 +14,8 @@ PriorityMuxer::PriorityMuxer(int ledCount) _lowestPriorityInfo.priority = LOWEST_PRIORITY; _lowestPriorityInfo.timeoutTime_ms = -1; _lowestPriorityInfo.ledColors = std::vector(ledCount, {0, 0, 0}); + + _activeInputs[_currentPriority] = _lowestPriorityInfo; } PriorityMuxer::~PriorityMuxer() @@ -33,21 +35,15 @@ QList PriorityMuxer::getPriorities() const bool PriorityMuxer::hasPriority(const int priority) const { - return _activeInputs.contains(priority); + return (priority == LOWEST_PRIORITY) ? true : _activeInputs.contains(priority); } const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) const { - if (priority == LOWEST_PRIORITY) - { - return _lowestPriorityInfo; - } - auto elemIt = _activeInputs.find(priority); if (elemIt == _activeInputs.end()) { - std::cout << "error " << priority << std::endl; - throw std::runtime_error("HYPERION (prioritymux) ERROR: no such priority"); + throw std::runtime_error("HYPERION (prioritymuxer) ERROR: no such priority"); } return elemIt.value(); } @@ -64,14 +60,10 @@ void PriorityMuxer::setInput(const int priority, const std::vector& le void PriorityMuxer::clearInput(const int priority) { - _activeInputs.remove(priority); - if (_currentPriority == priority) + if (priority < LOWEST_PRIORITY) { - if (_activeInputs.empty()) - { - _currentPriority = LOWEST_PRIORITY; - } - else + _activeInputs.remove(priority); + if (_currentPriority == priority) { QList keys = _activeInputs.keys(); _currentPriority = *std::min_element(keys.begin(), keys.end()); @@ -83,6 +75,7 @@ void PriorityMuxer::clearAll() { _activeInputs.clear(); _currentPriority = LOWEST_PRIORITY; + _activeInputs[_currentPriority] = _lowestPriorityInfo; } void PriorityMuxer::setCurrentTime(const int64_t& now) diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index b89236f7..050f7fa4 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -6,13 +6,11 @@ "logger" : { "type" : "object", - "required" : true, "properties" : { "level" : { - "type" : "string", - "required" : true + "enum" : ["silent", "warn", "verbose", "debug"] } }, "additionalProperties" : false @@ -50,7 +48,7 @@ "required" : false } }, - "additionalProperties" : false + "additionalProperties" : true }, "color" : { @@ -364,44 +362,37 @@ "smoothing": { "type" : "object", - "required" : true, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "type" : { - "enum" : ["none", "linear"], - "required" : true + "enum" : ["linear"] }, "time_ms" : { "type" : "integer", - "required" : false, "minimum" : 25, "maximum": 600 }, "updateFrequency" : { "type" : "number", - "required" : false, "minimum" : 1.000, "maximum": 100.000 }, "updateDelay" : { "type" : "integer", - "required" : false, "minimum" : 0, "maximum": 2048 }, "continuousOutput" : { - "type" : "boolean", - "required" : false + "type" : "boolean" } }, "additionalProperties" : false @@ -503,88 +494,120 @@ "framegrabber" : { "type" : "object", - "required" : false, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "type" : { - "type" : "string", - "required" : true + "type" : "string" }, "width" : { - "type" : "integer", - "required" : false + "type" : "integer" }, "height" : { - "type" : "integer", - "required" : false + "type" : "integer" }, "frequency_Hz" : { "type" : "integer", - "required" : true + "minimum" : 0 }, "priority" : + { + "type" : "integer" + }, + "cropLeft" : { "type" : "integer", - "required" : true + "minimum" : 0 + }, + "cropRight" : + { + "type" : "integer", + "minimum" : 0 + }, + "cropTop" : + { + "type" : "integer", + "minimum" : 0 + }, + "cropBottom" : + { + "type" : "integer", + "minimum" : 0 + }, + "useXGetImage" : + { + "type" : "boolean" + }, + "horizontalPixelDecimation" : + { + "type" : "integer", + "minimum" : 0 + }, + "verticalPixelDecimation" : + { + "type" : "integer", + "minimum" : 0 + }, + "device" : + { + "type" : "string" + }, + "display" : + { + "type" : "integer", + "minimum" : 0 } }, - "additionalProperties" : true + "additionalProperties" : false }, "blackborderdetector" : { "type" : "object", - "required" : true, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "threshold" : { "type" : "number", - "required" : true, "minimum" : 0.0, "maximum" : 1.0 }, "unknownFrameCnt" : { "type" : "number", - "required" : false, "minimum" : 0 }, "borderFrameCnt" : { "type" : "number", - "required" : false, "minimum" : 0 }, "maxInconsistentCnt" : { "type" : "number", - "required" : false, "minimum" : 0 }, "blurRemoveCnt" : { "type" : "number", - "required" : false, "minimum" : 0 }, "mode" : { - "type" : "string", - "required" : true + "type" : + { + "enum" : ["default", "classic", "osd"] + } } }, "additionalProperties" : false @@ -592,58 +615,47 @@ "kodiVideoChecker" : { "type" : "object", - "required" : true, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "kodiAddress" : { - "type" : "string", - "required" : true + "type" : "string" }, "kodiTcpPort" : { - "type" : "integer", - "required" : true + "type" : "integer" }, "grabVideo" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "grabPictures" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "grabAudio" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "grabMenu" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "grabPause" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "grabScreensaver" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "enable3DDetection" : { - "type" : "boolean", - "required" : true + "type" : "boolean" } }, "additionalProperties" : false @@ -651,34 +663,28 @@ "initialEffect" : { "type" : "object", - "required" : false, "properties" : { "background-effect" : { - "type" : "string", - "required" : false + "type" : "array" }, "background-effect-args" : { - "type" : "object", - "required" : false + "type" : "object" }, "foreground-effect" : { - "type" : "string", - "required" : false + "type" : "array" }, "foreground-effect-args" : { - "type" : "object", - "required" : false + "type" : "object" }, "foreground-duration_ms" : { - "type" : "integer", - "required" : false - } + "type" : "integer" + } }, "additionalProperties" : false }, @@ -741,13 +747,11 @@ "boblightServer" : { "type" : "object", - "required" : true, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "port" : { @@ -758,8 +762,7 @@ }, "priority" : { - "type" : "integer", - "required" : true + "type" : "integer" } }, "additionalProperties" : false @@ -767,13 +770,11 @@ "udpListener" : { "type" : "object", - "required" : true, "properties" : { "enable" : { - "type" : "boolean", - "required" : true + "type" : "boolean" }, "address" : { @@ -783,24 +784,20 @@ "port" : { "type" : "integer", - "required" : true, "minimum" : 0, "maximum" : 65535 }, "priority" : { - "type" : "integer", - "required" : true + "type" : "integer" }, "timeout" : { - "type" : "integer", - "required" : true + "type" : "integer" }, "shared" : { - "type" : "boolean", - "required" : true + "type" : "boolean" } }, "additionalProperties" : false @@ -832,13 +829,11 @@ "effects" : { "type" : "object", - "required" : false, "properties" : { "paths" : { - "type" : "array", - "required" : false + "type" : "array" } }, "additionalProperties" : false @@ -906,8 +901,7 @@ }, "endOfJson" : { - "type" : "string", - "required" : false + "type" : "string" } }, "additionalProperties" : false diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 2bf6a49c..b740942f 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -13,6 +13,7 @@ #include #include #include +#include // hyperion util includes #include @@ -820,7 +821,7 @@ void JsonClientConnection::handleConfigGetCommand(const Json::Value &) void JsonClientConnection::handleComponentStateCommand(const Json::Value& message) { const Json::Value & componentState = message["componentstate"]; - std::string component = componentState.get("component", "").asString(); + QString component = QString::fromStdString(componentState.get("component", "").asString()).toUpper(); if (component == "SMOOTHING") _hyperion->setComponentState((Components)0, componentState.get("state", true).asBool()); diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 0e45b5f5..40e71aae 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -1,6 +1,7 @@ // stl includes #include #include +#include // Qt includes #include @@ -85,6 +86,7 @@ int main(int argc, char * argv[]) AdjustmentParameter & argBAdjust = parameters.add('B', "blueAdjustment", "Set the adjustment of the blue color (requires 3 space seperated values between 0 and 255)"); IntParameter & argSource = parameters.add (0x0, "sourceSelect" , "Set current active priority channel and deactivate auto source switching"); SwitchParameter<> & argSourceAuto = parameters.add >(0x0, "sourceAutoSelect", "Enables auto source, if disabled prio by manual selecting input source"); + SwitchParameter<> & argSourceOff = parameters.add >(0x0, "sourceOff", "select no source, this results in leds activly set to black (=off)"); SwitchParameter<> & argConfigGet = parameters.add >(0x0, "configget" , "Print the current loaded Hyperion configuration file"); // set the default values @@ -109,7 +111,7 @@ int main(int argc, char * argv[]) bool colorModding = colorTransform || colorAdjust || argCorrection.isSet() || argTemperature.isSet(); // check that exactly one command was given - int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), argEnableComponent.isSet(), argDisableComponent.isSet(), colorModding, argSource.isSet(), argSourceAuto.isSet(), argConfigGet.isSet()}); + int commandCount = count({argColor.isSet(), argImage.isSet(), argEffect.isSet(), argServerInfo.isSet(), argClear.isSet(), argClearAll.isSet(), argEnableComponent.isSet(), argDisableComponent.isSet(), colorModding, argSource.isSet(), argSourceAuto.isSet(), argSourceOff.isSet(), argConfigGet.isSet()}); if (commandCount != 1) { std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl; @@ -183,6 +185,10 @@ int main(int argc, char * argv[]) { connection.setComponentState(argDisableComponent.getValue(), false); } + else if (argSourceOff.isSet()) + { + connection.setSource(std::numeric_limits::max()); + } else if (argSource.isSet()) { connection.setSource(argSource.getValue()); diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 249468ef..c86da78b 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -32,7 +33,7 @@ #include "hyperiond.h" -HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent) +HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent) : QObject(parent) , _log(Logger::getInstance("MAIN")) , _kodiVideoChecker(nullptr) @@ -48,10 +49,9 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent) , _osxGrabber(nullptr) , _hyperion(nullptr) { - loadConfig(configFile); // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson - loadConfig(QString::fromStdString(configFile)); + loadConfig(configFile); - _hyperion = Hyperion::initInstance(_config, configFile); + _hyperion = Hyperion::initInstance(_config, configFile.toStdString()); if (Logger::getLogLevel() == Logger::WARNING) { @@ -72,7 +72,7 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent) WarningIf(_qconfig.contains("logger"), Logger::getInstance("LOGGER"), "Logger settings overriden by command line argument"); } - Info(_log, "Hyperion started and initialised"); + Info(_log, "Hyperion initialised"); } HyperionDaemon::~HyperionDaemon() @@ -106,35 +106,14 @@ void HyperionDaemon::run() #if !defined(ENABLE_DISPMANX) && !defined(ENABLE_OSX) && !defined(ENABLE_FB) && !defined(ENABLE_X11) && !defined(ENABLE_AMLOGIC) WarningIf(_qconfig.contains("framegrabber"), _log, "No grabber can be instantiated, because all grabbers have been left out from the build"); #endif + Info(_log, "Hyperion started"); -} -void HyperionDaemon::loadConfig(const std::string & configFile) // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson -{ - Info(_log, "Selected configuration file: %s", configFile.c_str() ); - // make sure the resources are loaded (they may be left out after static linking) - Q_INIT_RESOURCE(resource); - - // read the json schema from the resource - QResource schemaData(":/hyperion-schema"); - assert(schemaData.isValid()); - - Json::Reader jsonReader; - Json::Value schemaJson; - if (!jsonReader.parse(reinterpret_cast(schemaData.data()), reinterpret_cast(schemaData.data()) + schemaData.size(), schemaJson, false)) - { - throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ; - } - JsonSchemaChecker schemaChecker; - schemaChecker.setSchema(schemaJson); - - _config = JsonFactory::readJson(configFile); - schemaChecker.validate(_config); } void HyperionDaemon::loadConfig(const QString & configFile) { -// Info(_log, "Selected configuration file: %s", configFile.toStdString().c_str()); // uncommend this line only if JsonCpp is removed. Otherwise appears this line twice in the debug output + Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData()); // make sure the resources are loaded (they may be left out after static linking) Q_INIT_RESOURCE(resource); @@ -176,6 +155,7 @@ void HyperionDaemon::loadConfig(const QString & configFile) QJsonSchemaChecker schemaChecker; schemaChecker.setSchema(schemaJson.object()); + _config = JsonFactory::readJson(configFile.toStdString()); // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson _qconfig = QJsonFactory::readJson(configFile); if (!schemaChecker.validate(_qconfig)) { @@ -190,68 +170,76 @@ void HyperionDaemon::loadConfig(const QString & configFile) void HyperionDaemon::startInitialEffect() { + #define FGCONFIG_ARRAY fgEffectConfig.toArray() + #define BGCONFIG_ARRAY bgEffectConfig.toArray() + Hyperion *hyperion = Hyperion::getInstance(); // create boot sequence if the configuration is present if (_config.isMember("initialEffect")) { - const Json::Value effectConfig = _config["initialEffect"]; - const int HIGHEST_PRIORITY = 0; + const QJsonObject & effectConfig = _qconfig["initialEffect"].toObject(); + const int FG_PRIORITY = 0; const int DURATION_INFINITY = 0; - const int LOWEST_PRIORITY = std::numeric_limits::max()-1; + const int BG_PRIORITY = PriorityMuxer::LOWEST_PRIORITY -1; // clear the leds - hyperion->setColor(HIGHEST_PRIORITY, ColorRgb::BLACK, DURATION_INFINITY, false); + hyperion->setColor(FG_PRIORITY, ColorRgb::BLACK, DURATION_INFINITY, false); // initial foreground effect/color - const Json::Value fgEffectConfig = effectConfig["foreground-effect"]; + const QJsonValue fgEffectConfig = effectConfig["foreground-effect"]; int default_fg_duration_ms = 3000; - int fg_duration_ms = effectConfig.get("foreground-effect-duration_ms",default_fg_duration_ms).asUInt(); + int fg_duration_ms = effectConfig["foreground-effect-duration_ms"].toInt(default_fg_duration_ms); if (fg_duration_ms == DURATION_INFINITY) { fg_duration_ms = default_fg_duration_ms; Warning(_log, "foreground effect duration 'infinity' is forbidden, set to default value %d ms",default_fg_duration_ms); } - if ( ! fgEffectConfig.isNull() && fgEffectConfig.isArray() && fgEffectConfig.size() == 3 ) + if ( ! fgEffectConfig.isNull() && fgEffectConfig.isArray() && FGCONFIG_ARRAY.size() == 3 ) { ColorRgb fg_color = { - (uint8_t)fgEffectConfig[0].asUInt(), - (uint8_t)fgEffectConfig[1].asUInt(), - (uint8_t)fgEffectConfig[2].asUInt() + (uint8_t)FGCONFIG_ARRAY.at(0).toInt(0), + (uint8_t)FGCONFIG_ARRAY.at(1).toInt(0), + (uint8_t)FGCONFIG_ARRAY.at(2).toInt(0) }; - hyperion->setColor(HIGHEST_PRIORITY, fg_color, fg_duration_ms, false); + hyperion->setColor(FG_PRIORITY, fg_color, fg_duration_ms, false); Info(_log,"Inital foreground color set (%d %d %d)",fg_color.red,fg_color.green,fg_color.blue); } - else if (! fgEffectConfig.isNull() && fgEffectConfig.isString()) + else if (! fgEffectConfig.isNull() && fgEffectConfig.isArray() && FGCONFIG_ARRAY.size() == 1 && FGCONFIG_ARRAY.at(0).isString()) { - const std::string bgEffectName = fgEffectConfig.asString(); - int result = effectConfig.isMember("foreground-effect-args") - ? hyperion->setEffect(bgEffectName, effectConfig["foreground-effect-args"], HIGHEST_PRIORITY, fg_duration_ms) - : hyperion->setEffect(bgEffectName, HIGHEST_PRIORITY, fg_duration_ms); - Info(_log,"Inital foreground effect '%s' %s", bgEffectName.c_str(), ((result == 0) ? "started" : "failed")); + const std::string fgEffectName = FGCONFIG_ARRAY.at(0).toString().toStdString(); + int result = effectConfig.contains("foreground-effect-args") +// ? hyperion->setEffect(fgEffectName, effectConfig["foreground-effect-args"], FG_PRIORITY, fg_duration_ms) + ? hyperion->setEffect(fgEffectName, _config["initialEffect"]["foreground-effect-args"], FG_PRIORITY, fg_duration_ms) + : hyperion->setEffect(fgEffectName, FG_PRIORITY, fg_duration_ms); + Info(_log,"Inital foreground effect '%s' %s", fgEffectName.c_str(), ((result == 0) ? "started" : "failed")); } // initial background effect/color - const Json::Value bgEffectConfig = effectConfig["background-effect"]; - if ( ! bgEffectConfig.isNull() && bgEffectConfig.isArray() && bgEffectConfig.size() == 3 ) + const QJsonValue bgEffectConfig = effectConfig["background-effect"]; + if ( ! bgEffectConfig.isNull() && bgEffectConfig.isArray() && BGCONFIG_ARRAY.size() == 3 ) { ColorRgb bg_color = { - (uint8_t)bgEffectConfig[0].asUInt(), - (uint8_t)bgEffectConfig[1].asUInt(), - (uint8_t)bgEffectConfig[2].asUInt() + (uint8_t)BGCONFIG_ARRAY.at(0).toInt(0), + (uint8_t)BGCONFIG_ARRAY.at(1).toInt(0), + (uint8_t)BGCONFIG_ARRAY.at(2).toInt(0) }; - hyperion->setColor(LOWEST_PRIORITY, bg_color, DURATION_INFINITY, false); + hyperion->setColor(BG_PRIORITY, bg_color, DURATION_INFINITY, false); Info(_log,"Inital background color set (%d %d %d)",bg_color.red,bg_color.green,bg_color.blue); } - else if (! bgEffectConfig.isNull() && bgEffectConfig.isString()) + else if (! bgEffectConfig.isNull() && bgEffectConfig.isArray() && BGCONFIG_ARRAY.size() == 1 && BGCONFIG_ARRAY.at(0).isString()) { - const std::string bgEffectName = bgEffectConfig.asString(); - int result = effectConfig.isMember("background-effect-args") - ? hyperion->setEffect(bgEffectName, effectConfig["background-effect-args"], LOWEST_PRIORITY, DURATION_INFINITY) - : hyperion->setEffect(bgEffectName, LOWEST_PRIORITY, DURATION_INFINITY); + const std::string bgEffectName = BGCONFIG_ARRAY.at(0).toString().toStdString(); + int result = effectConfig.contains("background-effect-args") +// ? hyperion->setEffect(bgEffectName, effectConfig["background-effect-args"], BG_PRIORITY, fg_duration_ms) + ? hyperion->setEffect(bgEffectName, _config["initialEffect"]["background-effect-args"], BG_PRIORITY, DURATION_INFINITY) + : hyperion->setEffect(bgEffectName, BG_PRIORITY, DURATION_INFINITY); Info(_log,"Inital background effect '%s' %s", bgEffectName.c_str(), ((result == 0) ? "started" : "failed")); } } + + #undef FGCONFIG_ARRAY + #undef BGCONFIG_ARRAY } @@ -271,7 +259,7 @@ void HyperionDaemon::createKODIVideoChecker() videoCheckerConfig["grabPause"].toBool(true), videoCheckerConfig["grabScreensaver"].toBool(false), videoCheckerConfig["enable3DDetection"].toBool(true)); - Debug(_log, "KODI checker created "); + Debug(_log, "KODI checker created "); if( kodiCheckerConfigured && videoCheckerConfig["enable"].toBool(true)) { diff --git a/src/hyperiond/hyperiond.h b/src/hyperiond/hyperiond.h index 590a215e..031974ad 100644 --- a/src/hyperiond/hyperiond.h +++ b/src/hyperiond/hyperiond.h @@ -51,10 +51,9 @@ class HyperionDaemon : public QObject { public: - HyperionDaemon(std::string configFile, QObject *parent=nullptr); + HyperionDaemon(QString configFile, QObject *parent=nullptr); ~HyperionDaemon(); - void loadConfig(const std::string & configFile); // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson void loadConfig(const QString & configFile); void run(); diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index a65e4fe6..3ef8ecaa 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "HyperionConfig.h" @@ -143,7 +144,7 @@ int main(int argc, char** argv) HyperionDaemon* hyperiond = nullptr; try { - hyperiond = new HyperionDaemon(configFiles[argvId], &app); + hyperiond = new HyperionDaemon(QString::fromStdString(configFiles[argvId]), &app); hyperiond->run(); } catch (std::exception& e)