Merge remote-tracking branch 'origin/master'

Former-commit-id: 1e45f0e613875e9c6e61ab4f5838874e8abd30f0
This commit is contained in:
T.van der Zwan 2014-09-26 18:25:24 +00:00
commit 2b3f605b91
5 changed files with 66 additions and 18 deletions

View File

@ -81,7 +81,7 @@
"type" : "none",
"time_ms" : 200,
"updateFrequency" : 20.0000,
"framesDelay" : 0
"updateDelay" : 0
}
},

View File

@ -1 +1 @@
7dbfa7fe80db4f8e65357ff45ff92a1321dfde49
f8d592fd55a3ca744f582c960dcde3aaa0afe5c0

View File

@ -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

View File

@ -3,18 +3,25 @@
#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);
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()
@ -25,7 +32,7 @@ LinearColorSmoothing::~LinearColorSmoothing()
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
{
// received a new target color
if (_previousValues.size() == 0)
if (_previousValues.empty())
{
// not initialized yet
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
@ -46,17 +53,20 @@ int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
int LinearColorSmoothing::switchOff()
{
// stop smoothing filter
_timer.stop();
// We will keep updating the leds (but with pure-black)
// 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 +79,7 @@ void LinearColorSmoothing::updateLeds()
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
_previousTime = now;
_ledDevice->write(_previousValues);
queueColors(_previousValues);
}
else
{
@ -86,6 +96,26 @@ void LinearColorSmoothing::updateLeds()
}
_previousTime = now;
_ledDevice->write(_previousValues);
queueColors(_previousValues);
}
}
void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & 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());
_outputQueue.pop_front();
}
}
}

View File

@ -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<ColorRgb> & ledColors);
/// The led device
LedDevice * _ledDevice;
@ -66,4 +74,10 @@ private:
/// The previously written led data
std::vector<ColorRgb> _previousValues;
/** The number of updates to keep in the output queue (delayed) before being output */
const unsigned _outputDelay;
/** The output queue */
std::list<std::vector<ColorRgb> > _outputQueue;
};