mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added the apa102 engine class
Former-commit-id: 03e11a19aed2ae782c5d134e1f4fcf9faea1969e
This commit is contained in:
parent
205fe8ab66
commit
4b716a9e2f
47
libsrc/leddevice/LedDeviceAPA102.cpp
Normal file
47
libsrc/leddevice/LedDeviceAPA102.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceAPA102.h"
|
||||
|
||||
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedSpiDevice(outputDevice, baudrate, 500000),
|
||||
mLedCount(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
mLedCount = ledValues.size();
|
||||
|
||||
const unsigned dataLen = 8 + (ledValues.size() * (sizeof(ColorRgb) + 1));
|
||||
const uint8_t data[dataLen] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
int position = 4;
|
||||
for (ColorRgb* rgb : ledValues ){
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = rgb.red;
|
||||
data[i++] = rgb.green;
|
||||
data[i++] = rgb.blue;
|
||||
}
|
||||
|
||||
// Write end frame
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
data[i++] = 0xFF;
|
||||
|
||||
return writeBytes(dataLen, data);
|
||||
}
|
||||
|
||||
int LedDeviceAPA102::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
||||
}
|
Loading…
Reference in New Issue
Block a user