set color on json connection implemented

This commit is contained in:
johan
2013-08-18 12:21:07 +02:00
parent 46076998a0
commit 638d5aa424
5 changed files with 39 additions and 6 deletions

View File

@@ -10,12 +10,16 @@
// Qt includes
#include <QResource>
// hyperion util includes
#include "utils/RgbColor.h"
// project includes
#include "JsonClientConnection.h"
JsonClientConnection::JsonClientConnection(QTcpSocket *socket) :
JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperion) :
QObject(),
_socket(socket),
_hyperion(hyperion),
_receiveBuffer()
{
// connect internal signals and slots
@@ -97,7 +101,20 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
void JsonClientConnection::handleColorCommand(const Json::Value &message)
{
handleNotImplemented();
// extract parameters
int priority = message["priority"].asInt();
int duration = message.get("duration", -1).asInt();
RgbColor color = {message["color"][0u].asInt(), message["color"][1u].asInt(), message["color"][2u].asInt()};
// create led output
std::vector<RgbColor> ledColors(_hyperion->getLedCount(), color);
// set output
_hyperion->setValue(priority, ledColors, duration);
// send reply
sendSuccessReply();
}
void JsonClientConnection::handleImageCommand(const Json::Value &message)
@@ -137,6 +154,16 @@ void JsonClientConnection::sendMessage(const Json::Value &message)
_socket->write(serializedReply.data(), serializedReply.length());
}
void JsonClientConnection::sendSuccessReply()
{
// create reply
Json::Value reply;
reply["success"] = true;
// send reply
sendMessage(reply);
}
void JsonClientConnection::sendErrorReply(const std::string &error)
{
// create reply