mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Hyperion-remote changed to support multiple colors in the setColor command
Former-commit-id: f0acda054056d6fa937e9cbd2b22686979911bc9
This commit is contained in:
parent
cf7f66bc40
commit
c11808878f
@ -11,7 +11,7 @@
|
|||||||
#include "ColorTransformValues.h"
|
#include "ColorTransformValues.h"
|
||||||
|
|
||||||
/// Data parameter for a color
|
/// Data parameter for a color
|
||||||
typedef vlofgren::PODParameter<QColor> ColorParameter;
|
typedef vlofgren::PODParameter<std::vector<QColor>> ColorParameter;
|
||||||
|
|
||||||
/// Data parameter for an image
|
/// Data parameter for an image
|
||||||
typedef vlofgren::PODParameter<QImage> ImageParameter;
|
typedef vlofgren::PODParameter<QImage> ImageParameter;
|
||||||
@ -21,40 +21,54 @@ typedef vlofgren::PODParameter<ColorTransformValues> TransformParameter;
|
|||||||
|
|
||||||
namespace vlofgren {
|
namespace vlofgren {
|
||||||
///
|
///
|
||||||
/// Translates a string (as passed on the commandline) to a color
|
/// Translates a string (as passed on the commandline) to a vector of colors
|
||||||
///
|
///
|
||||||
/// @param[in] s The string (as passed on the commandline)
|
/// @param[in] s The string (as passed on the commandline)
|
||||||
///
|
///
|
||||||
/// @return The translated color
|
/// @return The translated colors
|
||||||
///
|
///
|
||||||
/// @throws Parameter::ParameterRejected If the string did not result in a color
|
/// @throws Parameter::ParameterRejected If the string did not result in a color
|
||||||
///
|
///
|
||||||
template<>
|
template<>
|
||||||
QColor ColorParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
std::vector<QColor> ColorParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
|
||||||
{
|
{
|
||||||
// Check if we can create the color by name
|
// Check if we can create the color by name
|
||||||
QColor color(s.c_str());
|
QColor color(s.c_str());
|
||||||
if (color.isValid())
|
if (color.isValid())
|
||||||
{
|
{
|
||||||
return color;
|
return std::vector<QColor>{color};
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we can create the color by hex RRGGBB value
|
// check if we can create the color by hex RRGGBB value
|
||||||
if (s.length() == 6 && isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) && isxdigit(s[3]) && isxdigit(s[4]) && isxdigit(s[5]))
|
if (s.length() >= 6u && (s.length()%6) == 0u && std::count_if(s.begin(), s.end(), isxdigit) == s.length())
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
std::vector<QColor> colors;
|
||||||
|
|
||||||
|
for (size_t j = 0; j < s.length()/6; ++j)
|
||||||
|
{
|
||||||
int rgb[3];
|
int rgb[3];
|
||||||
for (int i = 0; i < 3 && ok; ++i)
|
for (int i = 0; i < 3 && ok; ++i)
|
||||||
{
|
{
|
||||||
QString colorComponent(s.substr(2*i, 2).c_str());
|
QString colorComponent(s.substr(6*j+2*i, 2).c_str());
|
||||||
rgb[i] = colorComponent.toInt(&ok, 16);
|
rgb[i] = colorComponent.toInt(&ok, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
color.setRgb(rgb[0], rgb[1], rgb[2]);
|
||||||
|
colors.push_back(color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if all components parsed succesfully
|
// check if all components parsed succesfully
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
color.setRgb(rgb[0], rgb[1], rgb[2]);
|
return colors;
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +79,7 @@ namespace vlofgren {
|
|||||||
}
|
}
|
||||||
throw Parameter::ParameterRejected(errorMessage.str());
|
throw Parameter::ParameterRejected(errorMessage.str());
|
||||||
|
|
||||||
return color;
|
return std::vector<QColor>{color};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -39,18 +39,21 @@ JsonConnection::~JsonConnection()
|
|||||||
_socket.close();
|
_socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonConnection::setColor(QColor color, int priority, int duration)
|
void JsonConnection::setColor(std::vector<QColor> colors, int priority, int duration)
|
||||||
{
|
{
|
||||||
std::cout << "Set color to " << color.red() << " " << color.green() << " " << color.blue() << std::endl;
|
std::cout << "Set color to " << colors[0].red() << " " << colors[0].green() << " " << colors[0].blue() << (colors.size() > 1 ? " + ..." : "") << std::endl;
|
||||||
|
|
||||||
// create command
|
// create command
|
||||||
Json::Value command;
|
Json::Value command;
|
||||||
command["command"] = "color";
|
command["command"] = "color";
|
||||||
command["priority"] = priority;
|
command["priority"] = priority;
|
||||||
Json::Value & rgbValue = command["color"];
|
Json::Value & rgbValue = command["color"];
|
||||||
rgbValue[0] = color.red();
|
for (const QColor & color : colors)
|
||||||
rgbValue[1] = color.green();
|
{
|
||||||
rgbValue[2] = color.blue();
|
rgbValue.append(color.red());
|
||||||
|
rgbValue.append(color.green());
|
||||||
|
rgbValue.append(color.blue());
|
||||||
|
}
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
{
|
{
|
||||||
command["duration"] = duration;
|
command["duration"] = duration;
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
/// @param priority The priority
|
/// @param priority The priority
|
||||||
/// @param duration The duration in milliseconds
|
/// @param duration The duration in milliseconds
|
||||||
///
|
///
|
||||||
void setColor(QColor color, int priority, int duration);
|
void setColor(std::vector<QColor> color, int priority, int duration);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set the leds according to the given image (assume the image is stretched to the display size)
|
/// Set the leds according to the given image (assume the image is stretched to the display size)
|
||||||
|
@ -40,7 +40,7 @@ int main(int argc, char * argv[])
|
|||||||
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());
|
||||||
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData());
|
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData());
|
||||||
IntParameter & argDuration = parameters.add<IntParameter> ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]");
|
IntParameter & argDuration = parameters.add<IntParameter> ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]");
|
||||||
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. The color may be repeated multiple time like: RRGGBBRRGGBB)");
|
||||||
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.");
|
StringParameter & argEffectArgs = parameters.add<StringParameter> (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string.");
|
||||||
|
Loading…
Reference in New Issue
Block a user