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 else
{ {
ledColors = (event.response.result); ledColors = (event.response.result.leds);
for(var idx=0; idx<ledColors.length; idx++) for(var idx=0; idx<ledColors.length; idx++)
{ {
led = ledColors[idx] led = ledColors[idx]

View File

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

View File

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

View File

@ -119,6 +119,14 @@ private:
template <typename Pixel_T> template <typename Pixel_T>
void verifyBorder(const Image<Pixel_T> & image) 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)) if(_borderProcessor->enabled() && _borderProcessor->process(image))
{ {
Debug(Logger::getInstance("BLACKBORDER"), "BORDER SWITCH REQUIRED!!"); Debug(Logger::getInstance("BLACKBORDER"), "BORDER SWITCH REQUIRED!!");

View File

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

View File

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

View File

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

View File

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

View File

@ -40,14 +40,15 @@ public:
/// Switch the leds off /// Switch the leds off
virtual int switchOff(); virtual int switchOff();
bool componentState() { return !_bypass; } void setEnable(bool enable);
bool enabled();
bool componentState() { return enabled(); };
private slots: private slots:
/// Timer callback which writes updated led values to the led device /// Timer callback which writes updated led values to the led device
void updateLeds(); void updateLeds();
void componentStateChanged(const hyperion::Components component, bool enable);
private: private:
/** /**
* Pushes the colors into the output queue and popping the head to the led-device * 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 /// Flag for dis/enable continuous output to led device regardless there is new data or not
bool _continuousOutput; bool _continuousOutput;
bool _bypass; bool _enabled;
}; };

View File

@ -1157,7 +1157,8 @@ bool JsonClientConnection::checkJson(const Json::Value & message, const QString
void JsonClientConnection::streamLedcolorsUpdate() 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()); const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
std::vector<ColorRgb> ledBuffer = priorityInfo.ledColors; std::vector<ColorRgb> ledBuffer = priorityInfo.ledColors;

View File

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