2016-05-26 23:44:27 +02:00
|
|
|
#include "LedDeviceLpd8806.h"
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceLpd8806::LedDeviceLpd8806(const QJsonObject &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderSpi()
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
_devConfig = deviceConfig;
|
|
|
|
_deviceReady = false;
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceLpd8806::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceLpd8806(deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceLpd8806::init(const QJsonObject &deviceConfig)
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
bool isInitOK = ProviderSpi::init(deviceConfig);
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
const unsigned clearSize = _ledCount/32+1;
|
2016-10-08 08:14:36 +02:00
|
|
|
unsigned messageLength = _ledRGBCount + clearSize;
|
|
|
|
// Initialise the buffer
|
|
|
|
_ledBuffer.resize(messageLength, 0x00);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
return isInitOK;
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
// 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
|
|
|
{
|
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[iLed*3] = 0x80 | (color.red >> 1);
|
|
|
|
_ledBuffer[iLed*3+1] = 0x80 | (color.green >> 1);
|
|
|
|
_ledBuffer[iLed*3+2] = 0x80 | (color.blue >> 1);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write the data
|
2016-12-05 22:46:04 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|