mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge pull request #212 from ssoerensen/master
Added support for the APA102 LED Strip Former-commit-id: 0e63a61fd8667458dbfb3c2b0d0c975f8cf615c1
This commit is contained in:
commit
c063d42ab4
BIN
doc/datasheets/APA102_LED.pdf
Normal file
BIN
doc/datasheets/APA102_LED.pdf
Normal file
Binary file not shown.
@ -57,6 +57,7 @@ if(ENABLE_SPIDEV)
|
|||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
|
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
|
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceAPA102.h
|
||||||
)
|
)
|
||||||
SET(Leddevice_SOURCES
|
SET(Leddevice_SOURCES
|
||||||
${Leddevice_SOURCES}
|
${Leddevice_SOURCES}
|
||||||
@ -65,6 +66,7 @@ if(ENABLE_SPIDEV)
|
|||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceAPA102.cpp
|
||||||
)
|
)
|
||||||
endif(ENABLE_SPIDEV)
|
endif(ENABLE_SPIDEV)
|
||||||
|
|
||||||
|
42
libsrc/leddevice/LedDeviceAPA102.cpp
Normal file
42
libsrc/leddevice/LedDeviceAPA102.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
// 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),
|
||||||
|
_ledBuffer(0)
|
||||||
|
{
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||||
|
{
|
||||||
|
const unsigned int mLedCount = (ledValues.size() * 4) + 8;
|
||||||
|
if(_ledBuffer.size() != mLedCount){
|
||||||
|
_ledBuffer.resize(mLedCount, 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned iLed=1; iLed<=ledValues.size(); ++iLed) {
|
||||||
|
const ColorRgb& rgb = ledValues[iLed];
|
||||||
|
_ledBuffer[iLed*4] = 0xFF;
|
||||||
|
_ledBuffer[iLed*4+1] = rgb.red;
|
||||||
|
_ledBuffer[iLed*4+2] = rgb.green;
|
||||||
|
_ledBuffer[iLed*4+3] = rgb.blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
int LedDeviceAPA102::switchOff()
|
||||||
|
{
|
||||||
|
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
||||||
|
}
|
42
libsrc/leddevice/LedDeviceAPA102.h
Normal file
42
libsrc/leddevice/LedDeviceAPA102.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// hyperion incluse
|
||||||
|
#include "LedSpiDevice.h"
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Implementation of the LedDevice interface for writing to APA102 led device.
|
||||||
|
///
|
||||||
|
/// APA102 is
|
||||||
|
///
|
||||||
|
class LedDeviceAPA102 : public LedSpiDevice
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Constructs the LedDevice for a string containing leds of the type APA102
|
||||||
|
///
|
||||||
|
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
|
||||||
|
/// @param baudrate The used baudrate for writing to the output device
|
||||||
|
///
|
||||||
|
LedDeviceAPA102(const std::string& outputDevice,
|
||||||
|
const unsigned baudrate);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Writes the led color values to the led-device
|
||||||
|
///
|
||||||
|
/// @param ledValues The color-value per led
|
||||||
|
/// @return Zero on succes else negative
|
||||||
|
///
|
||||||
|
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||||
|
|
||||||
|
/// Switch the leds off
|
||||||
|
virtual int switchOff();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/// The buffer containing the packed RGB values
|
||||||
|
std::vector<uint8_t> _ledBuffer;
|
||||||
|
|
||||||
|
};
|
@ -14,6 +14,7 @@
|
|||||||
#include "LedDeviceLpd8806.h"
|
#include "LedDeviceLpd8806.h"
|
||||||
#include "LedDeviceP9813.h"
|
#include "LedDeviceP9813.h"
|
||||||
#include "LedDeviceWs2801.h"
|
#include "LedDeviceWs2801.h"
|
||||||
|
#include "LedDeviceAPA102.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_TINKERFORGE
|
#ifdef ENABLE_TINKERFORGE
|
||||||
@ -86,6 +87,16 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
|||||||
|
|
||||||
device = deviceP9813;
|
device = deviceP9813;
|
||||||
}
|
}
|
||||||
|
else if (type == "apa102")
|
||||||
|
{
|
||||||
|
const std::string output = deviceConfig["output"].asString();
|
||||||
|
const unsigned rate = deviceConfig["rate"].asInt();
|
||||||
|
|
||||||
|
LedDeviceAPA102* deviceAPA102 = new LedDeviceAPA102(output, rate);
|
||||||
|
deviceAPA102->open();
|
||||||
|
|
||||||
|
device = deviceAPA102;
|
||||||
|
}
|
||||||
else if (type == "ws2801" || type == "lightberry")
|
else if (type == "ws2801" || type == "lightberry")
|
||||||
{
|
{
|
||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
|
Loading…
Reference in New Issue
Block a user