hyperion.ng/libsrc/leddevice/LedDeviceTpm2.cpp
redPanther 5aac2be702 Leddevice refactoring the next next part (#263)
* switch rs232 provider to completly async transfer

* start of implementing a seperate init function for leddevices

* rename setconfig to init

* more fixes

* implement missing code

* fix code style

* remove debug  code

* remove  debug stuff

* set loglevel to original state
2016-10-08 08:14:36 +02:00

34 lines
870 B
C++

#include "LedDeviceTpm2.h"
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
: ProviderRs232()
{
_deviceReady = init(deviceConfig);
}
LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig)
{
return new LedDeviceTpm2(deviceConfig);
}
bool LedDeviceTpm2::init(const Json::Value &deviceConfig)
{
ProviderRs232::init(deviceConfig);
_ledBuffer.resize(5 + 3*_ledCount);
_ledBuffer[0] = 0xC9; // block-start byte
_ledBuffer[1] = 0xDA; // DATA frame
_ledBuffer[2] = ((3 * _ledCount) >> 8) & 0xFF; // frame size high byte
_ledBuffer[3] = (3 * _ledCount) & 0xFF; // frame size low byte
_ledBuffer.back() = 0x36; // block-end byte
return true;
}
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
{
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledRGBCount);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}