2014-01-15 17:54:10 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Linux includes
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceP9813.h"
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate)
|
|
|
|
: LedSpiDevice(outputDevice, baudrate, 0)
|
2014-01-15 17:54:10 +01:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
if (_ledCount != (signed)ledValues.size())
|
2014-01-18 23:49:32 +01:00
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
_ledBuffer.resize(ledValues.size() * 4 + 8, 0x00);
|
2014-01-18 23:49:32 +01:00
|
|
|
_ledCount = ledValues.size();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceP9813::switchOff()
|
|
|
|
{
|
2014-01-18 23:49:32 +01:00
|
|
|
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
2014-01-15 17:54:10 +01:00
|
|
|
}
|
2014-01-16 20:34:56 +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
|
|
|
}
|