mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Leddevice refactoring the next part (#253)
* add general switchOff * refactoring of leddevices regarding ledcount and switchoff * remove obsolete includes
This commit is contained in:
@@ -1,13 +1,3 @@
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceLpd8806.h"
|
||||
|
||||
LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig)
|
||||
@@ -22,19 +12,20 @@ LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig)
|
||||
|
||||
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
const unsigned clearSize = ledValues.size()/32+1;
|
||||
const unsigned clearSize = _ledCount/32+1;
|
||||
unsigned messageLength = 3*_ledCount + clearSize;
|
||||
// Reconfigure if the current connfiguration does not match the required configuration
|
||||
if (3*ledValues.size() + clearSize != _ledBuffer.size())
|
||||
if (messageLength != _ledBuffer.size())
|
||||
{
|
||||
// Initialise the buffer
|
||||
_ledBuffer.resize(3*ledValues.size() + clearSize, 0x00);
|
||||
_ledBuffer.resize(messageLength, 0x00);
|
||||
|
||||
// Perform an initial reset to start accepting data on the first led
|
||||
writeBytes(clearSize, _ledBuffer.data());
|
||||
}
|
||||
|
||||
// Copy the colors from the ColorRgb vector to the Ldp8806 data vector
|
||||
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
||||
for (unsigned iLed=0; iLed<(unsigned)_ledCount; ++iLed)
|
||||
{
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
|
||||
@@ -44,14 +35,5 @@ int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
|
||||
}
|
||||
|
||||
// Write the data
|
||||
if (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedDeviceLpd8806::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
||||
return (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0) ? -1 : 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user