mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge remote-tracking branch 'upstream/master' into support_for_philips_hue
Former-commit-id: 51089fb3522bf9c228d67f2c2f9a1a5b33e5d0a5
This commit is contained in:
@@ -14,7 +14,8 @@ BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt,
|
||||
_detector(blackborderThreshold),
|
||||
_currentBorder({true, -1, -1}),
|
||||
_previousDetectedBorder({true, -1, -1}),
|
||||
_consistentCnt(0)
|
||||
_consistentCnt(0),
|
||||
_inconsistentCnt(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
@@ -30,11 +31,13 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||
if (newDetectedBorder == _previousDetectedBorder)
|
||||
{
|
||||
++_consistentCnt;
|
||||
_inconsistentCnt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousDetectedBorder = newDetectedBorder;
|
||||
_consistentCnt = 0;
|
||||
++_inconsistentCnt;
|
||||
}
|
||||
|
||||
// check if there is a change
|
||||
@@ -64,14 +67,18 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||
}
|
||||
else
|
||||
{
|
||||
// apply smaller borders immediately
|
||||
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
||||
bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 );
|
||||
//more then 10 consistent seems like a new size not only a short flicker
|
||||
//more then 30 inconsistent seems like the image is changing a lot and we need to set smaller border
|
||||
|
||||
// apply smaller borders (almost) immediately -> avoid switching for "abnormal" frames
|
||||
if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )
|
||||
{
|
||||
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
||||
borderChanged = true;
|
||||
}
|
||||
|
||||
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
||||
if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) )
|
||||
{
|
||||
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
||||
borderChanged = true;
|
||||
@@ -80,4 +87,4 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||
}
|
||||
|
||||
return borderChanged;
|
||||
}
|
||||
}
|
@@ -59,13 +59,16 @@ void BoblightClientConnection::readData()
|
||||
while(bytes > 0)
|
||||
{
|
||||
// create message string (strip the newline)
|
||||
#ifdef ENABLE_QT5
|
||||
QString message = QString::fromLatin1(_receiveBuffer.data(), bytes-1);
|
||||
#else
|
||||
QString message = QString::fromAscii(_receiveBuffer.data(), bytes-1);
|
||||
|
||||
#endif
|
||||
// remove message data from buffer
|
||||
_receiveBuffer = _receiveBuffer.mid(bytes);
|
||||
|
||||
// handle message
|
||||
handleMessage(message);
|
||||
// handle trimmed message
|
||||
handleMessage(message.trimmed());
|
||||
|
||||
// drop messages if the buffer is too full
|
||||
if (_receiveBuffer.size() > 100*1024)
|
||||
@@ -132,9 +135,15 @@ void BoblightClientConnection::handleMessage(const QString & message)
|
||||
{
|
||||
if (messageParts[3] == "rgb" && messageParts.size() == 7)
|
||||
{
|
||||
// replace decimal comma with decimal point
|
||||
messageParts[4].replace(',', '.');
|
||||
messageParts[5].replace(',', '.');
|
||||
messageParts[6].replace(',', '.');
|
||||
|
||||
bool rc1, rc2, rc3;
|
||||
uint8_t red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1))));
|
||||
|
||||
// check for correct locale should not be needed anymore - please check!
|
||||
if (!rc1)
|
||||
{
|
||||
// maybe a locale issue. switch to a locale with a comma instead of a dot as decimal seperator (or vice versa)
|
||||
|
@@ -17,7 +17,11 @@ set(BoblightServer_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/BoblightClientConnection.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
qt4_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(boblightserver
|
||||
${BoblightServer_HEADERS}
|
||||
@@ -26,6 +30,10 @@ add_library(boblightserver
|
||||
${BoblightServer_HEADERS_MOC}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(boblightserver Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(boblightserver
|
||||
hyperion
|
||||
hyperion-utils
|
||||
|
@@ -27,9 +27,13 @@ SET(EffectEngineSOURCES
|
||||
|
||||
set(EffectEngine_RESOURCES ${CURRENT_SOURCE_DIR}/EffectEngine.qrc)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
||||
qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
||||
|
||||
qt4_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(effectengine
|
||||
${EffectEngineHEADERS}
|
||||
@@ -39,6 +43,10 @@ add_library(effectengine
|
||||
${EffectEngineSOURCES}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(effectengine Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(effectengine
|
||||
hyperion
|
||||
jsoncpp
|
||||
|
@@ -75,7 +75,11 @@ const std::list<EffectDefinition> &EffectEngine::getEffects() const
|
||||
|
||||
bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition)
|
||||
{
|
||||
#ifdef ENABLE_QT5
|
||||
std::string fileName = path + QDir::separator().toLatin1() + effectConfigFile;
|
||||
#else
|
||||
std::string fileName = path + QDir::separator().toAscii() + effectConfigFile;
|
||||
#endif
|
||||
std::ifstream file(fileName.c_str());
|
||||
|
||||
if (!file.is_open())
|
||||
@@ -110,7 +114,11 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri
|
||||
|
||||
// setup the definition
|
||||
effectDefinition.name = config["name"].asString();
|
||||
#ifdef ENABLE_QT5
|
||||
effectDefinition.script = path + QDir::separator().toLatin1() + config["script"].asString();
|
||||
#else
|
||||
effectDefinition.script = path + QDir::separator().toAscii() + config["script"].asString();
|
||||
#endif
|
||||
effectDefinition.args = config["args"];
|
||||
|
||||
// return succes
|
||||
|
@@ -15,7 +15,11 @@ SET(AmlogicSOURCES
|
||||
${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(amlogic-grabber
|
||||
${AmlogicHEADERS}
|
||||
|
@@ -21,7 +21,11 @@ SET(DispmanxGrabberSOURCES
|
||||
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(dispmanx-grabber
|
||||
${DispmanxGrabberHEADERS}
|
||||
|
@@ -21,7 +21,11 @@ SET(FramebufferGrabberSOURCES
|
||||
${CURRENT_SOURCE_DIR}/FramebufferFrameGrabber.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(framebuffer-grabber
|
||||
${FramebufferGrabberHEADERS}
|
||||
|
@@ -16,7 +16,11 @@ SET(OsxGrabberSOURCES
|
||||
${CURRENT_SOURCE_DIR}/OsxFrameGrabber.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(osx-grabber
|
||||
${OsxGrabberHEADERS}
|
||||
|
@@ -16,7 +16,11 @@ SET(V4L2_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(v4l2-grabber
|
||||
${V4L2_HEADERS}
|
||||
@@ -25,6 +29,10 @@ add_library(v4l2-grabber
|
||||
${V4L2_HEADERS_MOC}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(v4l2-grabber Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(v4l2-grabber
|
||||
hyperion
|
||||
${QT_LIBRARIES}
|
||||
|
@@ -22,7 +22,11 @@ SET(X11_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(x11-grabber
|
||||
${X11_HEADERS}
|
||||
|
@@ -36,9 +36,13 @@ set(Hyperion_RESOURCES
|
||||
${CURRENT_SOURCE_DIR}/resource.qrc
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
|
||||
QT5_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
|
||||
|
||||
QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(hyperion
|
||||
${Hyperion_HEADERS}
|
||||
@@ -48,6 +52,10 @@ add_library(hyperion
|
||||
${Hyperion_RESOURCES_RCC}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(hyperion Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(hyperion
|
||||
blackborder
|
||||
hyperion-utils
|
||||
|
@@ -20,10 +20,13 @@ set(JsonServer_SOURCES
|
||||
set(JsonServer_RESOURCES
|
||||
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
||||
qt5_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
|
||||
else(ENABLE_QT5)
|
||||
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
|
||||
|
||||
qt4_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(jsonserver
|
||||
${JsonServer_HEADERS}
|
||||
@@ -34,6 +37,10 @@ add_library(jsonserver
|
||||
${JsonServer_RESOURCES_RCC}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(jsonserver Widgets Network)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(jsonserver
|
||||
hyperion
|
||||
hyperion-utils
|
||||
|
@@ -20,6 +20,8 @@ SET(Leddevice_QT_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
${CURRENT_SOURCE_DIR}/LedHIDDevice.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||
)
|
||||
|
||||
SET(Leddevice_HEADERS
|
||||
@@ -32,6 +34,7 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
|
||||
@@ -53,6 +56,7 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
|
||||
@@ -102,8 +106,12 @@ if(ENABLE_TINKERFORGE)
|
||||
)
|
||||
endif(ENABLE_TINKERFORGE)
|
||||
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
|
||||
add_library(leddevice
|
||||
${Leddevice_HEADERS}
|
||||
@@ -112,9 +120,13 @@ add_library(leddevice
|
||||
${Leddevice_SOURCES}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(leddevice Widgets Network)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(leddevice
|
||||
hyperion-utils
|
||||
serialport
|
||||
serialport
|
||||
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${QT_LIBRARIES}
|
||||
|
@@ -3,7 +3,6 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
@@ -13,30 +12,38 @@
|
||||
#include "LedDeviceAdalightApa102.h"
|
||||
|
||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||
LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms),
|
||||
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
|
||||
_ledBuffer(0),
|
||||
_timer()
|
||||
{
|
||||
// setup the timer
|
||||
_timer.setSingleShot(false);
|
||||
_timer.setInterval(5000);
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
||||
|
||||
// start the timer
|
||||
_timer.start();
|
||||
}
|
||||
//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)
|
||||
{
|
||||
ledCount = ledValues.size();
|
||||
const unsigned int startFrameSize = 4;
|
||||
const unsigned int endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 4);
|
||||
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
||||
if(_ledBuffer.size() != mLedCount){
|
||||
_ledBuffer.resize(mLedCount, 0xFF);
|
||||
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)(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[3] = (((unsigned int)(ledValues.size())) >> 8) & 0xFF; // LED count high byte
|
||||
_ledBuffer[4] = ((unsigned int)(ledValues.size())) & 0xFF; // LED count low byte
|
||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||
}
|
||||
|
||||
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
|
||||
|
||||
for (unsigned iLed=1; iLed<=ledCount; iLed++) {
|
||||
const ColorRgb& rgb = ledValues[iLed-1];
|
||||
_ledBuffer[iLed*4+6] = 0xFF;
|
||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||
@@ -51,4 +58,25 @@ int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
int LedDeviceAdalightApa102::switchOff()
|
||||
{
|
||||
for (unsigned iLed=1; iLed<=ledCount; iLed++) {
|
||||
_ledBuffer[iLed*4+6] = 0xFF;
|
||||
_ledBuffer[iLed*4+1+6] = 0x00;
|
||||
_ledBuffer[iLed*4+2+6] = 0x00;
|
||||
_ledBuffer[iLed*4+3+6] = 0x00;
|
||||
}
|
||||
|
||||
// restart the timer
|
||||
_timer.start();
|
||||
|
||||
// write data
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
|
||||
}
|
||||
|
||||
void LedDeviceAdalightApa102::rewriteLeds()
|
||||
{
|
||||
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
@@ -7,12 +7,12 @@
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedDeviceAdalight.h"
|
||||
#include "LedRs232Device.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an Adalight led device for APA102.
|
||||
///
|
||||
class LedDeviceAdalightApa102 : public LedDeviceAdalight
|
||||
class LedDeviceAdalightApa102 : public LedRs232Device
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -32,13 +32,17 @@ public:
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||
virtual int switchOff();
|
||||
|
||||
|
||||
|
||||
private slots:
|
||||
/// Write the last data to the leds again
|
||||
void rewriteLeds();
|
||||
|
||||
private:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
unsigned int ledCount;
|
||||
/// 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
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "LedDevicePiBlaster.h"
|
||||
#include "LedDeviceSedu.h"
|
||||
#include "LedDeviceTest.h"
|
||||
#include "LedDeviceFadeCandy.h"
|
||||
#include "LedDeviceHyperionUsbasp.h"
|
||||
#include "LedDevicePhilipsHue.h"
|
||||
#include "LedDeviceTpm2.h"
|
||||
@@ -243,6 +244,12 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
device = new LedDeviceTest(output);
|
||||
}
|
||||
else if (type == "fadecandy")
|
||||
{
|
||||
const std::string host = deviceConfig.get("output", "127.0.0.1").asString();
|
||||
const uint16_t port = deviceConfig.get("port", 7890).asInt();
|
||||
device = new LedDeviceFadeCandy(host,port);
|
||||
}
|
||||
else if (type == "tpm2")
|
||||
{
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
|
93
libsrc/leddevice/LedDeviceFadeCandy.cpp
Executable file
93
libsrc/leddevice/LedDeviceFadeCandy.cpp
Executable file
@@ -0,0 +1,93 @@
|
||||
#include "LedDeviceFadeCandy.h"
|
||||
|
||||
static const unsigned MAX_NUM_LEDS = 512;
|
||||
static const unsigned OPC_BROADCAST = 0; // OPC broadcast channel
|
||||
static const unsigned OPC_SET_PIXELS = 0; // OPC command codes
|
||||
static const unsigned OPC_HEADER_SIZE = 4; // OPC header size
|
||||
|
||||
|
||||
LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port) :
|
||||
_host(host), _port(port)
|
||||
{
|
||||
_opc_data.resize( OPC_HEADER_SIZE );
|
||||
_opc_data[0] = OPC_BROADCAST;
|
||||
_opc_data[1] = OPC_SET_PIXELS;
|
||||
_opc_data[2] = 0;
|
||||
_opc_data[3] = 0;
|
||||
}
|
||||
|
||||
|
||||
LedDeviceFadeCandy::~LedDeviceFadeCandy()
|
||||
{
|
||||
_client.close();
|
||||
}
|
||||
|
||||
|
||||
bool LedDeviceFadeCandy::isConnected()
|
||||
{
|
||||
return _client.state() == QAbstractSocket::ConnectedState;
|
||||
}
|
||||
|
||||
|
||||
bool LedDeviceFadeCandy::tryConnect()
|
||||
{
|
||||
if ( _client.state() == QAbstractSocket::UnconnectedState ) {
|
||||
qDebug("connecting to %s %i",_host.c_str(),_port);
|
||||
|
||||
_client.connectToHost( _host.c_str(), _port);
|
||||
if ( _client.waitForConnected(1000) )
|
||||
qDebug("connected");
|
||||
}
|
||||
|
||||
return isConnected();
|
||||
}
|
||||
|
||||
|
||||
int LedDeviceFadeCandy::write( const std::vector<ColorRgb> & ledValues )
|
||||
{
|
||||
ssize_t nrLedValues = ledValues.size();
|
||||
ssize_t led_data_size = nrLedValues * 3; // 3 color bytes
|
||||
ssize_t opc_data_size = led_data_size + OPC_HEADER_SIZE;
|
||||
|
||||
if (nrLedValues > MAX_NUM_LEDS)
|
||||
{
|
||||
std::cerr << "Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( opc_data_size != _opc_data.size() )
|
||||
_opc_data.resize( opc_data_size );
|
||||
|
||||
_opc_data[2] = led_data_size >> 8;
|
||||
_opc_data[3] = led_data_size & 0xff;
|
||||
|
||||
uint idx = OPC_HEADER_SIZE;
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
_opc_data[idx ] = unsigned( color.red );
|
||||
_opc_data[idx+1] = unsigned( color.green );
|
||||
_opc_data[idx+2] = unsigned( color.blue );
|
||||
idx += 3;
|
||||
}
|
||||
|
||||
return ( transferData()<0 ? -1 : 0 );
|
||||
}
|
||||
|
||||
|
||||
int LedDeviceFadeCandy::transferData()
|
||||
{
|
||||
if ( isConnected() || tryConnect() )
|
||||
return _client.write( _opc_data, _opc_data.size() );
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
int LedDeviceFadeCandy::switchOff()
|
||||
{
|
||||
for ( int idx=OPC_HEADER_SIZE; idx < _opc_data.size(); idx++ )
|
||||
_opc_data[idx] = 0;
|
||||
|
||||
return ( transferData()<0 ? -1 : 0 );
|
||||
}
|
||||
|
70
libsrc/leddevice/LedDeviceFadeCandy.h
Executable file
70
libsrc/leddevice/LedDeviceFadeCandy.h
Executable file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
// STL/Qt includes
|
||||
#include <fstream>
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for sending to
|
||||
/// fadecandy/opc-server via network by using the 'open pixel control' protocol.
|
||||
///
|
||||
class LedDeviceFadeCandy : public QObject, public LedDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the LedDevice for fadecandy/opc server
|
||||
///
|
||||
/// @param host The ip address/host name of fadecandy/opc server
|
||||
/// @param port The port to use (fadecandy default is 7890)
|
||||
///
|
||||
LedDeviceFadeCandy(const std::string& host, const uint16_t port);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the tcp client
|
||||
///
|
||||
virtual ~LedDeviceFadeCandy();
|
||||
|
||||
///
|
||||
/// 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:
|
||||
QTcpSocket _client;
|
||||
const std::string _host;
|
||||
const uint16_t _port;
|
||||
QByteArray _opc_data;
|
||||
|
||||
/// try to establish connection to opc server, if not connected yet
|
||||
///
|
||||
/// @return true if connection is established
|
||||
///
|
||||
bool tryConnect();
|
||||
|
||||
/// return the conenction state
|
||||
///
|
||||
/// @return True if connection established
|
||||
///
|
||||
bool isConnected();
|
||||
|
||||
|
||||
/// transfer current opc_data buffer to opc server
|
||||
///
|
||||
/// @return amount of transfered bytes. -1 error while transfering, -2 error while connecting
|
||||
///
|
||||
int transferData();
|
||||
|
||||
};
|
@@ -5,7 +5,7 @@
|
||||
#include <json/json.h>
|
||||
|
||||
// qt includes
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkReply>
|
||||
|
||||
@@ -200,22 +200,30 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
||||
// Next light id.
|
||||
idx++;
|
||||
}
|
||||
#ifdef ENABLE_QT5
|
||||
|
||||
#else
|
||||
timer.start();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedDevicePhilipsHue::switchOff() {
|
||||
#ifdef ENABLE_QT5
|
||||
|
||||
#else
|
||||
timer.stop();
|
||||
// If light states have been saved before, ...
|
||||
if (areStatesSaved()) {
|
||||
// ... restore them.
|
||||
restoreStates();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
// Perfrom request
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = manager->put(request, content.toAscii());
|
||||
@@ -226,8 +234,8 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
// Perfrom request
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = manager->get(request);
|
||||
@@ -236,8 +244,8 @@ QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
// Read all data of the response.
|
||||
return reply->readAll();
|
||||
// Read all data of the response.
|
||||
return reply->readAll();
|
||||
}
|
||||
|
||||
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include <QString>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QTimer>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
@@ -165,7 +164,7 @@ private:
|
||||
/// User name for the API ("newdeveloper")
|
||||
QString username;
|
||||
/// QNetworkAccessManager object for sending requests.
|
||||
QNetworkAccessManager* manager;
|
||||
QNetworkAccessManager* manager;
|
||||
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
|
||||
QTimer timer;
|
||||
///
|
||||
|
@@ -34,7 +34,11 @@ protobuf_generate_cpp(ProtoServer_PROTO_SRCS ProtoServer_PROTO_HDRS
|
||||
${ProtoServer_PROTOS}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
qt4_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(protoserver
|
||||
${ProtoServer_HEADERS}
|
||||
@@ -45,6 +49,9 @@ add_library(protoserver
|
||||
${ProtoServer_PROTO_SRCS}
|
||||
${ProtoServer_PROTO_HDRS}
|
||||
)
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(protoserver Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(protoserver
|
||||
hyperion
|
||||
|
@@ -15,7 +15,11 @@ SET(XBMCVideoChecker_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
QT5_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||
else(ENABLE_QT5)
|
||||
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
add_library(xbmcvideochecker
|
||||
${XBMCVideoChecker_HEADERS}
|
||||
@@ -24,6 +28,10 @@ add_library(xbmcvideochecker
|
||||
${XBMCVideoChecker_SOURCES}
|
||||
)
|
||||
|
||||
if(ENABLE_QT5)
|
||||
qt5_use_modules(xbmcvideochecker Widgets)
|
||||
endif(ENABLE_QT5)
|
||||
|
||||
target_link_libraries(xbmcvideochecker
|
||||
hyperion
|
||||
${QT_LIBRARIES})
|
||||
|
Reference in New Issue
Block a user