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

@ -39,7 +39,7 @@ public slots:
private:
const int _updateInterval_ms;
const int _timeout_ms;
const int _priority;
QTimer _timer;

View File

@ -15,6 +15,7 @@
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, Hyperion * hyperion) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_priority(128),
_timer(),
_image(grabWidth, grabHeight),
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
@ -52,7 +53,6 @@ void DispmanxWrapper::action()
_processor->process(_image, _ledColors);
const int _priority = 100;
_hyperion->setValue(_priority, _ledColors, _timeout_ms);
}
void DispmanxWrapper::stop()

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

View File

@ -10,6 +10,9 @@
// jsoncpp includes
#include <json/json.h>
// Hyperion includes
#include <hyperion/Hyperion.h>
// util includes
#include <utils/jsonschema/JsonSchemaChecker.h>
@ -18,7 +21,7 @@ class JsonClientConnection : public QObject
Q_OBJECT
public:
JsonClientConnection(QTcpSocket * socket);
JsonClientConnection(QTcpSocket * socket, Hyperion * hyperion);
~JsonClientConnection();
signals:
@ -39,6 +42,7 @@ private:
void handleNotImplemented();
void sendMessage(const Json::Value & message);
void sendSuccessReply();
void sendErrorReply(const std::string & error);
private:
@ -47,5 +51,7 @@ private:
private:
QTcpSocket * _socket;
Hyperion * _hyperion;
QByteArray _receiveBuffer;
};

View File

@ -42,7 +42,7 @@ void JsonServer::newConnection()
if (socket != nullptr)
{
std::cout << "New json connection" << std::endl;
JsonClientConnection * connection = new JsonClientConnection(socket);
JsonClientConnection * connection = new JsonClientConnection(socket, _hyperion);
_openConnections.insert(connection);
// register slot for cleaning up after the connection closed