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
|
2013-11-05 21:11:31 +01:00
|
|
|
#include "LedDeviceLpd6803.h"
|
2013-11-01 23:48:39 +01:00
|
|
|
|
2013-11-13 21:42:18 +01:00
|
|
|
LedDeviceLpd6803::LedDeviceLpd6803(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-13 21:42:18 +01:00
|
|
|
int LedDeviceLpd6803::write(const std::vector<ColorRgb> &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-11 10:00:37 +01:00
|
|
|
// Copy the colors from the ColorRgb vector to the Ldp6803 data vector
|
2013-11-02 06:51:41 +01:00
|
|
|
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
const ColorRgb& 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-13 21:42:18 +01:00
|
|
|
int LedDeviceLpd6803::switchOff()
|
2013-11-01 23:48:39 +01:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
2013-11-01 23:48:39 +01:00
|
|
|
}
|