From ae1bd7d254305b7a118d2015ec16b32d4c0a94e9 Mon Sep 17 00:00:00 2001 From: johan Date: Sat, 30 Nov 2013 12:42:08 +0100 Subject: [PATCH] Effects added to configuration file Former-commit-id: 2ff4700ee5d5bc3a7dd5a29ecd35c1c9dd189873 --- include/effectengine/EffectEngine.h | 2 +- libsrc/effectengine/EffectEngine.cpp | 17 ++++++++++------- libsrc/hyperion/Hyperion.cpp | 2 +- libsrc/hyperion/hyperion.schema.json | 21 +++++++++++++++++++++ libsrc/jsonserver/JsonClientConnection.cpp | 6 +++--- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/include/effectengine/EffectEngine.h b/include/effectengine/EffectEngine.h index 57cc6484..baed604b 100644 --- a/include/effectengine/EffectEngine.h +++ b/include/effectengine/EffectEngine.h @@ -11,7 +11,7 @@ class EffectEngine : public QObject Q_OBJECT public: - EffectEngine(Hyperion * hyperion); + EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig); virtual ~EffectEngine(); std::list getEffects() const; diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 9a9f1390..2e1ada31 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -1,16 +1,14 @@ -// Qt includes -#include - // Python includes #include +// Qt includes +#include + // effect engine includes #include #include "Effect.h" -//static PyThreadState *_mainThreadState = 0; - -EffectEngine::EffectEngine(Hyperion * hyperion) : +EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig) : _hyperion(hyperion), _availableEffects(), _activeEffects(), @@ -23,7 +21,12 @@ EffectEngine::EffectEngine(Hyperion * hyperion) : connect(_hyperion, SIGNAL(allChannelsCleared()), this, SLOT(allChannelsCleared())); // read all effects - _availableEffects["test"] = {"test.py", "{\"speed\":0.2}"}; + std::vector effectNames = jsonEffectConfig.getMemberNames(); + for (const std::string & name : effectNames) + { + const Json::Value & info = jsonEffectConfig[name]; + _availableEffects[name] = {info["script"].asString(), Json::FastWriter().write(info["args"])}; + } // initialize the python interpreter std::cout << "Initializing Python interpreter" << std::endl; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 2ac94674..2fd32e56 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -270,7 +270,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); // create the effect engine - _effectEngine = new EffectEngine(this); + _effectEngine = new EffectEngine(this, jsonConfig["effects"]); // initialize the leds update(); diff --git a/libsrc/hyperion/hyperion.schema.json b/libsrc/hyperion/hyperion.schema.json index d6f7c7bf..7409fbc6 100644 --- a/libsrc/hyperion/hyperion.schema.json +++ b/libsrc/hyperion/hyperion.schema.json @@ -200,6 +200,27 @@ "additionalProperties" : false } }, + "effects" : + { + "type" : "object", + "required" : false, + "additionalProperties" : + { + "type" : "object", + "required" : false, + "properties" : + { + "script" : { + "type" : "string", + "required" : true + }, + "args" : { + "type" : "object", + "required" : false + } + } + } + }, "blackborderdetector" : { "type" : "object", diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 2862de82..ae6e5527 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -176,7 +176,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) Json::Value & info = result["info"]; // collect priority information - Json::Value & priorities = info["priorities"]; + Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue); uint64_t now = QDateTime::currentMSecsSinceEpoch(); QList activePriorities = _hyperion->getActivePriorities(); foreach (int priority, activePriorities) { @@ -190,7 +190,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) } // collect transform information - Json::Value & transform = info["transform"]; + Json::Value & transform = info["transform"] = Json::Value(Json::objectValue); transform["saturationGain"] = _hyperion->getTransform(Hyperion::SATURATION_GAIN, Hyperion::INVALID); transform["valueGain"] = _hyperion->getTransform(Hyperion::VALUE_GAIN, Hyperion::INVALID); Json::Value & threshold = transform["threshold"]; @@ -211,7 +211,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) whitelevel.append(_hyperion->getTransform(Hyperion::WHITELEVEL, Hyperion::BLUE)); // collect effect info - Json::Value & effects = info["effects"]; + Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue); std::list effectNames = _hyperion->getEffects(); for (const std::string & name : effectNames) {