hyperion.ng/libsrc/leddevice/LedDeviceRawHID.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

40 lines
889 B
C++

#include "LedDeviceRawHID.h"
// Use feature report HID device
LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
: ProviderHID()
, _timer()
{
ProviderHID::init(deviceConfig);
_useFeature = true;
_ledBuffer.resize(_ledRGBCount);
// setup the timer
_timer.setSingleShot(false);
_timer.setInterval(5000);
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
// start the timer
_timer.start();
}
LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig)
{
return new LedDeviceRawHID(deviceConfig);
}
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
{
// restart the timer
_timer.start();
// write data
memcpy(_ledBuffer.data(), ledValues.data(), _ledRGBCount);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
void LedDeviceRawHID::rewriteLeds()
{
writeBytes(_ledBuffer.size(), _ledBuffer.data());
}