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:
LordGrey
2020-06-28 23:05:32 +02:00
committed by GitHub
parent e365a2839d
commit bfb50b8d91
61 changed files with 530 additions and 365 deletions

View File

@@ -8,6 +8,7 @@
#include <QDateTime>
#include <QEventLoop>
#include <QTimer>
#include <QDateTime>
#include "hyperion/Hyperion.h"
#include <utils/JsonUtils.h>
@@ -21,7 +22,7 @@ LedDevice::LedDevice(const QJsonObject& config, QObject* parent)
, _deviceInError(false)
, _refresh_timer(new QTimer(this))
, _refresh_timer_interval(0)
, _last_write_time(QDateTime::currentMSecsSinceEpoch())
, _lastWriteTime(QDateTime::currentDateTime())
, _latchTime_ms(0)
, _componentRegistered(false)
, _enabled(false)
@@ -140,7 +141,7 @@ bool LedDevice::init(const QJsonObject &deviceConfig)
//Debug(_log, "Refresh interval = %dms",_refresh_timer_interval );
_refresh_timer->setInterval( _refresh_timer_interval );
_last_write_time = QDateTime::currentMSecsSinceEpoch();
_lastWriteTime = QDateTime::currentDateTime();
this->startRefreshTimer();
}
@@ -170,12 +171,12 @@ int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
}
else
{
qint64 elapsedTime = QDateTime::currentMSecsSinceEpoch() - _last_write_time;
if (_latchTime_ms == 0 || elapsedTime >= _latchTime_ms)
qint64 elapsedTimeMs = _lastWriteTime.msecsTo(QDateTime::currentDateTime());
if (_latchTime_ms == 0 || elapsedTimeMs >= _latchTime_ms)
{
//std::cout << "LedDevice::updateLeds(), Elapsed time since last write (" << elapsedTime << ") ms > _latchTime_ms (" << _latchTime_ms << ") ms" << std::endl;
//std::cout << "LedDevice::updateLeds(), Elapsed time since last write (" << elapsedTimeMs << ") ms > _latchTime_ms (" << _latchTime_ms << ") ms" << std::endl;
retval = write(ledValues);
_last_write_time = QDateTime::currentMSecsSinceEpoch();
_lastWriteTime = QDateTime::currentDateTime();
// if device requires refreshing, save Led-Values and restart the timer
if ( _refresh_enabled )
@@ -186,7 +187,7 @@ int LedDevice::updateLeds(const std::vector<ColorRgb>& ledValues)
}
else
{
//std::cout << "LedDevice::updateLeds(), Skip write. _latchTime_ms (" << _latchTime_ms << ") ms > elapsedTime (" << elapsedTime << ") ms" << std::endl;
//std::cout << "LedDevice::updateLeds(), Skip write. elapsedTime (" << elapsedTimeMs << ") ms < _latchTime_ms (" << _latchTime_ms << ") ms" << std::endl;
if ( _refresh_enabled )
{
//Stop timer to allow for next non-refresh update
@@ -242,16 +243,16 @@ int LedDevice::rewriteLeds()
if ( _deviceReady )
{
// qint64 elapsedTime = QDateTime::currentMSecsSinceEpoch() - _last_write_time;
// std::cout << "LedDevice::rewriteLeds(): Rewrite Leds now, elapsedTime [" << elapsedTime << "] ms" << std::endl;
// qint64 elapsedTimeMs = _lastWriteTime.msecsTo(QDateTime::currentDateTime());
// std::cout << "LedDevice::rewriteLEDs(): Rewrite LEDs now, elapsedTime [" << elapsedTimeMs << "] ms" << std::endl;
// //:TESTING: Inject "white" output records to differentiate from normal writes
// _last_ledValues.clear();
// _last_ledValues.resize(static_cast<unsigned long>(_ledCount), ColorRgb::WHITE);
// printLedValues(_last_ledValues);
// //:TESTING:
//:TESTING:
retval = write(_last_ledValues);
_last_write_time = QDateTime::currentMSecsSinceEpoch();
_lastWriteTime = QDateTime::currentDateTime();
}
else
{

View File

@@ -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);
}

View File

@@ -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;
};

View File

@@ -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;

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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;

View File

@@ -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:

View File

@@ -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;
}

View File

@@ -9,8 +9,6 @@
class QUdpSocket;
const ushort MAX_PORT = 65535;
///
/// The ProviderUdp implements an abstract base-class for LedDevices using UDP packets.
///

View File

@@ -1,11 +1,12 @@
#include "LedDeviceFile.h"
#include <chrono>
#include <iomanip>
#include <iostream>
// Qt includes
#include <Qt>
#include <QTextStream>
LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig)
: LedDevice()
, _file (nullptr)
{
_devConfig = deviceConfig;
_deviceReady = false;
@@ -14,6 +15,10 @@ LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig)
LedDeviceFile::~LedDeviceFile()
{
if ( _file != nullptr )
{
_file->deleteLater();
}
}
LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig)
@@ -28,9 +33,19 @@ bool LedDeviceFile::init(const QJsonObject &deviceConfig)
_fileName = deviceConfig["output"].toString("/dev/null");
_printTimeStamp = deviceConfig["printTimeStamp"].toBool(false);
initFile(_fileName);
return initOK;
}
void LedDeviceFile::initFile(const QString &fileName)
{
if ( _file == nullptr )
{
_file = new QFile(fileName);
}
}
int LedDeviceFile::open()
{
int retval = -1;
@@ -39,26 +54,24 @@ int LedDeviceFile::open()
if ( init(_devConfig) )
{
if ( _ofs.is_open() )
if ( ! _file->isOpen() )
{
_ofs.close();
}
Debug(_log, "QIODevice::WriteOnly, %s", QSTRING_CSTR(_fileName));
if ( !_file->open(QIODevice::WriteOnly | QIODevice::Text) )
{
errortext = QString ("(%1) %2, file: (%3)").arg(_file->error()).arg(_file->errorString()).arg(_fileName);
}
else
{
_deviceReady = true;
setEnable(true);
retval = 0;
}
_ofs.open( QSTRING_CSTR(_fileName));
if ( _ofs.fail() )
{
errortext = QString ("Failed to open file (%1). Error message: %2").arg(_fileName, strerror(errno));
}
else
{
_deviceReady = true;
setEnable(true);
retval = 0;
}
if ( retval < 0 )
{
this->setInError( errortext );
if ( retval < 0 )
{
this->setInError( errortext );
}
}
}
return retval;
@@ -68,43 +81,47 @@ void LedDeviceFile::close()
{
LedDevice::close();
// LedDevice specific closing activites
if ( _ofs )
if ( _file != nullptr)
{
_ofs.close();
if ( _ofs.fail() )
// Test, if device requires closing
if ( _file->isOpen() )
{
Error( _log, "Failed to close device (%s). Error message: %s", QSTRING_CSTR(_fileName), strerror(errno) );
// close device physically
Debug(_log,"File: %s", QSTRING_CSTR(_fileName) );
_file->close();
}
}
}
int LedDeviceFile::write(const std::vector<ColorRgb> & ledValues)
{
QTextStream out(_file);
//printLedValues (ledValues);
if ( _printTimeStamp )
{
// get a precise timestamp as a string
const auto now = std::chrono::system_clock::now();
const auto nowAsTimeT = std::chrono::system_clock::to_time_t(now);
const auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
QDateTime now = QDateTime::currentDateTime();
qint64 elapsedTimeMs = _lastWriteTime.msecsTo(now);
const auto elapsedTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastWriteTime);
_ofs
<< std::put_time(std::localtime(&nowAsTimeT), "%Y-%m-%d %T")
<< '.' << std::setfill('0') << std::setw(3) << nowMs.count()
<< " | +" << std::setfill('0') << std::setw(4) << elapsedTimeMs.count();
lastWriteTime = now;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
out << now.toString(Qt::ISODateWithMs) << " | +" << QString("%1").arg( elapsedTimeMs,4);
#else
out << now.toString(Qt::ISODate) << now.toString(".zzz") << " | +" << QString("%1").arg( elapsedTimeMs,4);
#endif
}
_ofs << " [";
out << " [";
for (const ColorRgb& color : ledValues)
{
_ofs << color;
out << color;
}
_ofs << "]" << std::endl;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
out << "]" << Qt::endl;
#else
out << "]" << endl;
#endif
return 0;
}

View File

@@ -1,74 +1,84 @@
#pragma once
#ifndef LEDEVICEFILE_H
#define LEDEVICEFILE_H
// STL includes
#include <fstream>
#include <chrono>
// Leddevice includes
// LedDevice includes
#include <leddevice/LedDevice.h>
// Qt includes
#include <QFile>
#include <QDateTime>
///
/// Implementation of the LedDevice that write the led-colors to an
/// ASCII-textfile('/home/pi/LedDevice.out')
/// Implementation of the LedDevice that write the LED-colors to an
/// ASCII-textfile primarily for testing purposes
///
class LedDeviceFile : public LedDevice
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a file output LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceFile(const QJsonObject &deviceConfig);
///
/// Destructor of this test-device
/// @brief Destructor of the LedDevice
///
virtual ~LedDeviceFile() override;
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
public slots:
///
/// Sets configuration
/// @brief Closes the output device.
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
public slots:
///
/// Closes the output device.
/// Includes switching-off the device and stopping refreshes
/// @return Zero on success (i.e. device is closed), else negative
///
virtual void close() override;
protected:
///
/// Opens and initiatialises the output device
/// @brief Initialise the device's configuration
///
/// @return Zero on succes (i.e. device is ready and enabled) else negative
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
virtual bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Opens the output device.
///
/// @return Zero on success (i.e. device is ready), else negative
///
virtual int open() override;
///
/// Writes the given led-color values to the output stream
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
///
/// @return Zero on success else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
/// The outputstream
std::ofstream _ofs;
QFile* _file;
private:
void initFile(const QString &filename);
QString _fileName;
/// Timestamp for the output record
bool _printTimeStamp;
/// Last write/output timestamp
std::chrono::system_clock::time_point lastWriteTime = std::chrono::system_clock::now();
};
#endif // LEDEVICEFILE_H

View File

@@ -27,7 +27,7 @@ bool LedDeviceWS281x::init(const QJsonObject &deviceConfig)
QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off");
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
if (_whiteAlgorithm == RGBW::INVALID)
if (_whiteAlgorithm == RGBW::WhiteAlgorithm::INVALID)
{
errortext = QString ("unknown whiteAlgorithm: %1").arg(whiteAlgorithm);
isInitOK = false;

View File

@@ -2,7 +2,7 @@
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const QJsonObject &deviceConfig)
: ProviderSpi()
, _whiteAlgorithm(RGBW::INVALID)
, _whiteAlgorithm(RGBW::WhiteAlgorithm::INVALID)
, SPI_BYTES_PER_COLOUR(4)
, bitpair_to_byte {
0b10001000,
@@ -30,7 +30,7 @@ bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig)
QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off");
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
if (_whiteAlgorithm == RGBW::INVALID)
if (_whiteAlgorithm == RGBW::WhiteAlgorithm::INVALID)
{
QString errortext = QString ("unknown whiteAlgorithm: %1").arg(whiteAlgorithm);
this->setInError(errortext);