diff --git a/include/dispmanx-grabber/DispmanxWrapper.h b/include/dispmanx-grabber/DispmanxWrapper.h index 18b6370b..134c30cd 100644 --- a/include/dispmanx-grabber/DispmanxWrapper.h +++ b/include/dispmanx-grabber/DispmanxWrapper.h @@ -39,7 +39,7 @@ public slots: private: const int _updateInterval_ms; const int _timeout_ms; - + const int _priority; QTimer _timer; diff --git a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp index 32de71a9..413159ed 100644 --- a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp +++ b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp @@ -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() diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 9a93b46e..c9cc1b4f 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -10,12 +10,16 @@ // Qt includes #include +// 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 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 diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index e022742f..4d00dfe7 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -10,6 +10,9 @@ // jsoncpp includes #include +// Hyperion includes +#include + // util includes #include @@ -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; }; diff --git a/libsrc/jsonserver/JsonServer.cpp b/libsrc/jsonserver/JsonServer.cpp index f9f898c8..06a56221 100644 --- a/libsrc/jsonserver/JsonServer.cpp +++ b/libsrc/jsonserver/JsonServer.cpp @@ -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