mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
29d3209d7d
Former-commit-id: bd36530b6b63959ee4d83693e396cbb0af70ddb3
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
|
|
// STL includes
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
// Linux includes
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
// hyperion local includes
|
|
#include "LedDeviceRawHID.h"
|
|
|
|
// Use feature report HID device
|
|
LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) :
|
|
LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, true),
|
|
_ledBuffer(0),
|
|
_timer()
|
|
{
|
|
// setup the timer
|
|
_timer.setSingleShot(false);
|
|
_timer.setInterval(5000);
|
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
|
|
|
// start the timer
|
|
_timer.start();
|
|
}
|
|
|
|
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
|
|
{
|
|
// Resize buffer if required
|
|
if (_ledBuffer.size() < ledValues.size() * 3) {
|
|
_ledBuffer.resize(3 * ledValues.size());
|
|
}
|
|
|
|
// restart the timer
|
|
_timer.start();
|
|
|
|
// write data
|
|
memcpy(_ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|
|
int LedDeviceRawHID::switchOff()
|
|
{
|
|
// restart the timer
|
|
_timer.start();
|
|
|
|
// write data
|
|
std::fill(_ledBuffer.begin(), _ledBuffer.end(), uint8_t(0));
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|
|
void LedDeviceRawHID::rewriteLeds()
|
|
{
|
|
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|