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-08-23 20:07:12 +02:00
|
|
|
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
|
2016-08-28 07:12:48 +02:00
|
|
|
: ProviderRs232(deviceConfig)
|
2014-06-15 02:19:09 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceTpm2(deviceConfig);
|
2014-06-15 02:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
if (_ledBuffer.size() == 0)
|
|
|
|
{
|
2016-09-23 08:49:22 +02:00
|
|
|
_ledBuffer.resize(5 + 3*_ledCount);
|
2016-05-26 23:44:27 +02:00
|
|
|
_ledBuffer[0] = 0xC9; // block-start byte
|
|
|
|
_ledBuffer[1] = 0xDA; // DATA frame
|
2016-09-23 08:49:22 +02:00
|
|
|
_ledBuffer[2] = ((3 * _ledCount) >> 8) & 0xFF; // frame size high byte
|
|
|
|
_ledBuffer[3] = (3 * _ledCount) & 0xFF; // frame size low byte
|
2016-05-26 23:44:27 +02:00
|
|
|
_ledBuffer.back() = 0x36; // block-end byte
|
|
|
|
}
|
2014-06-15 02:19:09 +02:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
// write data
|
2016-09-23 08:49:22 +02:00
|
|
|
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledCount * 3);
|
2014-06-15 02:19:09 +02:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|