2014-06-15 02:19:09 +02:00
|
|
|
#include "LedDeviceTpm2.h"
|
2016-09-23 08:49:22 +02:00
|
|
|
|
2014-06-15 02:19:09 +02:00
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceTpm2::LedDeviceTpm2(const QJsonObject &deviceConfig)
|
2020-08-08 00:21:19 +02:00
|
|
|
: ProviderRs232(deviceConfig)
|
2014-06-15 02:19:09 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceTpm2::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceTpm2(deviceConfig);
|
2014-06-15 02:19:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceTpm2::init(const QJsonObject &deviceConfig)
|
2014-06-15 02:19:09 +02:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isInitOK = false;
|
|
|
|
|
|
|
|
// Initialise sub-class
|
|
|
|
if ( ProviderRs232::init(deviceConfig) )
|
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
_ledBuffer.resize(5 + _ledRGBCount);
|
|
|
|
_ledBuffer[0] = 0xC9; // block-start byte
|
|
|
|
_ledBuffer[1] = 0xDA; // DATA frame
|
|
|
|
_ledBuffer[2] = (_ledRGBCount >> 8) & 0xFF; // frame size high byte
|
|
|
|
_ledBuffer[3] = _ledRGBCount & 0xFF; // frame size low byte
|
|
|
|
_ledBuffer.back() = 0x36; // block-end byte
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
isInitOK = true;
|
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
return isInitOK;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
2014-06-15 02:19:09 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
|
|
|
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledRGBCount);
|
2014-06-15 02:19:09 +02:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|