make blackboder component enable/disable at runtime (#228)

* make enable/disable of bborder work

* fix typo

* smoothing can be disabled via config again

* fix smoothing
This commit is contained in:
redPanther 2016-09-08 16:32:42 +02:00 committed by GitHub
parent f23178c770
commit 36124c9afb
11 changed files with 95 additions and 70 deletions

View File

@ -11,7 +11,7 @@ $(document).ready(function() {
}
else
{
ledColors = (event.response.result);
ledColors = (event.response.result.leds);
for(var idx=0; idx<ledColors.length; idx++)
{
led = ledColors[idx]

View File

@ -62,7 +62,11 @@ namespace hyperion
BlackBorder imageBorder;
if (!enabled())
{
return false;
imageBorder.horizontalSize = 0;
imageBorder.verticalSize = 0;
imageBorder.unknown=true;
_currentBorder = imageBorder;
return true;
}
if (_detectionMode == "default") {

View File

@ -32,6 +32,7 @@
// Forward class declaration
class LedDevice;
class LinearColorSmoothing;
class ColorTransform;
class EffectEngine;
class HsvTransform;
@ -287,7 +288,7 @@ public:
static RgbChannelAdjustment * createRgbChannelCorrection(const Json::Value& colorConfig);
static RgbChannelAdjustment * createRgbChannelAdjustment(const Json::Value& colorConfig, const RgbChannel color);
static LedDevice * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice);
static LinearColorSmoothing * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice* leddevice);
static MessageForwarder * createMessageForwarder(const Json::Value & forwarderConfig);
signals:
@ -339,6 +340,9 @@ private:
/// The actual LedDevice
LedDevice * _device;
/// The smoothing LedDevice
LinearColorSmoothing * _deviceSmooth;
/// Effect engine
EffectEngine * _effectEngine;

View File

@ -119,6 +119,14 @@ private:
template <typename Pixel_T>
void verifyBorder(const Image<Pixel_T> & image)
{
if (!_borderProcessor->enabled() && ( _imageToLeds->horizontalBorder()!=0 || _imageToLeds->verticalBorder()!=0 ))
{
Debug(Logger::getInstance("BLACKBORDER"), "disabled, reset border");
_borderProcessor->process(image);
delete _imageToLeds;
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
}
if(_borderProcessor->enabled() && _borderProcessor->process(image))
{
Debug(Logger::getInstance("BLACKBORDER"), "BORDER SWITCH REQUIRED!!");

View File

@ -56,6 +56,9 @@ namespace hyperion
///
unsigned height() const;
const unsigned horizontalBorder() const { return _horizontalBorder; };
const unsigned verticalBorder() const { return _verticalBorder; };
///
/// Determines the mean-color for each led using the mapping the image given
/// at construction.
@ -99,6 +102,11 @@ namespace hyperion
const unsigned _width;
/// The height of the indexed image
const unsigned _height;
const unsigned _horizontalBorder;
const unsigned _verticalBorder;
/// The absolute indices into the image for each led
std::vector<std::vector<unsigned>> mColorsMap;

View File

@ -497,34 +497,34 @@ LedString Hyperion::createLedStringClone(const Json::Value& ledsConfig, const Co
return ledString;
}
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
LinearColorSmoothing * 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);
LinearColorSmoothing * device;
type = "linear"; // TODO currently hardcoded type, delete it if we have more types
if ( ! smoothingConfig.get("enable", true).asBool() )
{
Info(log,"Smoothing disabled");
Hyperion::getInstance()->getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, false);
return nullptr;
}
if (type == "linear")
{
Info(log, "Creating linear smoothing");
return new LinearColorSmoothing(
ledDevice,
Info( log, "Creating linear smoothing");
device = new LinearColorSmoothing(
leddevice,
smoothingConfig.get("updateFrequency", 25.0).asDouble(),
smoothingConfig.get("time_ms", 200).asInt(),
smoothingConfig.get("updateDelay", 0).asUInt(),
smoothingConfig.get("continuousOutput", true).asBool()
);
}
else
{
Error(log, "Smoothing disabled, because of unknown type '%s'.", type.c_str());
}
device->setEnable(smoothingConfig.get("enable", true).asBool());
InfoIf(!device->enabled(), log,"Smoothing disabled");
Error(log, "Smoothing disabled, because of unknown type '%s'.", type.c_str());
return nullptr;
return device;
}
MessageForwarder * Hyperion::createMessageForwarder(const Json::Value & forwarderConfig)
@ -575,7 +575,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
, _hwLedCount(_ledString.leds().size())
, _sourceAutoSelectEnabled(true)
{
_device = LedDeviceFactory::construct(jsonConfig["device"]);
registerPriority("Off", PriorityMuxer::LOWEST_PRIORITY);
if (!_raw2ledAdjustment->verifyAdjustments())
@ -604,18 +603,12 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
_ledString,
jsonConfig["blackborderdetector"]
);
//_hyperion->getComponentRegister().componentStateChanged(component, _processor->blackBorderDetectorEnabled());
getComponentRegister().componentStateChanged(hyperion::COMP_FORWARDER, _messageForwarder->forwardingEnabled());
// initialize the color smoothing filter
LedDevice* smoothing = createColorSmoothing(jsonConfig["smoothing"], _device);
if ( smoothing != nullptr )
{
_device = smoothing;
getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, ((LinearColorSmoothing*)_device)->componentState());
connect(this, SIGNAL(componentStateChanged(hyperion::Components,bool)), (LinearColorSmoothing*)_device, SLOT(componentStateChanged(hyperion::Components,bool)));
}
// initialize leddevices
_device = LedDeviceFactory::construct(jsonConfig["device"]);
_deviceSmooth = createColorSmoothing(jsonConfig["smoothing"], _device);
getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, _deviceSmooth->componentState());
// setup the timer
_timer.setSingleShot(true);
@ -700,7 +693,15 @@ bool Hyperion::setCurrentSourcePriority(int priority )
void Hyperion::setComponentState(const hyperion::Components component, const bool state)
{
emit componentStateChanged(component, state);
if (component == hyperion::COMP_SMOOTHING)
{
_deviceSmooth->setEnable(state);
getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, _deviceSmooth->componentState());
}
else
{
emit componentStateChanged(component, state);
}
}
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects)
@ -931,7 +932,10 @@ void Hyperion::update()
}
// Write the data to the device
_device->write(_ledBuffer);
if (_deviceSmooth->enabled())
_deviceSmooth->write(_ledBuffer);
else
_device->write(_ledBuffer);
// Start the timeout-timer
if (priorityInfo.timeoutTime_ms == -1)

View File

@ -13,10 +13,12 @@ ImageToLedsMap::ImageToLedsMap(
const unsigned height,
const unsigned horizontalBorder,
const unsigned verticalBorder,
const std::vector<Led>& leds) :
_width(width),
_height(height),
mColorsMap()
const std::vector<Led>& leds)
: _width(width)
, _height(height)
, _horizontalBorder(horizontalBorder)
, _verticalBorder(verticalBorder)
, mColorsMap()
{
// Sanity check of the size of the borders (and width and height)
assert(width > 2*verticalBorder);

View File

@ -15,7 +15,7 @@ LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpd
, _outputDelay(updateDelay)
, _writeToLedsEnable(true)
, _continuousOutput(continuousOutput)
, _bypass(false)
, _enabled(true)
{
_log = Logger::getInstance("Smoothing");
_timer.setSingleShot(false);
@ -35,28 +35,21 @@ LinearColorSmoothing::~LinearColorSmoothing()
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
{
if (_bypass)
// received a new target color
if (_previousValues.empty())
{
_ledDevice->write(ledValues);
// not initialized yet
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
_targetValues = ledValues;
_previousTime = QDateTime::currentMSecsSinceEpoch();
_previousValues = ledValues;
_timer.start();
}
else
{
// 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));
}
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
}
return 0;
@ -139,13 +132,13 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
}
}
void LinearColorSmoothing::componentStateChanged(const hyperion::Components component, bool enable)
void LinearColorSmoothing::setEnable(bool enable)
{
if (component == COMP_SMOOTHING)
{
InfoIf(_bypass == enable, _log, "change state to %s", (enable ? "enabled" : "disabled") );
Hyperion::getInstance()->getComponentRegister().componentStateChanged(component, enable);
_bypass = !enable;
}
_enabled = enable;
}
bool LinearColorSmoothing::enabled()
{
return _enabled;
}

View File

@ -40,14 +40,15 @@ public:
/// Switch the leds off
virtual int switchOff();
bool componentState() { return !_bypass; }
void setEnable(bool enable);
bool enabled();
bool componentState() { return enabled(); };
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
@ -91,5 +92,5 @@ private:
/// Flag for dis/enable continuous output to led device regardless there is new data or not
bool _continuousOutput;
bool _bypass;
bool _enabled;
};

View File

@ -1157,8 +1157,9 @@ bool JsonClientConnection::checkJson(const Json::Value & message, const QString
void JsonClientConnection::streamLedcolorsUpdate()
{
Json::Value & leds = _streaming_leds_reply["result"] = Json::Value(Json::arrayValue);
Json::Value & leds = _streaming_leds_reply["result"]["leds"] = Json::Value(Json::arrayValue);
//QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
std::vector<ColorRgb> ledBuffer = priorityInfo.ledColors;

View File

@ -2,7 +2,7 @@
STATS_FAILED=0
STATS_SUCCESS=0
STATS_SKIPED=0
STATS_SKIPPED=0
STATS_TOTAL=0
@ -13,7 +13,7 @@ function exec_test()
if [ ! -e "$2" ]
then
echo "skip test: '$test_name'"
(( STATS_SKIPED++ ))
(( STATS_SKIPPED++ ))
return
fi
shift
@ -52,7 +52,7 @@ echo "TEST SUMMARY"
echo "============"
echo " total: $STATS_TOTAL"
echo " success: $STATS_SUCCESS"
echo " skiped: $STATS_SKIPED"
echo " skipped: $STATS_SKIPPED"
echo " failed: $STATS_FAILED"
sleep 2