mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
refactor: Address (Windows) compile warnings (#840)
* Windows compile errors and (Qt 5.15 deprecation) warnings * Usability - Enable/Disable Instance button Co-authored-by: brindosch <edeltraud70@gmx.de>
This commit is contained in:
@@ -2,18 +2,20 @@
|
||||
#include "LedDeviceAtmoOrb.h"
|
||||
|
||||
// qt includes
|
||||
#include <QtNetwork>
|
||||
#include <QUdpSocket>
|
||||
|
||||
const quint16 MULTICAST_GROUPL_DEFAULT_PORT = 49692;
|
||||
const int LEDS_DEFAULT_NUMBER = 24;
|
||||
|
||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
, _networkmanager (nullptr)
|
||||
, _udpSocket (nullptr)
|
||||
, _multiCastGroupPort (49692)
|
||||
, joinedMulticastgroup (false)
|
||||
, _multiCastGroupPort (MULTICAST_GROUPL_DEFAULT_PORT)
|
||||
, _joinedMulticastgroup (false)
|
||||
, _useOrbSmoothing (false)
|
||||
, _transitiontime (0)
|
||||
, _skipSmoothingDiff (0)
|
||||
, _numLeds (24)
|
||||
, _numLeds (LEDS_DEFAULT_NUMBER)
|
||||
|
||||
{
|
||||
_devConfig = deviceConfig;
|
||||
@@ -27,25 +29,32 @@ LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig)
|
||||
|
||||
LedDeviceAtmoOrb::~LedDeviceAtmoOrb()
|
||||
{
|
||||
_networkmanager->deleteLater();
|
||||
_udpSocket->deleteLater();
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
_udpSocket->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
bool isInitOK = LedDevice::init(deviceConfig);
|
||||
bool isInitOK = false;
|
||||
|
||||
if ( isInitOK )
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
|
||||
_multicastGroup = deviceConfig["output"].toString().toStdString().c_str();
|
||||
_useOrbSmoothing = deviceConfig["useOrbSmoothing"].toBool(false);
|
||||
_transitiontime = deviceConfig["transitiontime"].toInt(0);
|
||||
_skipSmoothingDiff = deviceConfig["skipSmoothingDiff"].toInt(0);
|
||||
_multiCastGroupPort = static_cast<quint16>(deviceConfig["port"].toInt(49692));
|
||||
_numLeds = deviceConfig["numLeds"].toInt(24);
|
||||
_multiCastGroupPort = static_cast<quint16>(deviceConfig["port"].toInt(MULTICAST_GROUPL_DEFAULT_PORT));
|
||||
_numLeds = deviceConfig["numLeds"].toInt(LEDS_DEFAULT_NUMBER);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", Qt::SkipEmptyParts);
|
||||
#else
|
||||
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts);
|
||||
#endif
|
||||
|
||||
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts);
|
||||
_orbIds.clear();
|
||||
|
||||
foreach(auto & id_str, orbIds)
|
||||
@@ -53,7 +62,12 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
bool ok;
|
||||
int id = id_str.toInt(&ok);
|
||||
if (ok)
|
||||
_orbIds.append(id);
|
||||
{
|
||||
if ( id < 1 || id > 255 )
|
||||
Warning(_log, "Skip orb id '%d'. IDs must be in range 1-255", id);
|
||||
else
|
||||
_orbIds.append(id);
|
||||
}
|
||||
else
|
||||
Error(_log, "orb id '%s' is not a number", QSTRING_CSTR(id_str));
|
||||
}
|
||||
@@ -63,25 +77,15 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
this->setInError("No valid OrbIds found!");
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
isInitOK = true;
|
||||
}
|
||||
}
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
bool LedDeviceAtmoOrb::initNetwork()
|
||||
{
|
||||
bool isInitOK = true;
|
||||
|
||||
// TODO: Add Network-Error handling
|
||||
_networkmanager = new QNetworkAccessManager();
|
||||
_groupAddress = QHostAddress(_multicastGroup);
|
||||
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
_udpSocket->bind(QHostAddress::AnyIPv4, _multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
|
||||
|
||||
joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
int LedDeviceAtmoOrb::open()
|
||||
{
|
||||
int retval = -1;
|
||||
@@ -89,24 +93,56 @@ int LedDeviceAtmoOrb::open()
|
||||
|
||||
if ( init(_devConfig) )
|
||||
{
|
||||
if ( !initNetwork() )
|
||||
// Try to bind the UDP-Socket
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
this->setInError( "Network error!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
_deviceReady = true;
|
||||
setEnable(true);
|
||||
retval = 0;
|
||||
_groupAddress = QHostAddress(_multicastGroup);
|
||||
if ( !_udpSocket->bind(QHostAddress::AnyIPv4, _multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) )
|
||||
{
|
||||
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString()).arg(_multicastGroup);
|
||||
this->setInError( errortext );
|
||||
}
|
||||
else
|
||||
{
|
||||
_joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
|
||||
if ( !_joinedMulticastgroup )
|
||||
{
|
||||
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString()).arg(_multicastGroup);
|
||||
this->setInError( errortext );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything is OK, device is ready
|
||||
_deviceReady = true;
|
||||
setEnable(true);
|
||||
retval = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void LedDeviceAtmoOrb::close()
|
||||
{
|
||||
LedDevice::close();
|
||||
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
// Test, if device requires closing
|
||||
if ( _udpSocket->isOpen() )
|
||||
{
|
||||
Debug(_log,"Close UDP-device: %s", QSTRING_CSTR( this->getActiveDeviceType() ) );
|
||||
_udpSocket->close();
|
||||
// Everything is OK -> device is closed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues)
|
||||
{
|
||||
// If not in multicast group return
|
||||
if (!joinedMulticastgroup)
|
||||
if (!_joinedMulticastgroup)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -179,20 +215,23 @@ void LedDeviceAtmoOrb::setColor(int orbId, const ColorRgb &color, int commandTyp
|
||||
bytes.fill('\0');
|
||||
|
||||
// Command identifier: C0FFEE
|
||||
bytes[0] = 0xC0;
|
||||
bytes[1] = 0xFF;
|
||||
bytes[2] = 0xEE;
|
||||
bytes[0] = static_cast<char>(0xC0);
|
||||
bytes[1] = static_cast<char>(0xFF);
|
||||
bytes[2] = static_cast<char>(0xEE);
|
||||
|
||||
// Command type
|
||||
bytes[3] = commandType;
|
||||
bytes[3] = static_cast<char>(commandType);
|
||||
|
||||
// Orb ID
|
||||
bytes[4] = orbId;
|
||||
bytes[4] = static_cast<char>(orbId);
|
||||
|
||||
// RED / GREEN / BLUE
|
||||
bytes[5] = color.red;
|
||||
bytes[6] = color.green;
|
||||
bytes[7] = color.blue;
|
||||
bytes[5] = static_cast<char>(color.red);
|
||||
bytes[6] = static_cast<char>(color.green);
|
||||
bytes[7] = static_cast<char>(color.blue);
|
||||
|
||||
// TODO: Why is the datagram _numLeds * 3 in size, if only bypes 5,6,7 are updated with the color?
|
||||
//std::cout << "Orb [" << orbId << "] Cmd [" << bytes.toHex(':').toStdString() <<"]"<< std::endl;
|
||||
|
||||
sendCommand(bytes);
|
||||
}
|
||||
|
@@ -60,6 +60,13 @@ protected:
|
||||
///
|
||||
virtual int open() override;
|
||||
|
||||
///
|
||||
/// @brief Closes the output device.
|
||||
///
|
||||
/// @return Zero on success (i.e. device is closed), else negative
|
||||
///
|
||||
virtual void close() override;
|
||||
|
||||
private:
|
||||
|
||||
///
|
||||
@@ -102,7 +109,7 @@ private:
|
||||
quint16 _multiCastGroupPort;
|
||||
|
||||
// Multicast status
|
||||
bool joinedMulticastgroup;
|
||||
bool _joinedMulticastgroup;
|
||||
|
||||
/// use Orbs own (external) smoothing algorithm
|
||||
bool _useOrbSmoothing;
|
||||
@@ -116,9 +123,6 @@ private:
|
||||
/// Number of leds in Orb, used to determine buffer size
|
||||
int _numLeds;
|
||||
|
||||
|
||||
|
||||
|
||||
/// Array of the orb ids.
|
||||
QVector<int> _orbIds;
|
||||
|
||||
@@ -127,7 +131,4 @@ private:
|
||||
QMap<int, int> lastColorGreenMap;
|
||||
QMap<int, int> lastColorBlueMap;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@@ -165,7 +165,7 @@ int LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, QByteArra
|
||||
if ( isConnected() )
|
||||
{
|
||||
QByteArray sysExData;
|
||||
ssize_t data_size = msg.size() + 4;
|
||||
uint data_size = msg.size() + 4;
|
||||
sysExData.resize( 4 + OPC_HEADER_SIZE );
|
||||
|
||||
sysExData[0] = 0;
|
||||
|
@@ -337,12 +337,12 @@ bool LedDeviceNanoleaf::discoverDevice()
|
||||
SSDPDiscover discover;
|
||||
|
||||
// Discover Canvas device
|
||||
address = discover.getFirstService(STY_WEBSERVER, SSDP_CANVAS, SSDP_TIMEOUT);
|
||||
address = discover.getFirstService(searchType::STY_WEBSERVER, SSDP_CANVAS, SSDP_TIMEOUT);
|
||||
|
||||
//No Canvas device not found
|
||||
if ( address.isEmpty() ) {
|
||||
// Discover Light Panels (Aurora) device
|
||||
address = discover.getFirstService(STY_WEBSERVER, SSDP_LIGHTPANELS, SSDP_TIMEOUT);
|
||||
address = discover.getFirstService(searchType::STY_WEBSERVER, SSDP_LIGHTPANELS, SSDP_TIMEOUT);
|
||||
|
||||
if ( address.isEmpty() ) {
|
||||
Warning(_log, "No Nanoleaf device discovered");
|
||||
@@ -353,7 +353,12 @@ bool LedDeviceNanoleaf::discoverDevice()
|
||||
if ( ! address.isEmpty() ) {
|
||||
Info(_log, "Nanoleaf device discovered at [%s]", QSTRING_CSTR( address ));
|
||||
isDeviceFound = true;
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
// Resolve hostname and port (or use default API port)
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList addressparts = address.split(":", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
#endif
|
||||
_hostname = addressparts[0];
|
||||
_api_port = addressparts[1];
|
||||
}
|
||||
|
@@ -282,7 +282,11 @@ bool LedDevicePhilipsHueBridge::init(const QJsonObject &deviceConfig)
|
||||
|
||||
if ( !address.isEmpty() )
|
||||
{
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList addressparts = address.split(":", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
#endif
|
||||
|
||||
_hostname = addressparts[0];
|
||||
if ( addressparts.size() > 1 )
|
||||
@@ -402,7 +406,12 @@ void LedDevicePhilipsHueBridge::setBridgeConfig(QJsonDocument doc)
|
||||
_deviceFirmwareVersion = jsonConfigInfo[DEV_DATA_FIRMWAREVERSION].toString();
|
||||
_deviceAPIVersion = jsonConfigInfo[DEV_DATA_APIVERSION].toString();
|
||||
|
||||
QStringList apiVersionParts = _deviceAPIVersion.split(".", QString::SkipEmptyParts);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList apiVersionParts = _deviceAPIVersion.split(".", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList apiVersionParts = _deviceAPIVersion.split(".", QString::SkipEmptyParts);
|
||||
#endif
|
||||
|
||||
if ( !apiVersionParts.isEmpty() )
|
||||
{
|
||||
_api_major = apiVersionParts[0].toUInt();
|
||||
@@ -483,7 +492,7 @@ bool LedDevicePhilipsHueBridge::discoverDevice()
|
||||
SSDPDiscover discover;
|
||||
|
||||
// Discover Philips Hue Bridge
|
||||
address = discover.getFirstService( STY_WEBSERVER, SSDP_ID, SSDP_TIMEOUT );
|
||||
address = discover.getFirstService( searchType::STY_WEBSERVER, SSDP_ID, SSDP_TIMEOUT );
|
||||
if ( address.isEmpty() )
|
||||
{
|
||||
Warning(_log, "No Philips Hue Bridge discovered" );
|
||||
@@ -493,7 +502,13 @@ bool LedDevicePhilipsHueBridge::discoverDevice()
|
||||
// Philips Hue Bridge found
|
||||
Info(_log, "Philips Hue Bridge discovered at [%s]", QSTRING_CSTR( address ) );
|
||||
isDeviceFound = true;
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QStringList addressparts = address.split(":", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList addressparts = address.split(":", QString::SkipEmptyParts);
|
||||
#endif
|
||||
|
||||
_hostname = addressparts[0];
|
||||
_api_port = addressparts[1];
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#include "LedDeviceUdpH801.h"
|
||||
|
||||
const ushort H801_DEFAULT_PORT = 30977;
|
||||
static const char H801_DEFAULT_HOST[] = "255.255.255.255";
|
||||
|
||||
LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
@@ -31,8 +34,8 @@ bool LedDeviceUdpH801::init(const QJsonObject &deviceConfig)
|
||||
}
|
||||
|
||||
_message = QByteArray(_prefix_size + _colors + _id_size * _ids.size() + _suffix_size, 0x00);
|
||||
_message[0] = 0xFB;
|
||||
_message[1] = 0xEB;
|
||||
_message[0] = static_cast<char>(0xFB);
|
||||
_message[1] = static_cast<char>(0xEB);
|
||||
|
||||
for (int i = 0; i < _ids.length(); i++) {
|
||||
_message[_prefix_size + _colors + i * _id_size + 0] = (_ids[i] >> 0x00) & 0xFF;
|
||||
|
@@ -8,9 +8,6 @@
|
||||
///
|
||||
///
|
||||
|
||||
const ushort H801_DEFAULT_PORT = 30977;
|
||||
static const char H801_DEFAULT_HOST[] = "255.255.255.255";
|
||||
|
||||
class LedDeviceUdpH801: public ProviderUdp
|
||||
{
|
||||
protected:
|
||||
|
@@ -14,6 +14,8 @@
|
||||
// Local Hyperion includes
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
const ushort MAX_PORT = 65535;
|
||||
|
||||
ProviderUdp::ProviderUdp()
|
||||
: LedDevice()
|
||||
, _udpSocket (nullptr)
|
||||
@@ -26,7 +28,10 @@ ProviderUdp::ProviderUdp()
|
||||
|
||||
ProviderUdp::~ProviderUdp()
|
||||
{
|
||||
_udpSocket->deleteLater();
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
_udpSocket->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
bool ProviderUdp::init(const QJsonObject &deviceConfig)
|
||||
@@ -79,17 +84,18 @@ bool ProviderUdp::initNetwork()
|
||||
|
||||
_udpSocket = new QUdpSocket(this);
|
||||
|
||||
if ( _udpSocket != nullptr)
|
||||
// Try to bind the UDP-Socket
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
QHostAddress localAddress = QHostAddress::Any;
|
||||
quint16 localPort = 0;
|
||||
if ( !_udpSocket->bind(localAddress, localPort) )
|
||||
{
|
||||
Warning ( _log, "Could not bind local address: %s", strerror(errno));
|
||||
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;
|
||||
}
|
||||
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
@@ -120,18 +126,24 @@ void ProviderUdp::close()
|
||||
{
|
||||
LedDevice::close();
|
||||
|
||||
// LedDevice specific closing activites
|
||||
if ( _udpSocket != nullptr)
|
||||
if ( _udpSocket != nullptr )
|
||||
{
|
||||
_udpSocket->close();
|
||||
// Test, if device requires closing
|
||||
if ( _udpSocket->isOpen() )
|
||||
{
|
||||
Debug(_log,"Close UDP-device: %s", QSTRING_CSTR( this->getActiveDeviceType() ) );
|
||||
_udpSocket->close();
|
||||
// Everything is OK -> device is closed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
|
||||
qint64 retVal = _udpSocket->writeDatagram((const char *)data,size,_address,_port);
|
||||
WarningIf((retVal<0), _log, "Error sending: %s", strerror(errno));
|
||||
|
||||
WarningIf((retVal<0), _log, "&s", QSTRING_CSTR(QString
|
||||
("(%1:%2) Write Error: (%3) %4").arg(_address.toString()).arg(_port).arg(_udpSocket->error()).arg(_udpSocket->errorString())));
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
@@ -9,8 +9,6 @@
|
||||
|
||||
class QUdpSocket;
|
||||
|
||||
const ushort MAX_PORT = 65535;
|
||||
|
||||
///
|
||||
/// The ProviderUdp implements an abstract base-class for LedDevices using UDP packets.
|
||||
///
|
||||
|
Reference in New Issue
Block a user