mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added the possibility to set effect arguments over json
Former-commit-id: 4bc2920c04853e549c712ec70492371b14d20877
This commit is contained in:
parent
ae148afba9
commit
515ae3e8c0
14
include/effectengine/EffectDefinition.h
Normal file
14
include/effectengine/EffectDefinition.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// stl include
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// json include
|
||||||
|
#include <json/value.h>
|
||||||
|
|
||||||
|
struct EffectDefinition
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string script;
|
||||||
|
Json::Value args;
|
||||||
|
};
|
@ -1,11 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
// Json includes
|
// Json includes
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
|
|
||||||
// Hyperion includes
|
// Hyperion includes
|
||||||
#include <hyperion/Hyperion.h>
|
#include <hyperion/Hyperion.h>
|
||||||
|
|
||||||
|
// Effect engine includes
|
||||||
|
#include <effectengine/EffectDefinition.h>
|
||||||
|
|
||||||
// pre-declarioation
|
// pre-declarioation
|
||||||
class Effect;
|
class Effect;
|
||||||
typedef struct _ts PyThreadState;
|
typedef struct _ts PyThreadState;
|
||||||
@ -18,32 +24,28 @@ public:
|
|||||||
EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig);
|
EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig);
|
||||||
virtual ~EffectEngine();
|
virtual ~EffectEngine();
|
||||||
|
|
||||||
std::list<std::string> getEffects() const;
|
const std::list<EffectDefinition> & getEffects() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
||||||
int runEffect(const std::string &effectName, int priority, int timeout = -1);
|
int runEffect(const std::string &effectName, int priority, int timeout = -1);
|
||||||
|
|
||||||
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
||||||
|
int runEffect(const std::string &effectName, const Json::Value & args, int priority, int timeout = -1);
|
||||||
|
|
||||||
/// Clear any effect running on the provided channel
|
/// Clear any effect running on the provided channel
|
||||||
void channelCleared(int priority);
|
void channelCleared(int priority);
|
||||||
|
|
||||||
/// Clear all effects
|
/// Clear all effects
|
||||||
void allChannelsCleared();
|
void allChannelsCleared();
|
||||||
|
|
||||||
public:
|
|
||||||
struct EffectDefinition
|
|
||||||
{
|
|
||||||
std::string script;
|
|
||||||
Json::Value args;
|
|
||||||
};
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void effectFinished(Effect * effect);
|
void effectFinished(Effect * effect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Hyperion * _hyperion;
|
Hyperion * _hyperion;
|
||||||
|
|
||||||
std::map<std::string, EffectDefinition> _availableEffects;
|
std::list<EffectDefinition> _availableEffects;
|
||||||
|
|
||||||
std::list<Effect *> _activeEffects;
|
std::list<Effect *> _activeEffects;
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
#include <hyperion/LedDevice.h>
|
#include <hyperion/LedDevice.h>
|
||||||
#include <hyperion/PriorityMuxer.h>
|
#include <hyperion/PriorityMuxer.h>
|
||||||
|
|
||||||
|
// Effect engine includes
|
||||||
|
#include <effectengine/EffectDefinition.h>
|
||||||
|
|
||||||
// Forward class declaration
|
// Forward class declaration
|
||||||
class HsvTransform;
|
class HsvTransform;
|
||||||
class ColorTransform;
|
class ColorTransform;
|
||||||
@ -102,7 +105,7 @@ public:
|
|||||||
|
|
||||||
/// Get the list of available effects
|
/// Get the list of available effects
|
||||||
/// @return The list of available effects
|
/// @return The list of available effects
|
||||||
std::list<std::string> getEffects() const;
|
const std::list<EffectDefinition> &getEffects() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
///
|
///
|
||||||
@ -153,6 +156,12 @@ public slots:
|
|||||||
/// @param timout The timeout of the effect (after the timout, the effect will be cleared)
|
/// @param timout The timeout of the effect (after the timout, the effect will be cleared)
|
||||||
int setEffect(const std::string & effectName, int priority, int timeout = -1);
|
int setEffect(const std::string & effectName, int priority, int timeout = -1);
|
||||||
|
|
||||||
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
||||||
|
/// @param effectName Name of the effec to run
|
||||||
|
/// @param priority The priority channel of the effect
|
||||||
|
/// @param timout The timeout of the effect (after the timout, the effect will be cleared)
|
||||||
|
int setEffect(const std::string & effectName, const Json::Value & args, int priority, int timeout = -1);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LedDevice * createDevice(const Json::Value & deviceConfig);
|
static LedDevice * createDevice(const Json::Value & deviceConfig);
|
||||||
static ColorOrder createColorOrder(const Json::Value & deviceConfig);
|
static ColorOrder createColorOrder(const Json::Value & deviceConfig);
|
||||||
|
@ -14,6 +14,7 @@ SET(EffectEngineQT_HEADERS
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(EffectEngineHEADERS
|
SET(EffectEngineHEADERS
|
||||||
|
${CURRENT_HEADER_DIR}/EffectDefinition.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(EffectEngineSOURCES
|
SET(EffectEngineSOURCES
|
||||||
|
@ -49,9 +49,9 @@ private:
|
|||||||
|
|
||||||
const int _timeout;
|
const int _timeout;
|
||||||
|
|
||||||
const std::string & _script;
|
const std::string _script;
|
||||||
|
|
||||||
const Json::Value & _args;
|
const Json::Value _args;
|
||||||
|
|
||||||
int64_t _endTime;
|
int64_t _endTime;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo
|
|||||||
for (const std::string & name : effectNames)
|
for (const std::string & name : effectNames)
|
||||||
{
|
{
|
||||||
const Json::Value & info = jsonEffectConfig[name];
|
const Json::Value & info = jsonEffectConfig[name];
|
||||||
_availableEffects[name] = {info["script"].asString(), info["args"]};
|
_availableEffects.push_back({name, info["script"].asString(), info["args"]});
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the python interpreter
|
// initialize the python interpreter
|
||||||
@ -43,22 +43,33 @@ EffectEngine::~EffectEngine()
|
|||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::string> EffectEngine::getEffects() const
|
const std::list<EffectDefinition> &EffectEngine::getEffects() const
|
||||||
{
|
{
|
||||||
std::list<std::string> effectNames;
|
return _availableEffects;
|
||||||
foreach (auto entry, _availableEffects) {
|
|
||||||
effectNames.push_back(entry.first);
|
|
||||||
}
|
|
||||||
return effectNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int EffectEngine::runEffect(const std::string &effectName, int priority, int timeout)
|
int EffectEngine::runEffect(const std::string &effectName, int priority, int timeout)
|
||||||
|
{
|
||||||
|
return runEffect(effectName, Json::Value(Json::nullValue), priority, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
int EffectEngine::runEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout)
|
||||||
{
|
{
|
||||||
std::cout << "run effect " << effectName << " on channel " << priority << std::endl;
|
std::cout << "run effect " << effectName << " on channel " << priority << std::endl;
|
||||||
|
|
||||||
if (_availableEffects.find(effectName) == _availableEffects.end())
|
const EffectDefinition * effectDefinition = nullptr;
|
||||||
|
for (const EffectDefinition & e : _availableEffects)
|
||||||
|
{
|
||||||
|
if (e.name == effectName)
|
||||||
|
{
|
||||||
|
effectDefinition = &e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (effectDefinition == nullptr)
|
||||||
{
|
{
|
||||||
// no such effect
|
// no such effect
|
||||||
|
std::cerr << "effect " << effectName << " not found" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +77,7 @@ int EffectEngine::runEffect(const std::string &effectName, int priority, int tim
|
|||||||
channelCleared(priority);
|
channelCleared(priority);
|
||||||
|
|
||||||
// create the effect
|
// create the effect
|
||||||
const EffectDefinition & effectDefinition = _availableEffects[effectName];
|
Effect * effect = new Effect(priority, timeout, effectDefinition->script, args.isNull() ? effectDefinition->args : args);
|
||||||
Effect * effect = new Effect(priority, timeout, effectDefinition.script, effectDefinition.args);
|
|
||||||
connect(effect, SIGNAL(setColors(int,std::vector<ColorRgb>,int)), _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)), Qt::QueuedConnection);
|
connect(effect, SIGNAL(setColors(int,std::vector<ColorRgb>,int)), _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)), Qt::QueuedConnection);
|
||||||
connect(effect, SIGNAL(effectFinished(Effect*)), this, SLOT(effectFinished(Effect*)));
|
connect(effect, SIGNAL(effectFinished(Effect*)), this, SLOT(effectFinished(Effect*)));
|
||||||
_activeEffects.push_back(effect);
|
_activeEffects.push_back(effect);
|
||||||
|
@ -466,7 +466,7 @@ const Hyperion::InputInfo &Hyperion::getPriorityInfo(const int priority) const
|
|||||||
return _muxer.getInputInfo(priority);
|
return _muxer.getInputInfo(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::string> Hyperion::getEffects() const
|
const std::list<EffectDefinition> & Hyperion::getEffects() const
|
||||||
{
|
{
|
||||||
return _effectEngine->getEffects();
|
return _effectEngine->getEffects();
|
||||||
}
|
}
|
||||||
@ -476,6 +476,11 @@ int Hyperion::setEffect(const std::string &effectName, int priority, int timeout
|
|||||||
return _effectEngine->runEffect(effectName, priority, timeout);
|
return _effectEngine->runEffect(effectName, priority, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Hyperion::setEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout)
|
||||||
|
{
|
||||||
|
return _effectEngine->runEffect(effectName, args, priority, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
void Hyperion::update()
|
void Hyperion::update()
|
||||||
{
|
{
|
||||||
// Update the muxer, cleaning obsolete priorities
|
// Update the muxer, cleaning obsolete priorities
|
||||||
|
@ -162,7 +162,14 @@ void JsonClientConnection::handleEffectCommand(const Json::Value &message)
|
|||||||
const std::string & effectName = effect["name"].asString();
|
const std::string & effectName = effect["name"].asString();
|
||||||
|
|
||||||
// set output
|
// set output
|
||||||
_hyperion->setEffect(effectName, priority, duration);
|
if (effect.isMember("args"))
|
||||||
|
{
|
||||||
|
_hyperion->setEffect(effectName, effect["args"], priority, duration);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_hyperion->setEffect(effectName, priority, duration);
|
||||||
|
}
|
||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendSuccessReply();
|
sendSuccessReply();
|
||||||
@ -212,11 +219,13 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
|||||||
|
|
||||||
// collect effect info
|
// collect effect info
|
||||||
Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue);
|
Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue);
|
||||||
std::list<std::string> effectNames = _hyperion->getEffects();
|
const std::list<EffectDefinition> & effectsDefinitions = _hyperion->getEffects();
|
||||||
for (const std::string & name : effectNames)
|
for (const EffectDefinition & effectDefinition : effectsDefinitions)
|
||||||
{
|
{
|
||||||
Json::Value effect;
|
Json::Value effect;
|
||||||
effect["name"] = name;
|
effect["name"] = effectDefinition.name;
|
||||||
|
effect["script"] = effectDefinition.script;
|
||||||
|
effect["args"] = effectDefinition.args;
|
||||||
|
|
||||||
effects.append(effect);
|
effects.append(effect);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
"name" : {
|
"name" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"required" : true
|
"required" : true
|
||||||
|
},
|
||||||
|
"args" : {
|
||||||
|
"type" : "object",
|
||||||
|
"required" : false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
@ -102,7 +102,7 @@ void JsonConnection::setImage(QImage image, int priority, int duration)
|
|||||||
parseReply(reply);
|
parseReply(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonConnection::setEffect(const std::string &effectName, int priority, int duration)
|
void JsonConnection::setEffect(const std::string &effectName, const std::string & effectArgs, int priority, int duration)
|
||||||
{
|
{
|
||||||
std::cout << "Start effect " << effectName << std::endl;
|
std::cout << "Start effect " << effectName << std::endl;
|
||||||
|
|
||||||
@ -112,6 +112,14 @@ void JsonConnection::setEffect(const std::string &effectName, int priority, int
|
|||||||
command["priority"] = priority;
|
command["priority"] = priority;
|
||||||
Json::Value & effect = command["effect"];
|
Json::Value & effect = command["effect"];
|
||||||
effect["name"] = effectName;
|
effect["name"] = effectName;
|
||||||
|
if (effectArgs.size() > 0)
|
||||||
|
{
|
||||||
|
Json::Reader reader;
|
||||||
|
if (!reader.parse(effectArgs, effect["args"], false))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Error in effect arguments: " + reader.getFormattedErrorMessages());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
{
|
{
|
||||||
command["duration"] = duration;
|
command["duration"] = duration;
|
||||||
|
@ -56,10 +56,11 @@ public:
|
|||||||
/// Start the given effect
|
/// Start the given effect
|
||||||
///
|
///
|
||||||
/// @param effect The name of the effect
|
/// @param effect The name of the effect
|
||||||
|
/// @param effectArgs The arguments to use instead of the default ones
|
||||||
/// @param priority The priority
|
/// @param priority The priority
|
||||||
/// @param duration The duration in milliseconds
|
/// @param duration The duration in milliseconds
|
||||||
///
|
///
|
||||||
void setEffect(const std::string & effectName, int priority, int duration);
|
void setEffect(const std::string & effectName, const std::string &effectArgs, int priority, int duration);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Retrieve a list of all occupied priority channels
|
/// Retrieve a list of all occupied priority channels
|
||||||
|
@ -43,6 +43,7 @@ int main(int argc, char * argv[])
|
|||||||
ColorParameter & argColor = parameters.add<ColorParameter> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name)");
|
ColorParameter & argColor = parameters.add<ColorParameter> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name)");
|
||||||
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
|
||||||
StringParameter & argEffect = parameters.add<StringParameter> ('e', "effect" , "Enable the effect with the given name");
|
StringParameter & argEffect = parameters.add<StringParameter> ('e', "effect" , "Enable the effect with the given name");
|
||||||
|
StringParameter & argEffectArgs = parameters.add<StringParameter> (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string.");
|
||||||
SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('l', "list" , "List server info");
|
SwitchParameter<> & argServerInfo = parameters.add<SwitchParameter<> >('l', "list" , "List server info");
|
||||||
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
|
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
|
||||||
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clearall" , "Clear data for all active priority channels");
|
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clearall" , "Clear data for all active priority channels");
|
||||||
@ -59,6 +60,7 @@ int main(int argc, char * argv[])
|
|||||||
argAddress.setDefault(defaultServerAddress.toStdString());
|
argAddress.setDefault(defaultServerAddress.toStdString());
|
||||||
argPriority.setDefault(defaultPriority);
|
argPriority.setDefault(defaultPriority);
|
||||||
argDuration.setDefault(-1);
|
argDuration.setDefault(-1);
|
||||||
|
argEffectArgs.setDefault("");
|
||||||
|
|
||||||
// parse all options
|
// parse all options
|
||||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||||
@ -108,7 +110,7 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
else if (argEffect.isSet())
|
else if (argEffect.isSet())
|
||||||
{
|
{
|
||||||
connection.setEffect(argEffect.getValue(), argPriority.getValue(), argDuration.getValue());
|
connection.setEffect(argEffect.getValue(), argEffectArgs.getValue(), argPriority.getValue(), argDuration.getValue());
|
||||||
}
|
}
|
||||||
else if (argServerInfo.isSet())
|
else if (argServerInfo.isSet())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user