mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Clean up code
Use tabs for indenting to make someone happy...
This commit is contained in:
parent
463e7626b9
commit
a04af1242c
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/// Simple structure to contain the values of a color transformation
|
||||||
struct ColorTransformValues
|
struct ColorTransformValues
|
||||||
{
|
{
|
||||||
double valueRed;
|
double valueRed;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
// stl includes
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
// hyperion-remote includes
|
||||||
#include "Connection.h"
|
#include "Connection.h"
|
||||||
|
|
||||||
Connection::Connection(const std::string & a, bool printJson) :
|
Connection::Connection(const std::string & a, bool printJson) :
|
||||||
@ -69,9 +71,9 @@ bool Connection::setTransform(ColorTransformValues *threshold, ColorTransformVal
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connection::sendMessage(const Json::Value & message)
|
Json::Value Connection::sendMessage(const Json::Value & message)
|
||||||
{
|
{
|
||||||
// rpint if requested
|
// print command if requested
|
||||||
if (_printJson)
|
if (_printJson)
|
||||||
{
|
{
|
||||||
std::cout << "Command: " << message << std::endl;
|
std::cout << "Command: " << message << std::endl;
|
||||||
@ -103,11 +105,12 @@ bool Connection::sendMessage(const Json::Value & message)
|
|||||||
throw std::runtime_error("Error while parsing reply:" + serializedReply);
|
throw std::runtime_error("Error while parsing reply:" + serializedReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print reply if requested
|
||||||
if (_printJson)
|
if (_printJson)
|
||||||
{
|
{
|
||||||
std::cout << "Reply:" << reply << std::endl;
|
std::cout << "Reply:" << reply << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +1,48 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// stl includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
// jsoncpp includes
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
|
// hyperion-remote includes
|
||||||
#include "ColorTransformValues.h"
|
#include "ColorTransformValues.h"
|
||||||
|
|
||||||
|
/// Connection class to setup an connection to the hyperion server and execute commands
|
||||||
class Connection
|
class Connection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Connection(const std::string & address, bool printJson);
|
Connection(const std::string & address, bool printJson);
|
||||||
~Connection();
|
~Connection();
|
||||||
|
|
||||||
|
/// Set all leds to the specified color
|
||||||
bool setColor(QColor color, int priority, int duration);
|
bool setColor(QColor color, int priority, int duration);
|
||||||
|
|
||||||
|
/// Set the leds according to the given image (assume the image is stretched to the display size)
|
||||||
bool setImage(QImage image, int priority, int duration);
|
bool setImage(QImage image, int priority, int duration);
|
||||||
|
|
||||||
|
/// Retrieve a list of all occupied priority channels
|
||||||
bool listPriorities();
|
bool listPriorities();
|
||||||
|
|
||||||
|
/// Clear the given priority channel
|
||||||
bool clear(int priority);
|
bool clear(int priority);
|
||||||
|
|
||||||
|
/// Clear all priority channels
|
||||||
bool clearAll();
|
bool clearAll();
|
||||||
|
|
||||||
|
/// Set the color transform of the leds
|
||||||
|
/// Note that providing a NULL will leave the settings on the server unchanged
|
||||||
bool setTransform(ColorTransformValues * threshold, ColorTransformValues * gamma, ColorTransformValues * blacklevel, ColorTransformValues * whitelevel);
|
bool setTransform(ColorTransformValues * threshold, ColorTransformValues * gamma, ColorTransformValues * blacklevel, ColorTransformValues * whitelevel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool sendMessage(const Json::Value & message);
|
/// Send a json command message and receive its reply
|
||||||
|
Json::Value sendMessage(const Json::Value & message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _printJson;
|
bool _printJson;
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
|
// getoptPlusPLus includes
|
||||||
#include <getoptPlusPlus/getoptpp.h>
|
#include <getoptPlusPlus/getoptpp.h>
|
||||||
|
|
||||||
|
// hyperion-remote includes
|
||||||
#include "ColorTransformValues.h"
|
#include "ColorTransformValues.h"
|
||||||
|
|
||||||
|
|
||||||
typedef vlofgren::PODParameter<QColor> ColorParameter;
|
typedef vlofgren::PODParameter<QColor> ColorParameter;
|
||||||
typedef vlofgren::PODParameter<QImage> ImageParameter;
|
typedef vlofgren::PODParameter<QImage> ImageParameter;
|
||||||
typedef vlofgren::PODParameter<ColorTransformValues> TransformParameter;
|
typedef vlofgren::PODParameter<ColorTransformValues> TransformParameter;
|
||||||
|
|
||||||
|
|
||||||
namespace vlofgren {
|
namespace vlofgren {
|
||||||
template<>
|
template<>
|
||||||
QColor ColorParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
QColor ColorParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
|
// stl includes
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
// getoptPlusPLus includes
|
||||||
#include <getoptPlusPlus/getoptpp.h>
|
#include <getoptPlusPlus/getoptpp.h>
|
||||||
|
|
||||||
|
// hyperion-remote include
|
||||||
#include "CustomParameter.h"
|
#include "CustomParameter.h"
|
||||||
#include "Connection.h"
|
#include "Connection.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace vlofgren;
|
using namespace vlofgren;
|
||||||
|
|
||||||
|
/// Count the number of true values in a list of booleans
|
||||||
int count(std::initializer_list<bool> values)
|
int count(std::initializer_list<bool> values)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (auto& value : values) {
|
for (bool value : values) {
|
||||||
if (value)
|
if (value)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@ -26,10 +30,11 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// some settings
|
// some default settings
|
||||||
QString defaultServerAddress = "localhost:19444";
|
QString defaultServerAddress = "localhost:19444";
|
||||||
int defaultPriority = 100;
|
int defaultPriority = 100;
|
||||||
|
|
||||||
|
// create the option parser and initialize all parameters
|
||||||
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
||||||
ParameterSet & parameters = optionParser.getParameters();
|
ParameterSet & parameters = optionParser.getParameters();
|
||||||
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData());
|
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData());
|
||||||
@ -47,41 +52,35 @@ int main(int argc, char * argv[])
|
|||||||
SwitchParameter<> & argPrint = parameters.add<SwitchParameter<> >(0x0, "print" , "Print the json input and output messages on stdout");
|
SwitchParameter<> & argPrint = parameters.add<SwitchParameter<> >(0x0, "print" , "Print the json input and output messages on stdout");
|
||||||
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<> >('h', "help" , "Show this help message and exit");
|
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<> >('h', "help" , "Show this help message and exit");
|
||||||
|
|
||||||
|
// set the default values
|
||||||
argAddress.setDefault(defaultServerAddress.toStdString());
|
argAddress.setDefault(defaultServerAddress.toStdString());
|
||||||
argPriority.setDefault(defaultPriority);
|
argPriority.setDefault(defaultPriority);
|
||||||
argDuration.setDefault(-1);
|
argDuration.setDefault(-1);
|
||||||
|
|
||||||
// parse the options
|
// parse all options
|
||||||
optionParser.parse(argc, const_cast<const char **>(argv));
|
optionParser.parse(argc, const_cast<const char **>(argv));
|
||||||
|
|
||||||
// check if we need to display the usage
|
// check if we need to display the usage. exit if we do.
|
||||||
if (argHelp.isSet())
|
if (argHelp.isSet())
|
||||||
{
|
{
|
||||||
optionParser.usage();
|
optionParser.usage();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a color transform is set
|
// check if at least one of the available color transforms is set
|
||||||
bool colorTransform = argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet();
|
bool colorTransform = argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet();
|
||||||
|
|
||||||
// check if exactly one command was given
|
// check that exactly one command was given
|
||||||
int commandCount = count({argColor.isSet(), argImage.isSet(), argList.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform});
|
int commandCount = count({argColor.isSet(), argImage.isSet(), argList.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform});
|
||||||
if (commandCount != 1)
|
if (commandCount != 1)
|
||||||
{
|
{
|
||||||
if (commandCount == 0)
|
std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl;
|
||||||
{
|
|
||||||
std::cerr << "No command found. Provide one of the following options:" << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Multiple commands found. Provide one of the following options:" << std::endl;
|
|
||||||
}
|
|
||||||
std::cerr << " " << argColor.usageLine() << std::endl;
|
std::cerr << " " << argColor.usageLine() << std::endl;
|
||||||
std::cerr << " " << argImage.usageLine() << std::endl;
|
std::cerr << " " << argImage.usageLine() << std::endl;
|
||||||
std::cerr << " " << argList.usageLine() << std::endl;
|
std::cerr << " " << argList.usageLine() << std::endl;
|
||||||
std::cerr << " " << argClear.usageLine() << std::endl;
|
std::cerr << " " << argClear.usageLine() << std::endl;
|
||||||
std::cerr << " " << argClearAll.usageLine() << std::endl;
|
std::cerr << " " << argClearAll.usageLine() << std::endl;
|
||||||
std::cerr << "or one or more of the color transformations:" << std::endl;
|
std::cerr << "or one or more of the available color transformations:" << std::endl;
|
||||||
std::cerr << " " << argThreshold.usageLine() << std::endl;
|
std::cerr << " " << argThreshold.usageLine() << std::endl;
|
||||||
std::cerr << " " << argGamma.usageLine() << std::endl;
|
std::cerr << " " << argGamma.usageLine() << std::endl;
|
||||||
std::cerr << " " << argBlacklevel.usageLine() << std::endl;
|
std::cerr << " " << argBlacklevel.usageLine() << std::endl;
|
||||||
@ -89,7 +88,7 @@ int main(int argc, char * argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the connection
|
// create the connection to the hyperion server
|
||||||
Connection connection(argAddress.getValue(), argPrint.isSet());
|
Connection connection(argAddress.getValue(), argPrint.isSet());
|
||||||
|
|
||||||
// now execute the given command
|
// now execute the given command
|
||||||
@ -129,6 +128,7 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error & e)
|
catch (const std::runtime_error & e)
|
||||||
{
|
{
|
||||||
|
// An error occured. Display error and quit
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user