Details coming soon.

This commit is contained in:
Paulchen-Panther
2018-12-27 23:11:32 +01:00
parent e3be03ea73
commit d762aa2f3e
186 changed files with 6156 additions and 5444 deletions

View File

@@ -15,8 +15,8 @@
#include <QHostInfo>
// hyperion util includes
#include "hyperion/ImageProcessorFactory.h"
#include "hyperion/ImageProcessor.h"
//#include "hyperion/ImageProcessorFactory.h"
//#include "hyperion/ImageProcessor.h"
#include "utils/ColorRgb.h"
#include "HyperionConfig.h"
@@ -27,7 +27,7 @@ BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, const int
: QObject()
, _locale(QLocale::C)
, _socket(socket)
, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
//, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
, _hyperion(Hyperion::getInstance())
, _receiveBuffer()
, _priority(priority)
@@ -167,7 +167,7 @@ void BoblightClientConnection::handleMessage(const QString & message)
// send current color values to hyperion if this is the last led assuming leds values are send in order of id
if ((ledIndex == _ledColors.size() -1) && _priority < 255)
{
_hyperion->setColors(_priority, _ledColors, -1, true, hyperion::COMP_BOBLIGHTSERVER, _clientAddress);
_hyperion->setInput(_priority, _ledColors);
}
return;
@@ -205,7 +205,7 @@ void BoblightClientConnection::handleMessage(const QString & message)
// send current color values to hyperion
if (_priority < 255)
{
_hyperion->setColors(_priority, _ledColors, -1, true, hyperion::COMP_BOBLIGHTSERVER, _clientAddress);
_hyperion->setInput(_priority, _ledColors);
}
return;
}
@@ -227,11 +227,11 @@ void BoblightClientConnection::sendLightMessage()
int n = snprintf(buffer, sizeof(buffer), "lights %d\n", _hyperion->getLedCount());
sendMessage(QByteArray(buffer, n));
double h0, h1, v0, v1;
//double h0, h1, v0, v1;
for (unsigned i = 0; i < _hyperion->getLedCount(); ++i)
{
_imageProcessor->getScanParameters(i, h0, h1, v0, v1);
n = snprintf(buffer, sizeof(buffer), "light %03d scan %f %f %f %f\n", i, 100*v0, 100*v1, 100*h0, 100*h1);
sendMessage(QByteArray(buffer, n));
//_imageProcessor->getScanParameters(i, h0, h1, v0, v1);
//n = snprintf(buffer, sizeof(buffer), "light %03d scan %f %f %f %f\n", i, 100*v0, 100*v1, 100*h0, 100*h1);
//sendMessage(QByteArray(buffer, n));
}
}

View File

@@ -9,8 +9,6 @@
#include <hyperion/Hyperion.h>
#include <utils/Logger.h>
class ImageProcessor;
///
/// The Connection object created by \a BoblightServer when a new connection is establshed
///
@@ -76,9 +74,6 @@ private:
/// The TCP-Socket that is connected tot the boblight-client
QTcpSocket * _socket;
/// The processor for translating images to led-values
ImageProcessor * _imageProcessor;
/// Link to Hyperion for writing led-values to a priority channel
Hyperion * _hyperion;
@@ -90,7 +85,7 @@ private:
/// The latest led color data
std::vector<ColorRgb> _ledColors;
/// logger instance
Logger * _log;

View File

@@ -5,20 +5,31 @@
#include <boblightserver/BoblightServer.h>
#include "BoblightClientConnection.h"
// hyperion includes
#include <hyperion/Hyperion.h>
// qt incl
#include <QTcpServer>
using namespace hyperion;
BoblightServer::BoblightServer(const int priority, uint16_t port)
BoblightServer::BoblightServer(const QJsonDocument& config)
: QObject()
, _hyperion(Hyperion::getInstance())
, _server()
, _server(new QTcpServer(this))
, _openConnections()
, _priority(priority)
, _priority(0)
, _log(Logger::getInstance("BOBLIGHT"))
, _isActive(false)
, _port(port)
, _port(0)
{
// Set trigger for incoming connections
connect(&_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
Debug(_log, "Instance created");
// listen for component change
connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
// listen new connection signal from server
connect(_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
// init
handleSettingsUpdate(settings::BOBLSERVER, config);
}
BoblightServer::~BoblightServer()
@@ -28,63 +39,63 @@ BoblightServer::~BoblightServer()
void BoblightServer::start()
{
if ( active() )
if ( _server->isListening() )
return;
if (!_server.listen(QHostAddress::Any, _port))
if (!_server->listen(QHostAddress::Any, _port))
{
throw std::runtime_error("BOBLIGHT ERROR: server could not bind to port");
Error(_log, "Could not bind to port '%d', please use an available port", _port);
return;
}
Info(_log, "Boblight server started on port %d", _port);
Info(_log, "Started on port %d", _port);
_isActive = true;
emit statusChanged(_isActive);
_hyperion->registerPriority("Boblight", _priority);
_hyperion->getComponentRegister().componentStateChanged(COMP_BOBLIGHTSERVER, _server->isListening());
}
void BoblightServer::stop()
{
if ( ! active() )
if ( ! _server->isListening() )
return;
foreach (BoblightClientConnection * connection, _openConnections) {
delete connection;
}
_server.close();
_isActive = false;
emit statusChanged(_isActive);
_server->close();
_hyperion->unRegisterPriority("Boblight");
Info(_log, "Stopped");
_hyperion->getComponentRegister().componentStateChanged(COMP_BOBLIGHTSERVER, _server->isListening());
}
bool BoblightServer::active()
{
return _server->isListening();
}
void BoblightServer::componentStateChanged(const hyperion::Components component, bool enable)
{
if (component == COMP_BOBLIGHTSERVER)
{
if (_isActive != enable)
if (_server->isListening() != enable)
{
if (enable) start();
else stop();
Info(_log, "change state to %s", (_isActive ? "enabled" : "disabled") );
}
_hyperion->getComponentRegister().componentStateChanged(component, _isActive);
}
}
uint16_t BoblightServer::getPort() const
{
return _server.serverPort();
return _server->serverPort();
}
void BoblightServer::newConnection()
{
QTcpSocket * socket = _server.nextPendingConnection();
QTcpSocket * socket = _server->nextPendingConnection();
if (socket != nullptr)
{
Info(_log, "new connection");
_hyperion->registerInput(_priority, hyperion::COMP_BOBLIGHTSERVER, QString("Boblight@%1").arg(socket->peerAddress().toString()));
BoblightClientConnection * connection = new BoblightClientConnection(socket, _priority);
_openConnections.insert(connection);
@@ -101,3 +112,16 @@ void BoblightServer::closedConnection(BoblightClientConnection *connection)
// schedule to delete the connection object
connection->deleteLater();
}
void BoblightServer::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
{
if(type == settings::BOBLSERVER)
{
QJsonObject obj = config.object();
_port = obj["port"].toInt();
_priority = obj["priority"].toInt();
stop();
if(obj["enable"].toBool())
start();
}
}