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
|
|
|
|
LedDevicePaintpack::LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) :
|
|
|
|
LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, false),
|
|
|
|
_ledBuffer(0)
|
2013-12-10 20:28:27 +01:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|