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: private:
const int _updateInterval_ms; const int _updateInterval_ms;
const int _timeout_ms; const int _timeout_ms;
const int _priority;
QTimer _timer; QTimer _timer;

View File

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

View File

@ -10,12 +10,16 @@
// Qt includes // Qt includes
#include <QResource> #include <QResource>
// hyperion util includes
#include "utils/RgbColor.h"
// project includes // project includes
#include "JsonClientConnection.h" #include "JsonClientConnection.h"
JsonClientConnection::JsonClientConnection(QTcpSocket *socket) : JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperion) :
QObject(), QObject(),
_socket(socket), _socket(socket),
_hyperion(hyperion),
_receiveBuffer() _receiveBuffer()
{ {
// connect internal signals and slots // connect internal signals and slots
@ -97,7 +101,20 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
void JsonClientConnection::handleColorCommand(const Json::Value &message) 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) void JsonClientConnection::handleImageCommand(const Json::Value &message)
@ -137,6 +154,16 @@ void JsonClientConnection::sendMessage(const Json::Value &message)
_socket->write(serializedReply.data(), serializedReply.length()); _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) void JsonClientConnection::sendErrorReply(const std::string &error)
{ {
// create reply // create reply

View File

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

View File

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