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"
|
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned baudrate) :
|
|
|
|
LedSpiDevice(outputDevice, baudrate),
|
2013-10-27 18:04:37 +01:00
|
|
|
mLedCount(0)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-11-02 06:51:41 +01:00
|
|
|
// empty
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
|
|
|
{
|
2013-10-27 18:04:37 +01:00
|
|
|
mLedCount = ledValues.size();
|
|
|
|
|
2013-11-02 06:51:41 +01:00
|
|
|
const unsigned dataLen = ledValues.size() * sizeof(RgbColor);
|
|
|
|
const char * dataPtr = reinterpret_cast<const char *>(ledValues.data());
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-02 06:51:41 +01:00
|
|
|
const int retVal = latch(dataLen, dataPtr, 500000);
|
2013-07-26 22:38:34 +02:00
|
|
|
return retVal;
|
|
|
|
}
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
int LedDeviceWs2801::switchOff()
|
|
|
|
{
|
|
|
|
return write(std::vector<RgbColor>(mLedCount, RgbColor::BLACK));
|
|
|
|
}
|