mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)
* Refactor LedDevices - Initial version * Small renamings * Add WLED as own device * Lpd8806 Remove open() method * remove dependency on Qt 5.10 * Lpd8806 Remove open() method * Update WS281x * Update WS2812SPI * Add writeBlack for WLED powerOff * WLED remove extra bracket * Allow different Nanoleaf panel numbering sequence (Feature req.#827) * build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826) * Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4. - [Release notes](https://github.com/faye/websocket-extensions-node/releases) - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4) * Fix typos * Nanoleaf clean-up * Yeelight support, generalize wizard elements * Update Yeelight to handle quota in music mode * Yeelight extend rage for extraTimeDarkness for testing * Clean-up - Add commentary, Remove development debug statements * Fix brightnessSwitchOffOnMinimum typo and default value * Yeelight support restoreOriginalState, additional Fixes * WLED - Remove UDP-Port, as it is not configurable * Fix merging issue * Remove QHostAddress::operator=(const QString&)' is deprecated * Windows compile errors and (Qt 5.15 deprecation) warnings * Fix order includes * LedDeviceFile Support Qt5.7 and greater * Windows compatibility and other Fixes * Fix Qt Version compatability * Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support * Disable WLED Wizard Button (until Wizard is available) * Yeelight updates * Add wrong log-type as per #505 * Fixes and Clean-up after clang-tidy report * Fix udpe131 not enabled for generated CID * Change timer into dynamic for Qt Thread-Affinity * Hue clean-up and diyHue workaround * Updates after review feedback by m-seker * Add "chrono" includes
This commit is contained in:
@@ -22,7 +22,7 @@ ProviderUdp::ProviderUdp()
|
||||
, _port(1)
|
||||
, _defaultHost("127.0.0.1")
|
||||
{
|
||||
_deviceReady = false;
|
||||
_isDeviceReady = false;
|
||||
_latchTime_ms = 1;
|
||||
}
|
||||
|
||||
@@ -30,59 +30,65 @@ ProviderUdp::~ProviderUdp()
|
||||
{
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
_udpSocket->deleteLater();
|
||||
delete _udpSocket;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProviderUdp::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
bool isInitOK = LedDevice::init(deviceConfig);
|
||||
bool isInitOK = false;
|
||||
|
||||
QString host = deviceConfig["host"].toString(_defaultHost);
|
||||
// Initialise sub-class
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
QString host = deviceConfig["host"].toString(_defaultHost);
|
||||
|
||||
if (_address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if (info.addresses().isEmpty())
|
||||
if (_address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
QString errortext = QString ("Invalid target address [%1]!").arg(host);
|
||||
this->setInError ( errortext );
|
||||
return false;
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
_address = info.addresses().first();
|
||||
Debug( _log, "Failed to parse [%s] as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
QString errortext = QString ("Invalid target address [%1]!").arg(host);
|
||||
this->setInError ( errortext );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
}
|
||||
|
||||
int config_port = deviceConfig["port"].toInt(_port);
|
||||
if ( config_port <= 0 || config_port > MAX_PORT )
|
||||
{
|
||||
QString errortext = QString ("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError ( errortext );
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_port = static_cast<int>(config_port);
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
|
||||
isInitOK = true;
|
||||
}
|
||||
}
|
||||
|
||||
int config_port = deviceConfig["port"].toInt(_port);
|
||||
if ( config_port <= 0 || config_port > MAX_PORT )
|
||||
{
|
||||
QString errortext = QString ("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError ( errortext );
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_port = static_cast<int>(config_port);
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
}
|
||||
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
bool ProviderUdp::initNetwork()
|
||||
int ProviderUdp::open()
|
||||
{
|
||||
bool isInitOK = false;
|
||||
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
int retval = -1;
|
||||
_isDeviceReady = false;
|
||||
|
||||
// Try to bind the UDP-Socket
|
||||
if ( _udpSocket != nullptr )
|
||||
@@ -94,37 +100,21 @@ bool ProviderUdp::initNetwork()
|
||||
QString warntext = QString ("Could not bind local address: %1, (%2) %3").arg(localAddress.toString()).arg(_udpSocket->error()).arg(_udpSocket->errorString());
|
||||
Warning ( _log, "%s", QSTRING_CSTR(warntext));
|
||||
}
|
||||
isInitOK = true;
|
||||
// Everything is OK, device is ready
|
||||
_isDeviceReady = true;
|
||||
retval = 0;
|
||||
}
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
int ProviderUdp::open()
|
||||
{
|
||||
int retval = -1;
|
||||
QString errortext;
|
||||
_deviceReady = false;
|
||||
|
||||
if ( init(_devConfig) )
|
||||
else
|
||||
{
|
||||
if ( ! initNetwork())
|
||||
{
|
||||
this->setInError( "UDP Network error!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything is OK -> enable device
|
||||
_deviceReady = true;
|
||||
setEnable(true);
|
||||
retval = 0;
|
||||
}
|
||||
this->setInError( " Open error. UDP Socket not initialised!" );
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ProviderUdp::close()
|
||||
int ProviderUdp::close()
|
||||
{
|
||||
LedDevice::close();
|
||||
int retval = 0;
|
||||
_isDeviceReady = false;
|
||||
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
@@ -136,6 +126,7 @@ void ProviderUdp::close()
|
||||
// Everything is OK -> device is closed
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
Reference in New Issue
Block a user