enable components at runtime + grabber refactoring (#160)

* implement enable/disable on runtime for:
- smoothing
- kodi
- udplistener
- boblight

* implement enable/disable for forwarder
refactor component

* - implement grabber enable/disable at runtime
- big grabber refactoring. now with common base class for all grabbers

* implement enable/disable at runtime for bb detector

* osx fix

* try to fix cutted travis output for osx build
This commit is contained in:
redPanther
2016-08-11 07:13:55 +02:00
committed by GitHub
parent 0d3f6c7ba1
commit f1cc82b8c7
36 changed files with 471 additions and 495 deletions

View File

@@ -8,6 +8,7 @@ SET(Hyperion_QT_HEADERS
${CURRENT_HEADER_DIR}/Hyperion.h
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.h
${CURRENT_HEADER_DIR}/GrabberWrapper.h
)
SET(Hyperion_HEADERS
@@ -36,6 +37,7 @@ SET(Hyperion_SOURCES
${CURRENT_SOURCE_DIR}/MultiColorAdjustment.cpp
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp
${CURRENT_SOURCE_DIR}/MessageForwarder.cpp
${CURRENT_SOURCE_DIR}/GrabberWrapper.cpp
)
SET(Hyperion_RESOURCES

View File

@@ -0,0 +1,62 @@
// Hyperion includes
#include <hyperion/ImageProcessorFactory.h>
#include <hyperion/ImageProcessor.h>
#include <hyperion/GrabberWrapper.h>
GrabberWrapper::GrabberWrapper(std::string grabberName, const int priority)
: _grabberName(grabberName)
, _hyperion(Hyperion::getInstance())
, _priority(priority)
, _timer()
, _log(Logger::getInstance(grabberName.c_str()))
, _forward(true)
, _processor(ImageProcessorFactory::getInstance().newImageProcessor())
{
_timer.setSingleShot(false);
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool)));
connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
GrabberWrapper::~GrabberWrapper()
{
delete _processor;
}
bool GrabberWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
_hyperion->registerPriority(_grabberName,_priority);
return _timer.isActive();
}
void GrabberWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
_hyperion->unRegisterPriority(_grabberName);
}
void GrabberWrapper::componentStateChanged(const hyperion::Components component, bool enable)
{
if (component == hyperion::COMP_GRABBER && _timer.isActive() != enable)
{
if (enable) start();
else stop();
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
Info(_log, "grabber change state to %s", (enable ? "enabled" : "disabled") );
}
if (component == hyperion::COMP_BLACKBORDER && _processor->blackBorderDetectorEnabled() != enable)
{
_processor->enableBlackBorderDetector(enable);
Info(_log, "bb detector change state to %s", (_processor->blackBorderDetectorEnabled() ? "enabled" : "disabled") );
}
}

View File

@@ -498,7 +498,7 @@ LedString Hyperion::createLedStringClone(const Json::Value& ledsConfig, const Co
}
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
{
{
Logger * log = Logger::getInstance("Core");
std::string type = smoothingConfig.get("type", "linear").asString();
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
@@ -507,7 +507,7 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
if ( ! smoothingConfig.get("enable", true).asBool() )
{
Info(log,"Smoothing disabled");
return ledDevice;
return nullptr;
}
if (type == "linear")
@@ -523,7 +523,7 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
}
Error(log, "Smoothing disabled, because of unknown type '%s'.", type.c_str());
return ledDevice;
return nullptr;
}
MessageForwarder * Hyperion::createMessageForwarder(const Json::Value & forwarderConfig)
@@ -605,8 +605,12 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
);
// initialize the color smoothing filter
_device = createColorSmoothing(jsonConfig["smoothing"], _device);
LedDevice* smoothing = createColorSmoothing(jsonConfig["smoothing"], _device);
if ( smoothing != nullptr )
{
_device = smoothing;
connect(this, SIGNAL(componentStateChanged(hyperion::Components,bool)), (LinearColorSmoothing*)_device, SLOT(componentStateChanged(hyperion::Components,bool)));
}
// setup the timer
_timer.setSingleShot(true);
@@ -689,33 +693,9 @@ bool Hyperion::setCurrentSourcePriority(int priority )
return priorityValid;
}
void Hyperion::setComponentState(const Components component, const bool state)
void Hyperion::setComponentState(const hyperion::Components component, const bool state)
{
switch(component)
{
case SMOOTHING:
break;
case BLACKBORDER:
break;
case KODICHECKER:
{
KODIVideoChecker* kodiVideoChecker = KODIVideoChecker::getInstance();
if (kodiVideoChecker != nullptr)
state ? kodiVideoChecker->start() : kodiVideoChecker->stop();
else
Debug(_log, "Can't get instance from: '%s'", componentToString(component));
break;
}
case FORWARDER:
//_messageForwarder
break;
case UDPLISTENER:
break;
case BOBLIGHTSERVER:
break;
case GRABBER:
break;
}
emit componentStateChanged(component, state);
}
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects)

View File

@@ -48,6 +48,11 @@ void ImageProcessor::enableBlackBorderDetector(bool enable)
_borderProcessor->setEnabled(enable);
}
bool ImageProcessor::blackBorderDetectorEnabled()
{
return _borderProcessor->enabled();
}
bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
{
if (led < _ledString.leds().size())

View File

@@ -3,6 +3,8 @@
#include "LinearColorSmoothing.h"
using namespace hyperion;
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput)
: QObject()
, LedDevice()
@@ -13,15 +15,16 @@ LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpd
, _outputDelay(updateDelay)
, _writeToLedsEnable(true)
, _continuousOutput(continuousOutput)
, _bypass(false)
{
_log = Logger::getInstance("Smoothing");
_timer.setSingleShot(false);
_timer.setInterval(_updateInterval);
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
Info(Logger::getInstance("Smoothing"),
"Created linear-smoothing with interval: %d ms, settlingTime: %d ms, updateDelay: %d frames",
_updateInterval, settlingTime_ms, _outputDelay );
Info( _log, "Created linear-smoothing with interval: %d ms, settlingTime: %d ms, updateDelay: %d frames",
_updateInterval, settlingTime_ms, _outputDelay );
}
LinearColorSmoothing::~LinearColorSmoothing()
@@ -33,21 +36,28 @@ LinearColorSmoothing::~LinearColorSmoothing()
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
{
// received a new target color
if (_previousValues.empty())
if (_bypass)
{
// not initialized yet
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
_targetValues = ledValues;
_previousTime = QDateTime::currentMSecsSinceEpoch();
_previousValues = ledValues;
_timer.start();
_ledDevice->write(ledValues);
}
else
{
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
// received a new target color
if (_previousValues.empty())
{
// not initialized yet
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
_targetValues = ledValues;
_previousTime = QDateTime::currentMSecsSinceEpoch();
_previousValues = ledValues;
_timer.start();
}
else
{
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
}
}
return 0;
@@ -129,3 +139,13 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
}
}
}
void LinearColorSmoothing::componentStateChanged(const hyperion::Components component, bool enable)
{
if (component == COMP_SMOOTHING && _bypass == enable)
{
_bypass = !enable;
Info(_log, "change state to %s", (enable ? "enabled" : "disabled") );
}
}

View File

@@ -9,6 +9,7 @@
// hyperion incluse
#include <leddevice/LedDevice.h>
#include <utils/Components.h>
/// Linear Smooting class
///
@@ -39,10 +40,14 @@ public:
/// Switch the leds off
virtual int switchOff();
bool componentState() { return _bypass; }
private slots:
/// Timer callback which writes updated led values to the led device
void updateLeds();
void componentStateChanged(const hyperion::Components component, bool enable);
private:
/**
* Pushes the colors into the output queue and popping the head to the led-device
@@ -85,4 +90,6 @@ private:
/// Flag for dis/enable continuous output to led device regardless there is new data or not
bool _continuousOutput;
bool _bypass;
};