mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Manual input source select via json (#143)
* implement manual source select via json interface fix schema error * refactoring * add visible value to all listed prios
This commit is contained in:
@@ -555,6 +555,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
|
||||
, _timer()
|
||||
, _log(Logger::getInstance("Core"))
|
||||
, _hwLedCount(_ledString.leds().size())
|
||||
, _sourceAutoSelectEnabled(true)
|
||||
{
|
||||
if (!_raw2ledAdjustment->verifyAdjustments())
|
||||
{
|
||||
@@ -643,6 +644,31 @@ void Hyperion::unRegisterPriority(const std::string name)
|
||||
_priorityRegister.erase(name);
|
||||
}
|
||||
|
||||
void Hyperion::setSourceAutoSelectEnabled(bool enabled)
|
||||
{
|
||||
_sourceAutoSelectEnabled = enabled;
|
||||
if (! _sourceAutoSelectEnabled)
|
||||
{
|
||||
setCurrentSourcePriority(_muxer.getCurrentPriority());
|
||||
}
|
||||
DebugIf( !_sourceAutoSelectEnabled, _log, "source auto select is disabled");
|
||||
InfoIf(_sourceAutoSelectEnabled, _log, "set current input source to auto select");
|
||||
}
|
||||
|
||||
bool Hyperion::setCurrentSourcePriority(int priority )
|
||||
{
|
||||
bool priorityValid = _muxer.hasPriority(priority);
|
||||
if (priorityValid)
|
||||
{
|
||||
DebugIf(_sourceAutoSelectEnabled, _log, "source auto select is disabled");
|
||||
_sourceAutoSelectEnabled = false;
|
||||
_currentSourcePriority = priority;
|
||||
Info(_log, "set current input source to priority channel %d", _currentSourcePriority);
|
||||
}
|
||||
|
||||
return priorityValid;
|
||||
}
|
||||
|
||||
|
||||
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects)
|
||||
{
|
||||
@@ -758,7 +784,8 @@ void Hyperion::clearall()
|
||||
|
||||
int Hyperion::getCurrentPriority() const
|
||||
{
|
||||
return _muxer.getCurrentPriority();
|
||||
|
||||
return _sourceAutoSelectEnabled || !_muxer.hasPriority(_currentSourcePriority) ? _muxer.getCurrentPriority() : _currentSourcePriority;
|
||||
}
|
||||
|
||||
QList<int> Hyperion::getActivePriorities() const
|
||||
@@ -797,8 +824,8 @@ void Hyperion::update()
|
||||
_muxer.setCurrentTime(QDateTime::currentMSecsSinceEpoch());
|
||||
|
||||
// Obtain the current priority channel
|
||||
int priority = _muxer.getCurrentPriority();
|
||||
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||
int priority = _sourceAutoSelectEnabled || !_muxer.hasPriority(_currentSourcePriority) ? _muxer.getCurrentPriority() : _currentSourcePriority;
|
||||
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||
|
||||
// copy ledcolors to local buffer
|
||||
_ledBuffer.reserve(_hwLedCount);
|
||||
|
@@ -6,10 +6,10 @@
|
||||
// Hyperion includes
|
||||
#include <hyperion/PriorityMuxer.h>
|
||||
|
||||
PriorityMuxer::PriorityMuxer(int ledCount) :
|
||||
_currentPriority(LOWEST_PRIORITY),
|
||||
_activeInputs(),
|
||||
_lowestPriorityInfo()
|
||||
PriorityMuxer::PriorityMuxer(int ledCount)
|
||||
: _currentPriority(LOWEST_PRIORITY)
|
||||
, _activeInputs()
|
||||
, _lowestPriorityInfo()
|
||||
{
|
||||
_lowestPriorityInfo.priority = LOWEST_PRIORITY;
|
||||
_lowestPriorityInfo.timeoutTime_ms = -1;
|
||||
@@ -46,6 +46,7 @@ const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority)
|
||||
auto elemIt = _activeInputs.find(priority);
|
||||
if (elemIt == _activeInputs.end())
|
||||
{
|
||||
std::cout << "error " << priority << std::endl;
|
||||
throw std::runtime_error("HYPERION (prioritymux) ERROR: no such priority");
|
||||
}
|
||||
return elemIt.value();
|
||||
|
@@ -58,7 +58,10 @@
|
||||
"required" : true,
|
||||
"properties":
|
||||
{
|
||||
"channelAdjustment_enable" : "boolean",
|
||||
"channelAdjustment_enable" :
|
||||
{
|
||||
"type" : "boolean"
|
||||
},
|
||||
"channelAdjustment" :
|
||||
{
|
||||
"type" : "array",
|
||||
@@ -173,7 +176,10 @@
|
||||
"additionalProperties" : false
|
||||
}
|
||||
},
|
||||
"temperature_enable" : "boolean",
|
||||
"temperature_enable" :
|
||||
{
|
||||
"type" : "boolean"
|
||||
},
|
||||
"temperature" :
|
||||
{
|
||||
"type" : "array",
|
||||
@@ -228,7 +234,10 @@
|
||||
"additionalProperties" : false
|
||||
}
|
||||
},
|
||||
"transform_enable" : "boolean",
|
||||
"transform_enable" :
|
||||
{
|
||||
"type" : "boolean"
|
||||
},
|
||||
"transform" :
|
||||
{
|
||||
"type" : "array",
|
||||
|
@@ -27,14 +27,14 @@
|
||||
// project includes
|
||||
#include "JsonClientConnection.h"
|
||||
|
||||
JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperion) :
|
||||
QObject(),
|
||||
_socket(socket),
|
||||
_imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_hyperion(hyperion),
|
||||
_receiveBuffer(),
|
||||
_webSocketHandshakeDone(false),
|
||||
_log(Logger::getInstance("JSONCLIENTCONNECTION"))
|
||||
JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
|
||||
: QObject()
|
||||
, _socket(socket)
|
||||
, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _receiveBuffer()
|
||||
, _webSocketHandshakeDone(false)
|
||||
, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
|
||||
{
|
||||
// connect internal signals and slots
|
||||
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
|
||||
@@ -256,6 +256,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
||||
handleTemperatureCommand(message);
|
||||
else if (command == "adjustment")
|
||||
handleAdjustmentCommand(message);
|
||||
else if (command == "sourceselect")
|
||||
handleSourceSelectCommand(message);
|
||||
else
|
||||
handleNotImplemented();
|
||||
}
|
||||
@@ -388,7 +390,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
uint64_t now = QDateTime::currentMSecsSinceEpoch();
|
||||
QList<int> activePriorities = _hyperion->getActivePriorities();
|
||||
Hyperion::PriorityRegister priorityRegister = _hyperion->getPriorityRegister();
|
||||
|
||||
int currentPriority = _hyperion->getCurrentPriority();
|
||||
foreach (int priority, activePriorities) {
|
||||
const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority);
|
||||
Json::Value & item = priorities[priorities.size()];
|
||||
@@ -399,7 +401,8 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
}
|
||||
|
||||
item["owner"] = "unknown";
|
||||
item["active"] = "true";
|
||||
item["active"] = true;
|
||||
item["visible"] = (priority == currentPriority);
|
||||
foreach(auto const &entry, priorityRegister)
|
||||
{
|
||||
if (entry.second == priority)
|
||||
@@ -414,7 +417,8 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
{
|
||||
Json::Value & item = priorities[priorities.size()];
|
||||
item["priority"] = entry.second;
|
||||
item["active"] = "false";
|
||||
item["active"] = false;
|
||||
item["visible"] = false;
|
||||
item["owner"] = entry.first;
|
||||
}
|
||||
|
||||
@@ -773,7 +777,30 @@ void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message)
|
||||
|
||||
sendSuccessReply();
|
||||
}
|
||||
|
||||
|
||||
void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message)
|
||||
{
|
||||
bool success = false;
|
||||
if (message.get("auto",false).asBool())
|
||||
{
|
||||
_hyperion->setSourceAutoSelectEnabled(true);
|
||||
success = true;
|
||||
}
|
||||
else if (message.isMember("priority"))
|
||||
{
|
||||
success = _hyperion->setCurrentSourcePriority(message["priority"].asInt());
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
sendSuccessReply();
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("setting current priority failed");
|
||||
}
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleNotImplemented()
|
||||
{
|
||||
sendErrorReply("Command not implemented");
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
/// @param socket The Socket object for this connection
|
||||
/// @param hyperion The Hyperion server
|
||||
///
|
||||
JsonClientConnection(QTcpSocket * socket, Hyperion * hyperion);
|
||||
JsonClientConnection(QTcpSocket * socket);
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
@@ -128,6 +128,13 @@ private:
|
||||
///
|
||||
void handleAdjustmentCommand(const Json::Value & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON SourceSelect message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleSourceSelectCommand(const Json::Value & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON message of unknown type
|
||||
///
|
||||
@@ -195,6 +202,7 @@ private:
|
||||
|
||||
/// used for WebSocket detection and connection handling
|
||||
bool _webSocketHandshakeDone;
|
||||
|
||||
|
||||
/// the logger instance
|
||||
Logger * _log;
|
||||
};
|
||||
|
@@ -11,5 +11,6 @@
|
||||
<file alias="schema-temperature">schema/schema-temperature.json</file>
|
||||
<file alias="schema-adjustment">schema/schema-adjustment.json</file>
|
||||
<file alias="schema-effect">schema/schema-effect.json</file>
|
||||
<file alias="schema-sourceselect">schema/schema-sourceselect.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -5,19 +5,18 @@
|
||||
#include <jsonserver/JsonServer.h>
|
||||
#include "JsonClientConnection.h"
|
||||
|
||||
JsonServer::JsonServer(uint16_t port) :
|
||||
QObject(),
|
||||
_hyperion(Hyperion::getInstance()),
|
||||
_server(),
|
||||
_openConnections(),
|
||||
_log(Logger::getInstance("JSONSERVER"))
|
||||
JsonServer::JsonServer(uint16_t port)
|
||||
: QObject()
|
||||
, _server()
|
||||
, _openConnections()
|
||||
, _log(Logger::getInstance("JSONSERVER"))
|
||||
{
|
||||
if (!_server.listen(QHostAddress::Any, port))
|
||||
{
|
||||
throw std::runtime_error("JSONSERVER ERROR: could not bind to port");
|
||||
}
|
||||
|
||||
QList<MessageForwarder::JsonSlaveAddress> list = _hyperion->getForwarder()->getJsonSlaves();
|
||||
QList<MessageForwarder::JsonSlaveAddress> list = Hyperion::getInstance()->getForwarder()->getJsonSlaves();
|
||||
for ( int i=0; i<list.size(); i++ )
|
||||
{
|
||||
if ( list.at(i).addr == QHostAddress::LocalHost && list.at(i).port == port ) {
|
||||
@@ -52,7 +51,7 @@ void JsonServer::newConnection()
|
||||
if (socket != nullptr)
|
||||
{
|
||||
Debug(_log, "New connection");
|
||||
JsonClientConnection * connection = new JsonClientConnection(socket, _hyperion);
|
||||
JsonClientConnection * connection = new JsonClientConnection(socket);
|
||||
_openConnections.insert(connection);
|
||||
|
||||
// register slot for cleaning up after the connection closed
|
||||
|
18
libsrc/jsonserver/schema/schema-sourceselect.json
Normal file
18
libsrc/jsonserver/schema/schema-sourceselect.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":false,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["sourceselect"]
|
||||
},
|
||||
"priority": {
|
||||
"type": "integer"
|
||||
},
|
||||
"auto": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment"]
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user