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

Commit 66a4d02

Browse files
author
luisc
committed
add files for P9813 support
1 parent 8999135 commit 66a4d02

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

libsrc/leddevice/LedDeviceP9813.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "LedDeviceP9813.h"
13+
14+
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) :
15+
LedSpiDevice(outputDevice, baudrate, 0),
16+
mLedCount(0)
17+
{
18+
// empty
19+
}
20+
21+
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
22+
{
23+
mLedCount = ledValues.size();
24+
25+
const unsigned dataLen = ledValues.size() * sizeof(ColorRgb);
26+
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
27+
28+
return writeBytes(dataLen, dataPtr);
29+
}
30+
31+
int LedDeviceP9813::switchOff()
32+
{
33+
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
34+
}

libsrc/leddevice/LedDeviceP9813.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
// STL includes
4+
#include <string>
5+
6+
// hyperion include
7+
#include "LedSpiDevice.h"
8+
9+
///
10+
/// Implementation of the LedDevice interface for writing to P9813 led device.
11+
///
12+
class LedDeviceP9813 : public LedSpiDevice
13+
{
14+
public:
15+
///
16+
/// Constructs the LedDevice for a string containing leds of the type P9813
17+
///
18+
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
19+
/// @param baudrate The used baudrate for writing to the output device
20+
///
21+
LedDeviceP9813(const std::string& outputDevice,
22+
const unsigned baudrate);
23+
24+
///
25+
/// Writes the led color values to the led-device
26+
///
27+
/// @param ledValues The color-value per led
28+
/// @return Zero on succes else negative
29+
///
30+
virtual int write(const std::vector<ColorRgb> &ledValues);
31+
32+
/// Switch the leds off
33+
virtual int switchOff();
34+
35+
private:
36+
37+
/// the number of leds
38+
size_t mLedCount;
39+
};

0 commit comments

Comments
 (0)