2016-05-26 23:44:27 +02:00
|
|
|
#include "LedDeviceLpd8806.h"
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig)
|
2016-08-28 07:12:48 +02:00
|
|
|
: ProviderSpi(deviceConfig)
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceLpd8806(deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-09-23 08:49:22 +02:00
|
|
|
const unsigned clearSize = _ledCount/32+1;
|
|
|
|
unsigned messageLength = 3*_ledCount + clearSize;
|
2016-05-26 23:44:27 +02:00
|
|
|
// Reconfigure if the current connfiguration does not match the required configuration
|
2016-09-23 08:49:22 +02:00
|
|
|
if (messageLength != _ledBuffer.size())
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
|
|
|
// Initialise the buffer
|
2016-09-23 08:49:22 +02:00
|
|
|
_ledBuffer.resize(messageLength, 0x00);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// 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
|
2016-09-23 08:49:22 +02:00
|
|
|
for (unsigned iLed=0; iLed<(unsigned)_ledCount; ++iLed)
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
|
|
|
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
|
2016-09-23 08:49:22 +02:00
|
|
|
return (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0) ? -1 : 0;
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|