LED-Device updates (#1315)

* SPI Fix - Free allocated memory in case of invert

* Remove development statement

* UI updates

* Minor corrections

* Tpm2net Fix - Free allocated memory

* LGTM Finding

* Add config directory and user type to SysInfo

* WS281x - Ensure that device runs with root priviliges

* WS281x - Update DMA defauls as per rpi_ws281x recommendation

* Support Sysinfo for Qt < 5.10

* Address LGTM finding
This commit is contained in:
LordGrey
2021-09-15 10:31:56 +02:00
committed by GitHub
parent 8fb3d76b9c
commit 8a785e70c8
18 changed files with 214 additions and 53 deletions

View File

@@ -4,9 +4,15 @@ const ushort TPM2_DEFAULT_PORT = 65506;
LedDeviceTpm2net::LedDeviceTpm2net(const QJsonObject &deviceConfig)
: ProviderUdp(deviceConfig)
, _tpm2_buffer(nullptr)
{
}
LedDeviceTpm2net::~LedDeviceTpm2net()
{
free (_tpm2_buffer);
}
LedDevice* LedDeviceTpm2net::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceTpm2net(deviceConfig);
@@ -25,6 +31,8 @@ bool LedDeviceTpm2net::init(const QJsonObject &deviceConfig)
_tpm2ByteCount = 3 * _ledCount;
_tpm2TotalPackets = (_tpm2ByteCount / _tpm2_max) + ((_tpm2ByteCount % _tpm2_max) != 0);
_tpm2_buffer = (uint8_t*) malloc(_tpm2_max+7);
isInitOK = true;
}
return isInitOK;
@@ -32,8 +40,6 @@ bool LedDeviceTpm2net::init(const QJsonObject &deviceConfig)
int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
{
uint8_t * tpm2_buffer = (uint8_t*) malloc(_tpm2_max+7);
int retVal = 0;
int _thisPacketBytes = 0;
@@ -48,23 +54,22 @@ int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
_thisPacketBytes = (_tpm2ByteCount - rawIdx < _tpm2_max) ? _tpm2ByteCount % _tpm2_max : _tpm2_max;
// is this the last packet? ? ^^ last packet : ^^ earlier packets
tpm2_buffer[0] = 0x9c; // Packet start byte
tpm2_buffer[1] = 0xda; // Packet type Data frame
tpm2_buffer[2] = (_thisPacketBytes >> 8) & 0xff; // Frame size high
tpm2_buffer[3] = _thisPacketBytes & 0xff; // Frame size low
tpm2_buffer[4] = _tpm2ThisPacket++; // Packet Number
tpm2_buffer[5] = _tpm2TotalPackets; // Number of packets
_tpm2_buffer[0] = 0x9c; // Packet start byte
_tpm2_buffer[1] = 0xda; // Packet type Data frame
_tpm2_buffer[2] = (_thisPacketBytes >> 8) & 0xff; // Frame size high
_tpm2_buffer[3] = _thisPacketBytes & 0xff; // Frame size low
_tpm2_buffer[4] = _tpm2ThisPacket++; // Packet Number
_tpm2_buffer[5] = _tpm2TotalPackets; // Number of packets
}
tpm2_buffer [6 + rawIdx%_tpm2_max] = rawdata[rawIdx];
_tpm2_buffer [6 + rawIdx%_tpm2_max] = rawdata[rawIdx];
// is this the last byte of last packet || last byte of other packets
if ( (rawIdx == _tpm2ByteCount-1) || (rawIdx %_tpm2_max == _tpm2_max-1) )
{
tpm2_buffer [6 + rawIdx%_tpm2_max +1] = 0x36; // Packet end byte
retVal &= writeBytes(_thisPacketBytes+7, tpm2_buffer);
_tpm2_buffer [6 + rawIdx%_tpm2_max +1] = 0x36; // Packet end byte
retVal &= writeBytes(_thisPacketBytes+7, _tpm2_buffer);
}
}
return retVal;
}

View File

@@ -18,6 +18,11 @@ public:
///
explicit LedDeviceTpm2net(const QJsonObject &deviceConfig);
///
/// @brief Destructor of the TPM2 LED-device
///
~LedDeviceTpm2net() override;
///
/// @brief Constructs the LED-device
///
@@ -48,6 +53,8 @@ private:
int _tpm2ByteCount;
int _tpm2TotalPackets;
int _tpm2ThisPacket;
uint8_t * _tpm2_buffer;
};
#endif // LEDEVICETPM2NET_H