2013-12-10 20:28:27 +01:00
|
|
|
|
|
|
|
// Hyperion includes
|
|
|
|
#include "LedDevicePaintpack.h"
|
|
|
|
|
2015-11-08 16:32:53 +01:00
|
|
|
// Use out report HID device
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig)
|
|
|
|
: LedHIDDevice(deviceConfig)
|
2013-12-10 20:28:27 +01:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
_useFeature = false;
|
2013-12-10 20:28:27 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDevicePaintpack::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDevicePaintpack(deviceConfig);
|
|
|
|
}
|
2013-12-10 20:28:27 +01:00
|
|
|
|
2015-11-08 16:32:53 +01:00
|
|
|
int LedDevicePaintpack::write(const std::vector<ColorRgb> & ledValues)
|
2013-12-10 20:28:27 +01:00
|
|
|
{
|
2015-11-08 16:32:53 +01:00
|
|
|
if (_ledBuffer.size() < 2 + ledValues.size()*3)
|
2013-12-10 20:28:27 +01:00
|
|
|
{
|
2015-11-08 16:32:53 +01:00
|
|
|
_ledBuffer.resize(2 + ledValues.size()*3, uint8_t(0));
|
|
|
|
_ledBuffer[0] = 3;
|
|
|
|
_ledBuffer[1] = 0;
|
2013-12-10 20:28:27 +01:00
|
|
|
}
|
|
|
|
|
2015-11-08 16:32:53 +01:00
|
|
|
auto bufIt = _ledBuffer.begin()+2;
|
2013-12-10 20:28:27 +01:00
|
|
|
for (const ColorRgb & ledValue : ledValues)
|
|
|
|
{
|
|
|
|
*bufIt = ledValue.red;
|
|
|
|
++bufIt;
|
|
|
|
*bufIt = ledValue.green;
|
|
|
|
++bufIt;
|
|
|
|
*bufIt = ledValue.blue;
|
|
|
|
++bufIt;
|
|
|
|
}
|
|
|
|
|
2015-11-08 16:32:53 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
2013-12-10 20:28:27 +01:00
|
|
|
}
|
|
|
|
|
2015-11-08 16:32:53 +01:00
|
|
|
|
2013-12-10 20:28:27 +01:00
|
|
|
int LedDevicePaintpack::switchOff()
|
|
|
|
{
|
2015-11-08 16:32:53 +01:00
|
|
|
std::fill(_ledBuffer.begin() + 2, _ledBuffer.end(), uint8_t(0));
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
2013-12-10 20:28:27 +01:00
|
|
|
}
|