2014-12-03 09:35:10 +01:00
|
|
|
#include "LedDeviceAPA102.h"
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceAPA102::LedDeviceAPA102(const QJsonObject &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderSpi()
|
2014-12-03 09:35:10 +01: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* LedDeviceAPA102::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceAPA102(deviceConfig);
|
2014-12-03 09:35:10 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceAPA102::init(const QJsonObject &deviceConfig)
|
2014-12-03 09:35:10 +01:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
bool isInitOK = ProviderSpi::init(deviceConfig);
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
if ( isInitOK )
|
|
|
|
{
|
|
|
|
const unsigned int startFrameSize = 4;
|
|
|
|
const unsigned int endFrameSize = qMax<unsigned int>(((_ledCount + 15) / 16), 4);
|
|
|
|
const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize;
|
2016-05-10 12:16:19 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
_ledBuffer.resize(APAbufferSize, 0xFF);
|
|
|
|
_ledBuffer[0] = 0x00;
|
|
|
|
_ledBuffer[1] = 0x00;
|
|
|
|
_ledBuffer[2] = 0x00;
|
|
|
|
_ledBuffer[3] = 0x00;
|
|
|
|
}
|
|
|
|
return isInitOK;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
for (signed iLed=0; iLed < static_cast<int>( _ledCount); ++iLed) {
|
2016-05-10 12:16:19 +02:00
|
|
|
const ColorRgb& rgb = ledValues[iLed];
|
|
|
|
_ledBuffer[4+iLed*4] = 0xFF;
|
|
|
|
_ledBuffer[4+iLed*4+1] = rgb.red;
|
|
|
|
_ledBuffer[4+iLed*4+2] = rgb.green;
|
|
|
|
_ledBuffer[4+iLed*4+3] = rgb.blue;
|
2014-12-11 13:48:14 +01:00
|
|
|
}
|
2014-12-03 09:35:10 +01:00
|
|
|
|
2014-12-11 13:48:14 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
2014-12-03 09:35:10 +01:00
|
|
|
}
|