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

58 lines
1.4 KiB
C++

// 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)
: ProviderSpi(deviceConfig)
{
}
LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig)
{
return new LedDeviceLpd8806(deviceConfig);
}
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
{
const unsigned clearSize = ledValues.size()/32+1;
// Reconfigure if the current connfiguration does not match the required configuration
if (3*ledValues.size() + clearSize != _ledBuffer.size())
{
// Initialise the buffer
_ledBuffer.resize(3*ledValues.size() + clearSize, 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)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[iLed*3] = 0x80 | (rgb.red >> 1);
_ledBuffer[iLed*3+1] = 0x80 | (rgb.green >> 1);
_ledBuffer[iLed*3+2] = 0x80 | (rgb.blue >> 1);
}
// 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}));
}