2015-11-08 16:31:18 +01:00
|
|
|
#include "LedDeviceRawHID.h"
|
|
|
|
|
|
|
|
// Use feature report HID device
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceRawHID::LedDeviceRawHID(const QJsonObject &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderHID()
|
2016-08-14 10:46:44 +02:00
|
|
|
, _timer()
|
2015-11-08 16:31:18 +01:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderHID::init(deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
_useFeature = true;
|
2016-10-08 08:14:36 +02:00
|
|
|
_ledBuffer.resize(_ledRGBCount);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
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-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceRawHID(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2015-11-08 16:31:18 +01:00
|
|
|
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
|
|
|
|
{
|
|
|
|
// restart the timer
|
|
|
|
_timer.start();
|
|
|
|
|
|
|
|
// write data
|
2016-10-08 08:14:36 +02:00
|
|
|
memcpy(_ledBuffer.data(), ledValues.data(), _ledRGBCount);
|
2015-11-08 16:31:18 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LedDeviceRawHID::rewriteLeds()
|
|
|
|
{
|
|
|
|
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|