2014-01-15 17:54:10 +01:00
|
|
|
#include "LedDeviceP9813.h"
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceP9813::LedDeviceP9813(const QJsonObject &deviceConfig)
|
2020-08-08 00:21:19 +02:00
|
|
|
: ProviderSpi(deviceConfig)
|
2014-01-15 17:54:10 +01:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceP9813(deviceConfig);
|
2014-01-15 17:54:10 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceP9813::init(const QJsonObject &deviceConfig)
|
2014-01-15 17:54:10 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isInitOK = false;
|
|
|
|
|
|
|
|
// Initialise sub-class
|
|
|
|
if ( ProviderSpi::init(deviceConfig) )
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
|
|
|
_ledBuffer.resize(_ledCount * 4 + 8, 0x00);
|
2020-07-12 20:27:56 +02:00
|
|
|
isInitOK = true;
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
return isInitOK;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
uint8_t * dataPtr = _ledBuffer.data();
|
2014-01-18 23:49:32 +01:00
|
|
|
for (const ColorRgb & color : ledValues)
|
|
|
|
{
|
|
|
|
*dataPtr++ = calculateChecksum(color);
|
|
|
|
*dataPtr++ = color.blue;
|
|
|
|
*dataPtr++ = color.green;
|
|
|
|
*dataPtr++ = color.red;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
2014-01-15 17:54:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-18 23:49:32 +01:00
|
|
|
uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb & color) const
|
2014-01-16 20:34:56 +01:00
|
|
|
{
|
2014-01-18 23:49:32 +01:00
|
|
|
uint8_t res = 0;
|
2014-01-16 20:34:56 +01:00
|
|
|
|
2014-01-18 23:49:32 +01:00
|
|
|
res |= (uint8_t)0x03 << 6;
|
|
|
|
res |= (uint8_t)(~(color.blue >> 6) & 0x03) << 4;
|
|
|
|
res |= (uint8_t)(~(color.green >> 6) & 0x03) << 2;
|
|
|
|
res |= (uint8_t)(~(color.red >> 6) & 0x03);
|
2014-01-16 20:34:56 +01:00
|
|
|
|
2014-01-18 23:49:32 +01:00
|
|
|
return res;
|
2014-01-16 20:34:56 +01:00
|
|
|
}
|