2016-05-26 23:44:27 +02:00
|
|
|
#include "LedDeviceLpd6803.h"
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderSpi()
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
_deviceReady = init(deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceLpd6803(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
bool LedDeviceLpd6803::init(const Json::Value &deviceConfig)
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderSpi::init(deviceConfig);
|
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
unsigned messageLength = 4 + 2*_ledCount + _ledCount/8 + 1;
|
2016-10-08 08:14:36 +02:00
|
|
|
// Initialise the buffer
|
|
|
|
_ledBuffer.resize(messageLength, 0x00);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
int LedDeviceLpd6803::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
// Copy the colors from the ColorRgb vector to the Ldp6803 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
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
const ColorRgb& color = ledValues[iLed];
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
_ledBuffer[4 + 2 * iLed] = 0x80 | ((color.red & 0xf8) >> 1) | (color.green >> 6);
|
|
|
|
_ledBuffer[5 + 2 * iLed] = ((color.green & 0x38) << 2) | (color.blue >> 3);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|