Added the possibility to set effect arguments over json

Former-commit-id: 4bc2920c04853e549c712ec70492371b14d20877
This commit is contained in:
johan
2013-12-01 14:09:01 +01:00
parent ae148afba9
commit 515ae3e8c0
12 changed files with 95 additions and 30 deletions

View File

@@ -102,7 +102,7 @@ void JsonConnection::setImage(QImage image, int priority, int duration)
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;
@@ -112,6 +112,14 @@ void JsonConnection::setEffect(const std::string &effectName, int priority, int
command["priority"] = priority;
Json::Value & effect = command["effect"];
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)
{
command["duration"] = duration;

View File

@@ -56,10 +56,11 @@ public:
/// Start the given effect
///
/// @param effect The name of the effect
/// @param effectArgs The arguments to use instead of the default ones
/// @param priority The priority
/// @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

View File

@@ -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)");
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 & 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<> & 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");
@@ -59,6 +60,7 @@ int main(int argc, char * argv[])
argAddress.setDefault(defaultServerAddress.toStdString());
argPriority.setDefault(defaultPriority);
argDuration.setDefault(-1);
argEffectArgs.setDefault("");
// parse all options
optionParser.parse(argc, const_cast<const char **>(argv));
@@ -108,7 +110,7 @@ int main(int argc, char * argv[])
}
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())
{