mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
merge adalight and adalightapa102 (#303)
if you want to use adalightapa102 driver, select adalight and set lightberry_apa102_mode : true in device config. Default is standard adalight
This commit is contained in:
parent
1670ec58a7
commit
9ddbf81810
@ -17,7 +17,6 @@ SET(Leddevice_QT_HEADERS
|
|||||||
${CURRENT_HEADER_DIR}/LedDevice.h
|
${CURRENT_HEADER_DIR}/LedDevice.h
|
||||||
${CURRENT_SOURCE_DIR}/ProviderRs232.h
|
${CURRENT_SOURCE_DIR}/ProviderRs232.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.h
|
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.h
|
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||||
${CURRENT_SOURCE_DIR}/ProviderHID.h
|
${CURRENT_SOURCE_DIR}/ProviderHID.h
|
||||||
@ -53,7 +52,6 @@ SET(Leddevice_SOURCES
|
|||||||
${CURRENT_SOURCE_DIR}/ProviderHID.cpp
|
${CURRENT_SOURCE_DIR}/ProviderHID.cpp
|
||||||
|
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalightApa102.cpp
|
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceAtmoOrb.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.cpp
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
|
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
|
||||||
: ProviderRs232()
|
: ProviderRs232()
|
||||||
|
, _ligthBerryAPA102Mode(false)
|
||||||
{
|
{
|
||||||
_deviceReady = init(deviceConfig);
|
_deviceReady = init(deviceConfig);
|
||||||
|
_ligthBerryAPA102Mode = deviceConfig["lightberry_apa102_mode"].toBool(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDevice* LedDeviceAdalight::construct(const QJsonObject &deviceConfig)
|
LedDevice* LedDeviceAdalight::construct(const QJsonObject &deviceConfig)
|
||||||
@ -15,23 +17,56 @@ bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
|
|||||||
{
|
{
|
||||||
ProviderRs232::init(deviceConfig);
|
ProviderRs232::init(deviceConfig);
|
||||||
|
|
||||||
_ledBuffer.resize(6 + _ledRGBCount);
|
// create ledBuffer
|
||||||
|
unsigned int bufferSize = 6; // 6 bytes header
|
||||||
|
unsigned int totalLedCount = _ledCount;
|
||||||
|
|
||||||
|
if (_ligthBerryAPA102Mode)
|
||||||
|
{
|
||||||
|
const unsigned int startFrameSize = 4;
|
||||||
|
const unsigned int bytesPerRGBLed = 4;
|
||||||
|
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), bytesPerRGBLed);
|
||||||
|
bufferSize += (_ledCount * bytesPerRGBLed) + startFrameSize + endFrameSize ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalLedCount -= 1;
|
||||||
|
bufferSize += _ledRGBCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ledBuffer.resize(bufferSize, 0x00);
|
||||||
_ledBuffer[0] = 'A';
|
_ledBuffer[0] = 'A';
|
||||||
_ledBuffer[1] = 'd';
|
_ledBuffer[1] = 'd';
|
||||||
_ledBuffer[2] = 'a';
|
_ledBuffer[2] = 'a';
|
||||||
_ledBuffer[3] = (((unsigned int)_ledCount - 1) >> 8) & 0xFF; // LED count high byte
|
_ledBuffer[3] = (((unsigned int)(totalLedCount)) >> 8) & 0xFF; // LED count high byte
|
||||||
_ledBuffer[4] = ((unsigned int)_ledCount - 1) & 0xFF; // LED count low byte
|
_ledBuffer[4] = ((unsigned int)(totalLedCount)) & 0xFF; // LED count low byte
|
||||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||||
|
|
||||||
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
||||||
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5]
|
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5]
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
||||||
{
|
{
|
||||||
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
if(_ligthBerryAPA102Mode)
|
||||||
|
{
|
||||||
|
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
||||||
|
{
|
||||||
|
const ColorRgb& rgb = ledValues[iLed-1];
|
||||||
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
||||||
|
}
|
||||||
|
|
||||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,5 +30,7 @@ private:
|
|||||||
/// @return Zero on succes else negative
|
/// @return Zero on succes else negative
|
||||||
///
|
///
|
||||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||||
|
|
||||||
|
bool _ligthBerryAPA102Mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
#include "LedDeviceAdalightApa102.h"
|
|
||||||
|
|
||||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const QJsonObject &deviceConfig)
|
|
||||||
: ProviderRs232()
|
|
||||||
{
|
|
||||||
_deviceReady = init(deviceConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
LedDevice* LedDeviceAdalightApa102::construct(const QJsonObject &deviceConfig)
|
|
||||||
{
|
|
||||||
return new LedDeviceAdalightApa102(deviceConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LedDeviceAdalightApa102::init(const QJsonObject &deviceConfig)
|
|
||||||
{
|
|
||||||
ProviderRs232::init(deviceConfig);
|
|
||||||
|
|
||||||
const unsigned int startFrameSize = 4;
|
|
||||||
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), 4);
|
|
||||||
const unsigned int mLedCount = (_ledCount * 4) + startFrameSize + endFrameSize;
|
|
||||||
if(_ledBuffer.size() != mLedCount+6)
|
|
||||||
{
|
|
||||||
_ledBuffer.resize(mLedCount+6, 0x00);
|
|
||||||
_ledBuffer[0] = 'A';
|
|
||||||
_ledBuffer[1] = 'd';
|
|
||||||
_ledBuffer[2] = 'a';
|
|
||||||
_ledBuffer[3] = (((unsigned int)(_ledCount)) >> 8) & 0xFF; // LED count high byte
|
|
||||||
_ledBuffer[4] = ((unsigned int)(_ledCount)) & 0xFF; // LED count low byte
|
|
||||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
|
||||||
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
|
||||||
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5] );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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)
|
|
||||||
{
|
|
||||||
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
|
||||||
{
|
|
||||||
const ColorRgb& rgb = ledValues[iLed-1];
|
|
||||||
_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write data
|
|
||||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// hyperion include
|
|
||||||
#include "LedDeviceAdalight.h"
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
|
||||||
///
|
|
||||||
class LedDeviceAdalightApa102 : public ProviderRs232
|
|
||||||
{
|
|
||||||
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 QJsonObject &deviceConfig);
|
|
||||||
|
|
||||||
/// create leddevice when type in config is set to this type
|
|
||||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
|
||||||
|
|
||||||
virtual bool init(const QJsonObject &deviceConfig);
|
|
||||||
|
|
||||||
private:
|
|
||||||
///
|
|
||||||
/// 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);
|
|
||||||
};
|
|
||||||
|
|
@ -45,7 +45,6 @@
|
|||||||
#include "LedDevicePhilipsHue.h"
|
#include "LedDevicePhilipsHue.h"
|
||||||
#include "LedDeviceTpm2.h"
|
#include "LedDeviceTpm2.h"
|
||||||
#include "LedDeviceAtmo.h"
|
#include "LedDeviceAtmo.h"
|
||||||
#include "LedDeviceAdalightApa102.h"
|
|
||||||
#include "LedDeviceAtmoOrb.h"
|
#include "LedDeviceAtmoOrb.h"
|
||||||
#include "LedDeviceUdpH801.h"
|
#include "LedDeviceUdpH801.h"
|
||||||
|
|
||||||
@ -69,7 +68,6 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const
|
|||||||
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower().toStdString(), LedDevice##className::construct);
|
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower().toStdString(), LedDevice##className::construct);
|
||||||
// rs232 devices
|
// rs232 devices
|
||||||
REGISTER(Adalight);
|
REGISTER(Adalight);
|
||||||
REGISTER(AdalightApa102);
|
|
||||||
REGISTER(Sedu);
|
REGISTER(Sedu);
|
||||||
REGISTER(DMX);
|
REGISTER(DMX);
|
||||||
REGISTER(Tpm2);
|
REGISTER(Tpm2);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/leddevices/">
|
<qresource prefix="/leddevices/">
|
||||||
<file alias="schema-adalightapa102">schemas/schema-adalightapa102.json</file>
|
|
||||||
<file alias="schema-adalight">schemas/schema-adalight.json</file>
|
<file alias="schema-adalight">schemas/schema-adalight.json</file>
|
||||||
<file alias="schema-apa102">schemas/schema-apa102.json</file>
|
<file alias="schema-apa102">schemas/schema-apa102.json</file>
|
||||||
<file alias="schema-atmo">schemas/schema-atmo.json</file>
|
<file alias="schema-atmo">schemas/schema-atmo.json</file>
|
||||||
|
@ -26,6 +26,13 @@
|
|||||||
"default": 5000,
|
"default": 5000,
|
||||||
"append" : "ms",
|
"append" : "ms",
|
||||||
"propertyOrder" : 4
|
"propertyOrder" : 4
|
||||||
|
},
|
||||||
|
"lightberry_apa102_mode": {
|
||||||
|
"type": "boolean",
|
||||||
|
"format": "checkbox",
|
||||||
|
"title":"LightBerry APA102 Mode",
|
||||||
|
"default": false,
|
||||||
|
"propertyOrder" : 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": true
|
"additionalProperties": true
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"type":"object",
|
|
||||||
"required":true,
|
|
||||||
"properties":{
|
|
||||||
"output": {
|
|
||||||
"type": "string",
|
|
||||||
"title":"Output path",
|
|
||||||
"propertyOrder" : 1
|
|
||||||
},
|
|
||||||
"rate": {
|
|
||||||
"type": "integer",
|
|
||||||
"title":"Baudrate",
|
|
||||||
"default": 1000000,
|
|
||||||
"propertyOrder" : 2
|
|
||||||
},
|
|
||||||
"delayAfterConnect": {
|
|
||||||
"type": "integer",
|
|
||||||
"title":"Delay after connect",
|
|
||||||
"default": 250,
|
|
||||||
"append" : "ms",
|
|
||||||
"propertyOrder" : 3
|
|
||||||
},
|
|
||||||
"rewriteTime": {
|
|
||||||
"type": "integer",
|
|
||||||
"title":"refresh time",
|
|
||||||
"default": 5000,
|
|
||||||
"append" : "ms",
|
|
||||||
"propertyOrder" : 4
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": true
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user