2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Linux includes
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceWs2801.h"
|
|
|
|
|
2016-08-13 19:54:08 +02:00
|
|
|
LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned baudrate, const unsigned latchTime,
|
2016-08-14 10:46:44 +02:00
|
|
|
const int spiMode, const bool spiDataInvert)
|
2016-08-13 19:54:08 +02:00
|
|
|
: LedSpiDevice(outputDevice, baudrate, latchTime, spiMode, spiDataInvert)
|
2016-02-13 13:00:31 +01:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
int LedDeviceWs2801::write(const std::vector<ColorRgb> &ledValues)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
_ledCount = ledValues.size();
|
2013-10-27 18:04:37 +01:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
const unsigned dataLen = ledValues.size() * sizeof(ColorRgb);
|
2013-11-02 19:30:19 +01:00
|
|
|
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-02 19:30:19 +01:00
|
|
|
return writeBytes(dataLen, dataPtr);
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
int LedDeviceWs2801::switchOff()
|
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
2013-10-27 18:04:37 +01:00
|
|
|
}
|