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