From 30cc14d9e8983707f9ca7cc229dfdf897821f992 Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Mon, 22 Sep 2014 21:28:38 +0200 Subject: [PATCH 1/4] Added delay to smoothing and changed the switch off to continue sending black Former-commit-id: fa5a7f14b0fdf3a0a74169cfefbf5b625330b753 --- config/hyperion.config.json | 2 +- libsrc/hyperion/Hyperion.cpp | 8 +++- libsrc/hyperion/LinearColorSmoothing.cpp | 52 +++++++++++++++++------- libsrc/hyperion/LinearColorSmoothing.h | 16 +++++++- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/config/hyperion.config.json b/config/hyperion.config.json index 61fb7865..8e361ed0 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -81,7 +81,7 @@ "type" : "none", "time_ms" : 200, "updateFrequency" : 20.0000, - "framesDelay" : 0 + "updateDelay" : 0 } }, diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 9b5eb9b9..5e76d8e8 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -243,9 +243,13 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, } else { -// const unsigned framesDelay = smoothingConfig.get("framesDelay", Json::Value(0u)).asUInt(); + const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt(); std::cout << "Creating linear smoothing" << std::endl; - return new LinearColorSmoothing(ledDevice, smoothingConfig["updateFrequency"].asDouble(), smoothingConfig["time_ms"].asInt()); + return new LinearColorSmoothing( + ledDevice, + smoothingConfig["updateFrequency"].asDouble(), + smoothingConfig["time_ms"].asInt(), + updateDelay); } } else diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index 0fe3e208..47974c90 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -3,13 +3,18 @@ #include "LinearColorSmoothing.h" -LinearColorSmoothing::LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms) : +LinearColorSmoothing::LinearColorSmoothing( + LedDevice *ledDevice, + double ledUpdateFrequency_hz, + int settlingTime_ms, + unsigned updateDelay) : QObject(), LedDevice(), _ledDevice(ledDevice), _updateInterval(1000 / ledUpdateFrequency_hz), _settlingTime(settlingTime_ms), - _timer() + _timer(), + _outputDelay(updateDelay) { _timer.setSingleShot(false); _timer.setInterval(_updateInterval); @@ -25,7 +30,7 @@ LinearColorSmoothing::~LinearColorSmoothing() int LinearColorSmoothing::write(const std::vector &ledValues) { // received a new target color - if (_previousValues.size() == 0) + if (_previousValues.empty()) { // not initialized yet _targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime; @@ -46,17 +51,19 @@ int LinearColorSmoothing::write(const std::vector &ledValues) int LinearColorSmoothing::switchOff() { - // stop smoothing filter - _timer.stop(); - - // return to uninitialized state - _previousValues.clear(); - _previousTime = 0; - _targetValues.clear(); + // Clear the smoothing parameters + std::fill(_targetValues.begin(), _targetValues.end(), ColorRgb::BLACK); _targetTime = 0; - // finally switch off all leds - return _ledDevice->switchOff(); + // Erase the output-queue + for (unsigned i=0; i<_outputQueue.size(); ++i) + { + _outputQueue.push_back(_targetValues); + _outputQueue.pop_front(); + } + + + return 0; } void LinearColorSmoothing::updateLeds() @@ -69,7 +76,7 @@ void LinearColorSmoothing::updateLeds() memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb)); _previousTime = now; - _ledDevice->write(_previousValues); + queueColors(_previousValues); } else { @@ -86,6 +93,23 @@ void LinearColorSmoothing::updateLeds() } _previousTime = now; - _ledDevice->write(_previousValues); + queueColors(_previousValues); + } +} + +void LinearColorSmoothing::queueColors(const std::vector & ledColors) +{ + if (_outputDelay == 0) + { + _ledDevice->write(ledColors); + } + else + { + _outputQueue.push_back(ledColors); + if (_outputQueue.size() > _outputDelay) + { + _ledDevice->write(_outputQueue.front()); + _outputQueue.pop_front(); + } } } diff --git a/libsrc/hyperion/LinearColorSmoothing.h b/libsrc/hyperion/LinearColorSmoothing.h index 5c27862d..2b75059e 100644 --- a/libsrc/hyperion/LinearColorSmoothing.h +++ b/libsrc/hyperion/LinearColorSmoothing.h @@ -23,7 +23,8 @@ public: /// @param LedDevice the led device /// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz) /// @param settingTime The time after which the updated led values have been fully applied (sec) - LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime); + /// @param updateDelay The number of frames to delay outgoing led updates + LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay); /// Destructor virtual ~LinearColorSmoothing(); @@ -43,6 +44,13 @@ private slots: void updateLeds(); private: + /** + * Pushes the colors into the output queue and popping the head to the led-device + * + * @param ledColors The colors to queue + */ + void queueColors(const std::vector & ledColors); + /// The led device LedDevice * _ledDevice; @@ -66,4 +74,10 @@ private: /// The previously written led data std::vector _previousValues; + + /** The number of updates to keep in the output queue (delayed) before being output */ + const unsigned _outputDelay; + /** The output queue */ + std::list > _outputQueue; + }; From fbe8e0ad4e29ea4e278ac2831b259cc3f368e8aa Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Thu, 25 Sep 2014 22:05:01 +0200 Subject: [PATCH 2/4] Added some code comments Former-commit-id: 58c1ec1fd2dcc210b6d162d1e8b6c40a502f30fa --- libsrc/hyperion/LinearColorSmoothing.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index 47974c90..888b1c2f 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -4,7 +4,7 @@ #include "LinearColorSmoothing.h" LinearColorSmoothing::LinearColorSmoothing( - LedDevice *ledDevice, + LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay) : @@ -51,6 +51,8 @@ int LinearColorSmoothing::write(const std::vector &ledValues) int LinearColorSmoothing::switchOff() { + // We will keep updating the leds (but with pure-black) + // Clear the smoothing parameters std::fill(_targetValues.begin(), _targetValues.end(), ColorRgb::BLACK); _targetTime = 0; @@ -62,7 +64,6 @@ int LinearColorSmoothing::switchOff() _outputQueue.pop_front(); } - return 0; } @@ -101,11 +102,14 @@ void LinearColorSmoothing::queueColors(const std::vector & ledColors) { if (_outputDelay == 0) { + // No output delay => immediate write _ledDevice->write(ledColors); } else { + // Push the new colors in the delay-buffer _outputQueue.push_back(ledColors); + // If the delay-buffer is filled pop the front and write to device if (_outputQueue.size() > _outputDelay) { _ledDevice->write(_outputQueue.front()); From 11d29d02c565151821fa045cc67522b06cc94c75 Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Thu, 25 Sep 2014 22:31:20 +0200 Subject: [PATCH 3/4] Added debug statement to standard out Former-commit-id: daaeb2a07931942bbeaf272775da81902169ad04 --- libsrc/hyperion/LinearColorSmoothing.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index 888b1c2f..da932e9e 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -20,6 +20,8 @@ LinearColorSmoothing::LinearColorSmoothing( _timer.setInterval(_updateInterval); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds())); + + std::cout << "Created linear-smoothing(interval_ms=" << _updateInterval << ";settlingTime_ms=" << settlingTime_ms << ";updateDelay=" << _outputDelay << std::endl; } LinearColorSmoothing::~LinearColorSmoothing() From 7c1811091aba5b16b65d94d51d183570835ba4b1 Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Thu, 25 Sep 2014 22:33:03 +0200 Subject: [PATCH 4/4] Updated RPi release Former-commit-id: 971008c4e31aaf67e7cfe28d163e3305f426a8e6 --- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index f71fa321..687dfb80 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -7dbfa7fe80db4f8e65357ff45ff92a1321dfde49 \ No newline at end of file +f8d592fd55a3ca744f582c960dcde3aaa0afe5c0 \ No newline at end of file