2015-11-08 16:31:18 +01:00
|
|
|
#include "LedDeviceRawHID.h"
|
|
|
|
|
|
|
|
// Use feature report HID device
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
|
2016-08-28 07:12:48 +02:00
|
|
|
: ProviderHID(deviceConfig)
|
2016-08-14 10:46:44 +02:00
|
|
|
, _timer()
|
2015-11-08 16:31:18 +01:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
_useFeature = true;
|
|
|
|
|
2015-11-08 16:31:18 +01:00
|
|
|
// setup the timer
|
|
|
|
_timer.setSingleShot(false);
|
|
|
|
_timer.setInterval(5000);
|
|
|
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
|
|
|
|
|
|
|
// start the timer
|
|
|
|
_timer.start();
|
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceRawHID(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2015-11-08 16:31:18 +01:00
|
|
|
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
|
|
|
|
{
|
|
|
|
// Resize buffer if required
|
2016-09-23 08:49:22 +02:00
|
|
|
unsigned bufferSize = _ledCount * 3;
|
|
|
|
if (_ledBuffer.size() < bufferSize)
|
|
|
|
{
|
|
|
|
_ledBuffer.resize(bufferSize);
|
2015-11-08 16:31:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// restart the timer
|
|
|
|
_timer.start();
|
|
|
|
|
|
|
|
// write data
|
2016-09-23 08:49:22 +02:00
|
|
|
memcpy(_ledBuffer.data(), ledValues.data(), bufferSize);
|
2015-11-08 16:31:18 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LedDeviceRawHID::rewriteLeds()
|
|
|
|
{
|
|
|
|
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|