Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 03e11a1

Browse files
committed
Added the apa102 engine class
1 parent ecea592 commit 03e11a1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

libsrc/leddevice/LedDeviceAPA102.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
// STL includes
3+
#include <cstring>
4+
#include <cstdio>
5+
#include <iostream>
6+
7+
// Linux includes
8+
#include <fcntl.h>
9+
#include <sys/ioctl.h>
10+
11+
// hyperion local includes
12+
#include "LedDeviceAPA102.h"
13+
14+
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate) :
15+
LedSpiDevice(outputDevice, baudrate, 500000),
16+
mLedCount(0)
17+
{
18+
// empty
19+
}
20+
21+
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
22+
{
23+
mLedCount = ledValues.size();
24+
25+
const unsigned dataLen = 8 + (ledValues.size() * (sizeof(ColorRgb) + 1));
26+
const uint8_t data[dataLen] = { 0x00, 0x00, 0x00, 0x00 };
27+
int position = 4;
28+
for (ColorRgb* rgb : ledValues ){
29+
data[i++] = 0xFF;
30+
data[i++] = rgb.red;
31+
data[i++] = rgb.green;
32+
data[i++] = rgb.blue;
33+
}
34+
35+
// Write end frame
36+
data[i++] = 0xFF;
37+
data[i++] = 0xFF;
38+
data[i++] = 0xFF;
39+
data[i++] = 0xFF;
40+
41+
return writeBytes(dataLen, data);
42+
}
43+
44+
int LedDeviceAPA102::switchOff()
45+
{
46+
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
47+
}

0 commit comments

Comments
 (0)