Implemented set transform for the json server

This commit is contained in:
johan 2013-08-19 19:57:35 +02:00
parent 0a9bbe86a4
commit cb38baa985
3 changed files with 86 additions and 1 deletions

View File

@ -21,6 +21,16 @@ class Hyperion : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Color
{
RED, GREEN, BLUE
};
enum Transform
{
THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL
};
static LedString createLedString(const Json::Value& ledsConfig); static LedString createLedString(const Json::Value& ledsConfig);
Hyperion(const Json::Value& jsonConfig); Hyperion(const Json::Value& jsonConfig);
@ -33,6 +43,8 @@ public:
void setColors(int priority, std::vector<RgbColor> &ledColors, const int timeout_ms); void setColors(int priority, std::vector<RgbColor> &ledColors, const int timeout_ms);
void setTransform(Transform transform, Color color, double value);
void clear(int priority); void clear(int priority);
void clearall(); void clearall();

View File

@ -145,6 +145,45 @@ void Hyperion::setColors(int priority, std::vector<RgbColor>& ledColors, const i
} }
} }
void Hyperion::setTransform(Hyperion::Transform transform, Hyperion::Color color, double value)
{
// select the transform of the requested color
ColorTransform * t = nullptr;
switch (color)
{
case RED:
t = _redTransform;
break;
case GREEN:
t = _greenTransform;
break;
case BLUE:
t = _blueTransform;
break;
default:
assert(false);
}
// set transform value
switch (transform)
{
case THRESHOLD:
t->setThreshold(value);
break;
case GAMMA:
t->setGamma(value);
break;
case BLACKLEVEL:
t->setBlacklevel(value);
break;
case WHITELEVEL:
t->setWhitelevel(value);
break;
default:
assert(false);
}
}
void Hyperion::clear(int priority) void Hyperion::clear(int priority)
{ {
if (_muxer.hasPriority(priority)) if (_muxer.hasPriority(priority))

View File

@ -175,7 +175,41 @@ void JsonClientConnection::handleClearallCommand(const Json::Value &)
void JsonClientConnection::handleTransformCommand(const Json::Value &message) void JsonClientConnection::handleTransformCommand(const Json::Value &message)
{ {
handleNotImplemented(); const Json::Value & transform = message["transform"];
if (transform.isMember("threshold"))
{
const Json::Value & threshold = transform["threshold"];
_hyperion->setTransform(Hyperion::THRESHOLD, Hyperion::RED, threshold[0u].asDouble());
_hyperion->setTransform(Hyperion::THRESHOLD, Hyperion::GREEN, threshold[1u].asDouble());
_hyperion->setTransform(Hyperion::THRESHOLD, Hyperion::BLUE, threshold[2u].asDouble());
}
if (transform.isMember("gamma"))
{
const Json::Value & threshold = transform["gamma"];
_hyperion->setTransform(Hyperion::GAMMA, Hyperion::RED, threshold[0u].asDouble());
_hyperion->setTransform(Hyperion::GAMMA, Hyperion::GREEN, threshold[1u].asDouble());
_hyperion->setTransform(Hyperion::GAMMA, Hyperion::BLUE, threshold[2u].asDouble());
}
if (transform.isMember("blacklevel"))
{
const Json::Value & threshold = transform["blacklevel"];
_hyperion->setTransform(Hyperion::BLACKLEVEL, Hyperion::RED, threshold[0u].asDouble());
_hyperion->setTransform(Hyperion::BLACKLEVEL, Hyperion::GREEN, threshold[1u].asDouble());
_hyperion->setTransform(Hyperion::BLACKLEVEL, Hyperion::BLUE, threshold[2u].asDouble());
}
if (transform.isMember("whitelevel"))
{
const Json::Value & threshold = transform["whitelevel"];
_hyperion->setTransform(Hyperion::WHITELEVEL, Hyperion::RED, threshold[0u].asDouble());
_hyperion->setTransform(Hyperion::WHITELEVEL, Hyperion::GREEN, threshold[1u].asDouble());
_hyperion->setTransform(Hyperion::WHITELEVEL, Hyperion::BLUE, threshold[2u].asDouble());
}
sendSuccessReply();
} }
void JsonClientConnection::handleNotImplemented() void JsonClientConnection::handleNotImplemented()