From cb38baa985d96bfa64ea1bef0f391dc337daa803 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 19 Aug 2013 19:57:35 +0200 Subject: [PATCH] Implemented set transform for the json server --- include/hyperion/Hyperion.h | 12 +++++++ libsrc/hyperion/Hyperion.cpp | 39 ++++++++++++++++++++++ libsrc/jsonserver/JsonClientConnection.cpp | 36 +++++++++++++++++++- 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 7d78ed18..4a41b1fc 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -21,6 +21,16 @@ class Hyperion : public QObject { Q_OBJECT public: + enum Color + { + RED, GREEN, BLUE + }; + + enum Transform + { + THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL + }; + static LedString createLedString(const Json::Value& ledsConfig); Hyperion(const Json::Value& jsonConfig); @@ -33,6 +43,8 @@ public: void setColors(int priority, std::vector &ledColors, const int timeout_ms); + void setTransform(Transform transform, Color color, double value); + void clear(int priority); void clearall(); diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 64c1db85..60e1c4dd 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -145,6 +145,45 @@ void Hyperion::setColors(int priority, std::vector& 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) { if (_muxer.hasPriority(priority)) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 25fa7583..1bbcbf97 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -175,7 +175,41 @@ void JsonClientConnection::handleClearallCommand(const Json::Value &) 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()