Create Effect configuration files (.json) with JSON RPC (#277)

* Add getEffectSchemas and loadEffectSchema function

* Add getEffectSchemas function

* add effect schema files to internal resources

* Add loadEffectSchema and getEffectSchemas function

* add effect schema resources

* add getEffectSchemas function

* extend handleSchemaGetCommand to get ...

... all available effect schemas
add handleCreateEffectCommand function

* add handleCreateEffectCommand function

* include schema-create-effect.json file

* add create-effect schema

* Add schema-create-effect.json file

* Add createEffect to hyperion-remote

* Add createEffect function

* add createEffect function

* Create fade.schema.json

* Add files via upload

* Add files via upload

* Update police.schema.json

* Update EffectEngine.qrc.in

* Update CMakeLists.txt
This commit is contained in:
Paulchen Panther
2016-10-24 23:52:53 +02:00
committed by redPanther
parent 4faa505fa4
commit fab0c208fe
29 changed files with 915 additions and 12 deletions

View File

@@ -148,9 +148,10 @@ void JsonConnection::setEffect(const QString &effectName, const QString & effect
}
effect["args"] = doc.object();
command["effect"] = effect;
}
command["effect"] = effect;
if (duration > 0)
{
command["duration"] = duration;
@@ -163,6 +164,51 @@ void JsonConnection::setEffect(const QString &effectName, const QString & effect
parseReply(reply);
}
void JsonConnection::createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs)
{
qDebug() << "Create effect " << effectName;
// create command
QJsonObject effect;
effect["command"] = QString("create-effect");
effect["name"] = effectName;
effect["script"] = effectScript;
if (effectArgs.size() > 0)
{
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(effectArgs.toUtf8() ,&error);
if (error.error != QJsonParseError::NoError)
{
// report to the user the failure and their locations in the document.
int errorLine(0), errorColumn(0);
for( int i=0, count=qMin( error.offset,effectArgs.size()); i<count; ++i )
{
++errorColumn;
if(effectArgs.at(i) == '\n' )
{
errorColumn = 0;
++errorLine;
}
}
std::stringstream sstream;
sstream << "Error in effect arguments: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
throw std::runtime_error(sstream.str());
}
effect["args"] = doc.object();
}
// send command message
QJsonObject reply = sendMessage(effect);
// parse reply message
parseReply(reply);
}
QString JsonConnection::getServerInfo()
{
qDebug() << "Get server info";

View File

@@ -56,6 +56,15 @@ public:
///
void setEffect(const QString & effectName, const QString &effectArgs, int priority, int duration);
///
/// Create a effect configuration file (.json)
///
/// @param effectName The name of the effect
/// @param effectScript The name of the Python effect file
/// @param effectArgs The arguments of the effect
///
void createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs);
///
/// Retrieve a list of all occupied priority channels
///

View File

@@ -56,13 +56,15 @@ int main(int argc, char * argv[])
// create the option parser and initialize all parameters
Parser parser("Simple application to send a command to hyperion using the Json interface");
Option & argAddress = parser.add<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "localhost:19444");
Option & argAddress = parser.add<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "localhost:19444");
IntOption & argPriority = parser.add<IntOption> ('p', "priority" , "Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]", "100");
IntOption & argDuration = parser.add<IntOption> ('d', "duration" , "Specify how long the leds should be switched on in milliseconds [default: infinity]");
ColorsOption & argColor = parser.add<ColorsOption> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex getColors or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)");
ImageOption & argImage = parser.add<ImageOption> ('i', "image" , "Set the leds to the colors according to the given image file");
Option & argEffect = parser.add<Option> ('e', "effect" , "Enable the effect with the given name");
Option & argEffectFile = parser.add<Option> (0x0, "effectFile", "Arguments to use in combination with --createEffect");
Option & argEffectArgs = parser.add<Option> (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string.", "");
Option & argCreateEffect= parser.add<Option> (0x0, "createEffect","Write a new Json Effect configuration file.\nFirst parameter = Effect name.\nSecond parameter = Effect file (--effectFile).\nLast parameter = Effect arguments (--effectArgs.)", "");
BooleanOption & argServerInfo = parser.add<BooleanOption>('l', "list" , "List server info and active effects with priority and duration");
BooleanOption & argClear = parser.add<BooleanOption>('x', "clear" , "Clear data for the priority channel provided by the -p option");
BooleanOption & argClearAll = parser.add<BooleanOption>(0x0, "clearall" , "Clear data for all active priority channels");
@@ -92,12 +94,12 @@ int main(int argc, char * argv[])
Option & argConfigSet = parser.add<Option> ('W', "configSet", "Write to the actual loaded configuration file. Should be a Json object string.");
// parse all _options
parser.process(app);
parser.process(app);
// check if we need to display the usage. exit if we do.
if (parser.isSet(argHelp))
{
parser.showHelp(0);
parser.showHelp(0);
}
// check if at least one of the available color transforms is set
@@ -106,13 +108,14 @@ int main(int argc, char * argv[])
bool colorModding = colorTransform || colorAdjust;
// check that exactly one command was given
int commandCount = count({parser.isSet(argColor), parser.isSet(argImage), parser.isSet(argEffect), parser.isSet(argServerInfo), parser.isSet(argClear), parser.isSet(argClearAll), parser.isSet(argEnableComponent), parser.isSet(argDisableComponent), colorModding, parser.isSet(argSource), parser.isSet(argSourceAuto), parser.isSet(argSourceOff), parser.isSet(argConfigGet), parser.isSet(argSchemaGet), parser.isSet(argConfigSet)});
int commandCount = count({parser.isSet(argColor), parser.isSet(argImage), parser.isSet(argEffect), parser.isSet(argCreateEffect), parser.isSet(argServerInfo), parser.isSet(argClear), parser.isSet(argClearAll), parser.isSet(argEnableComponent), parser.isSet(argDisableComponent), colorModding, parser.isSet(argSource), parser.isSet(argSourceAuto), parser.isSet(argSourceOff), parser.isSet(argConfigGet), parser.isSet(argSchemaGet), parser.isSet(argConfigSet)});
if (commandCount != 1)
{
qWarning() << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:";
showHelp(argColor);
showHelp(argImage);
showHelp(argEffect);
showHelp(argEffect);
showHelp(argCreateEffect);
showHelp(argServerInfo);
showHelp(argClear);
showHelp(argClearAll);
@@ -156,6 +159,10 @@ int main(int argc, char * argv[])
{
connection.setEffect(argEffect.value(parser), argEffectArgs.value(parser), argPriority.getInt(parser), argDuration.getInt(parser));
}
else if (parser.isSet(argCreateEffect))
{
connection.createEffect(argCreateEffect.value(parser), argEffectFile.value(parser), argEffectArgs.value(parser));
}
else if (parser.isSet(argServerInfo))
{
QString info = connection.getServerInfo();