mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge pull request #393 from LightberryEu/master
APA102 implementation for Adalight Former-commit-id: 60d2efea7fdc9b995039132fb0a399aa65c4bc17
This commit is contained in:
commit
7e72600afd
@ -15,6 +15,7 @@ include_directories(
|
||||
SET(Leddevice_QT_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
)
|
||||
@ -40,6 +41,7 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
|
||||
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAmbiLed.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.cpp
|
||||
|
@ -40,7 +40,7 @@ private slots:
|
||||
/// Write the last data to the leds again
|
||||
void rewriteLeds();
|
||||
|
||||
private:
|
||||
protected:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
|
53
libsrc/leddevice/LedDeviceAdalightApa102.cpp
Normal file
53
libsrc/leddevice/LedDeviceAdalightApa102.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceAdalightApa102.h"
|
||||
|
||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||
LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms),
|
||||
_ledBuffer(0),
|
||||
_timer()
|
||||
{
|
||||
}
|
||||
//comparing to ws2801 adalight, the following changes were needed:
|
||||
// 1- differnt data frame (4 bytes instead of 3)
|
||||
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd
|
||||
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
const unsigned int startFrameSize = 4;
|
||||
const unsigned int endFrameSize = (ledValues.size() + 63) / 64 * 4;
|
||||
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
||||
if(_ledBuffer.size() != mLedCount){
|
||||
_ledBuffer.resize(mLedCount, 0x00);
|
||||
_ledBuffer[0] = 'A';
|
||||
_ledBuffer[1] = 'd';
|
||||
_ledBuffer[2] = 'a';
|
||||
_ledBuffer[3] = (((unsigned int)(ledValues.size() * 1.33) - 1) >> 8) & 0xFF; // LED count high byte
|
||||
_ledBuffer[4] = ((unsigned int)(ledValues.size() * 1.33) - 1) & 0xFF; // LED count low byte
|
||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||
}
|
||||
|
||||
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
_ledBuffer[iLed*4+6] = 0xFF;
|
||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||
_ledBuffer[iLed*4+2+6] = rgb.green;
|
||||
_ledBuffer[iLed*4+3+6] = rgb.blue;
|
||||
}
|
||||
|
||||
// restart the timer
|
||||
_timer.start();
|
||||
|
||||
// write data
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
46
libsrc/leddevice/LedDeviceAdalightApa102.h
Normal file
46
libsrc/leddevice/LedDeviceAdalightApa102.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <string>
|
||||
|
||||
// Qt includes
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedDeviceAdalight.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
||||
///
|
||||
class LedDeviceAdalightApa102 : public LedDeviceAdalight
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the LedDevice for attached Adalight device
|
||||
///
|
||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||
/// @param baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
|
||||
|
||||
///
|
||||
/// 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);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
/// Timer object which makes sure that led data is written at a minimum rate
|
||||
/// The Adalight device will switch off when it does not receive data at least
|
||||
/// every 15 seconds
|
||||
QTimer _timer;
|
||||
};
|
@ -33,6 +33,7 @@
|
||||
#include "LedDevicePhilipsHue.h"
|
||||
#include "LedDeviceTpm2.h"
|
||||
#include "LedDeviceAtmo.h"
|
||||
#include "LedDeviceAdalightApa102.h"
|
||||
|
||||
#ifdef ENABLE_WS2812BPWM
|
||||
#include "LedDeviceWS2812b.h"
|
||||
@ -58,6 +59,17 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
|
||||
device = deviceAdalight;
|
||||
}
|
||||
else if (type == "adalightapa102")
|
||||
{
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
const unsigned rate = deviceConfig["rate"].asInt();
|
||||
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
|
||||
|
||||
LedDeviceAdalightApa102* deviceAdalightApa102 = new LedDeviceAdalightApa102(output, rate, delay_ms);
|
||||
deviceAdalightApa102->open();
|
||||
|
||||
device = deviceAdalightApa102;
|
||||
}
|
||||
else if (type == "ambiled")
|
||||
{
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
|
Loading…
Reference in New Issue
Block a user