hyperion.ng/libsrc/leddevice/LedDeviceRawHID.cpp
penfold42 cc8185691a Renamed the lowlevel providers from LedXXXDevice to ProviderXXX (#206)
%s/LedUdpDevice/ProviderUdp/g
git mv LedUdpDevice.cpp ProviderUdp.cpp
git mv LedUdpDevice.h ProviderUdp.h

vi `grep -l LedHID *`
%s/LedHIDDevice/ProviderHID/g
git mv LedHIDDevice.cpp ProviderHID.cpp
git mv LedHIDDevice.h ProviderHID.h

vi `grep -l LedRs *`
%s/LedRs232Device/ProviderRs232/g
git mv LedRs232Device.cpp ProviderRs232.cpp
git mv LedRs232Device.h ProviderRs232.h

vi `grep -l LedSpi *`
%s/LedSpiDevice/ProviderSpi/g
git mv LedSpiDevice.cpp ProviderSpi.cpp
git mv LedSpiDevice.h ProviderSpi.h
2016-08-28 07:12:47 +02:00

64 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 Json::Value &deviceConfig)
: ProviderHID(deviceConfig)
, _timer()
{
_useFeature = true;
// 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)
{
// 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());
}