Bugfix/Hotfix/Update

Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
Paulchen-Panther
2019-07-02 19:06:36 +02:00
parent d739d9efdb
commit d414942e2e
20 changed files with 149 additions and 115 deletions

View File

@@ -5,17 +5,17 @@ static const unsigned OPC_SET_PIXELS = 0; // OPC command codes
static const unsigned OPC_SYS_EX = 255; // OPC command codes
static const unsigned OPC_HEADER_SIZE = 4; // OPC header size
LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject &deviceConfig)
: LedDevice()
: LedDevice()
, _client(nullptr)
{
_deviceReady = init(deviceConfig);
_client = new QTcpSocket(this);
}
LedDeviceFadeCandy::~LedDeviceFadeCandy()
{
_client.close();
_client->close();
}
LedDevice* LedDeviceFadeCandy::construct(const QJsonObject &deviceConfig)
@@ -23,10 +23,9 @@ LedDevice* LedDeviceFadeCandy::construct(const QJsonObject &deviceConfig)
return new LedDeviceFadeCandy(deviceConfig);
}
bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
{
_client.close();
LedDevice::init(deviceConfig);
if (_ledCount > MAX_NUM_LEDS)
{
@@ -67,15 +66,14 @@ bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
bool LedDeviceFadeCandy::isConnected()
{
return _client.state() == QAbstractSocket::ConnectedState;
return _client->state() == QAbstractSocket::ConnectedState;
}
bool LedDeviceFadeCandy::tryConnect()
{
if ( _client.state() == QAbstractSocket::UnconnectedState ) {
_client.connectToHost( _host, _port);
if ( _client.waitForConnected(1000) )
if ( _client->state() == QAbstractSocket::UnconnectedState ) {
_client->connectToHost( _host, _port);
if ( _client->waitForConnected(1000) )
{
Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", QSTRING_CSTR(_host), _port, _channel);
if (_setFcConfig)
@@ -88,7 +86,6 @@ bool LedDeviceFadeCandy::tryConnect()
return isConnected();
}
int LedDeviceFadeCandy::write( const std::vector<ColorRgb> & ledValues )
{
uint idx = OPC_HEADER_SIZE;
@@ -103,11 +100,11 @@ int LedDeviceFadeCandy::write( const std::vector<ColorRgb> & ledValues )
return ( transferData()<0 ? -1 : 0 );
}
int LedDeviceFadeCandy::transferData()
{
if ( isConnected() || tryConnect() )
return _client.write( _opc_data, _opc_data.size() );
if (LedDevice::enabled())
if ( isConnected() || tryConnect() )
return _client->write( _opc_data, _opc_data.size() );
return -2;
}
@@ -131,7 +128,7 @@ int LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, QByteArra
sysExData += msg;
return _client.write( sysExData, sysExData.size() );
return _client->write( sysExData, sysExData.size() );
}
return -1;
}

View File

@@ -56,17 +56,18 @@ public:
/// @return true if success
bool init(const QJsonObject &deviceConfig);
private:
///
/// Writes the led color values to the led-device
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
virtual int write(const std::vector<ColorRgb>& ledValues);
private:
QTcpSocket _client;
QString _host;
protected:
QTcpSocket* _client;
QString _host;
uint16_t _port;
unsigned _channel;
QByteArray _opc_data;

View File

@@ -41,7 +41,7 @@ public:
protected:
///
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
/// Writes the given bytes/bits to the UDP-device and sleeps the latch time to ensure that the
/// values are latched.
///
/// @param[in] size The length of the data