2014-01-15 17:54:10 +01:00
|
|
|
#include "LedDeviceP9813.h"
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderSpi()
|
2014-01-15 17:54:10 +01:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
_deviceReady = init(deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LedDevice* LedDeviceP9813::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceP9813(deviceConfig);
|
2014-01-15 17:54:10 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
bool LedDeviceP9813::init(const Json::Value &deviceConfig)
|
2014-01-15 17:54:10 +01:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderSpi::init(deviceConfig);
|
2014-01-18 23:49:32 +01:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
_ledBuffer.resize(_ledCount * 4 + 8, 0x00);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|