hyperion.ng/libsrc/hyperion/device/LedDeviceLpd6803.cpp
T. van der Zwan ef6ac97f84 Renamed ldp6803 to lpd6803
Added Lpd8806 device


Former-commit-id: 716cd60d1ac750fc2feca6f3621b20196b52a84e
2013-11-13 20:42:18 +00:00

50 lines
1.2 KiB
C++

// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceLpd6803.h"
LedDeviceLpd6803::LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate) :
LedSpiDevice(outputDevice, baudrate),
_ledBuffer(0)
{
// empty
}
int LedDeviceLpd6803::write(const std::vector<ColorRgb> &ledValues)
{
// Reconfigure if the current connfiguration does not match the required configuration
if (4 + 2*ledValues.size() != _ledBuffer.size())
{
// Initialise the buffer
_ledBuffer.resize(4 + 2*ledValues.size(), 0x00);
}
// Copy the colors from the ColorRgb vector to the Ldp6803 data vector
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[4 + 2 * iLed] = 0x80 | ((rgb.red & 0xf8) >> 1) | (rgb.green >> 6);
_ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3);
}
// Write the data
if (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0)
{
return -1;
}
return 0;
}
int LedDeviceLpd6803::switchOff()
{
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
}