Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per effect smoothing #456

Merged
merged 10 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add dynamic smoothing first step
  • Loading branch information
redpanther committed Aug 1, 2017
commit 7a378479df3f20c02378f1f4a2126b246b0c41fe
11 changes: 10 additions & 1 deletion libsrc/hyperion/Hyperion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, _deviceSmooth->componentState());
getComponentRegister().componentStateChanged(hyperion::COMP_LEDDEVICE, _device->componentState());

_deviceSmooth->addConfig(1000);

// setup the timer
_timer.setSingleShot(true);
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
Expand Down Expand Up @@ -891,7 +893,14 @@ void Hyperion::update()
// Write the data to the device
if (_device->enabled())
{
_deviceSmooth->setPause(priorityInfo.componentId == hyperion::COMP_EFFECT);
if ( priorityInfo.componentId == hyperion::COMP_EFFECT )
{
_deviceSmooth->selectConfig(1);
}
else
{
_deviceSmooth->selectConfig(0);
}
// feed smoothing in pause mode to maintain a smooth transistion back to smoth mode
if (_deviceSmooth->enabled() || _deviceSmooth->pause())
_deviceSmooth->setLedValues(_ledBuffer);
Expand Down
37 changes: 37 additions & 0 deletions libsrc/hyperion/LinearColorSmoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using namespace hyperion;

// ledUpdateFrequency_hz = 0 > cause divide by zero!
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput)
: LedDevice()
, _ledDevice(ledDevice)
Expand All @@ -23,6 +24,8 @@ LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpd
_timer.setSingleShot(false);
_timer.setInterval(_updateInterval);

addConfig(_settlingTime, ledUpdateFrequency_hz, updateDelay, continuousOutput);

connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
Info( _log, "Created linear-smoothing with interval: %d ms, settlingTime: %d ms, updateDelay: %d frames",
_updateInterval, settlingTime_ms, _outputDelay );
Expand Down Expand Up @@ -160,3 +163,37 @@ void LinearColorSmoothing::setPause(bool pause)
_pause = pause;
}

unsigned LinearColorSmoothing::addConfig(int settlingTime_ms, double ledUpdateFrequency_hz, unsigned updateDelay, bool continuousOutput)
{
SMOOTHING_CFG cfg = {false, settlingTime_ms, int64_t(1000.0/ledUpdateFrequency_hz), updateDelay, continuousOutput};
_cfgList.append(cfg);
return _cfgList.count() - 1;
}

unsigned LinearColorSmoothing::addConfig(bool pause)
{
SMOOTHING_CFG cfg = {true, 100, 50, 0, false};
_cfgList.append(cfg);
return _cfgList.count() - 1;
}

bool LinearColorSmoothing::selectConfig(unsigned cfg)
{
if ( cfg < (unsigned)_cfgList.count())
{
_settlingTime = _cfgList[cfg].settlingTime;
_outputDelay = _cfgList[cfg].outputDelay;
_continuousOutput = _cfgList[cfg].continuousOutput;

if (_cfgList[cfg].updateInterval != _updateInterval)
{
_timer.stop();
_updateInterval = _cfgList[cfg].updateInterval;
_timer.start();
}
return true;
}

return false;
}

25 changes: 21 additions & 4 deletions libsrc/hyperion/LinearColorSmoothing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Qt includes
#include <QTimer>
#include <QVector>

// hyperion incluse
#include <leddevice/LedDevice.h>
Expand Down Expand Up @@ -33,7 +34,7 @@ class LinearColorSmoothing : public LedDevice
/// write updated values as input for the smoothing filter
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @return Zero on success else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues);

Expand All @@ -45,6 +46,10 @@ class LinearColorSmoothing : public LedDevice
bool pause() { return _pause; } ;
bool enabled() { return LedDevice::enabled() && !_pause; };

unsigned addConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0, bool continuousOutput=true);
unsigned addConfig(bool pause);
bool selectConfig(unsigned cfg);

private slots:
/// Timer callback which writes updated led values to the led device
void updateLeds();
Expand All @@ -61,10 +66,10 @@ private slots:
LedDevice * _ledDevice;

/// The interval at which to update the leds (msec)
const int64_t _updateInterval;
int64_t _updateInterval;

/// The time after which the updated led values have been fully applied (msec)
const int64_t _settlingTime;
int64_t _settlingTime;

/// The Qt timer object
QTimer _timer;
Expand All @@ -82,7 +87,7 @@ private slots:
std::vector<ColorRgb> _previousValues;

/// The number of updates to keep in the output queue (delayed) before being output
const unsigned _outputDelay;
unsigned _outputDelay;
/// The output queue
std::list<std::vector<ColorRgb> > _outputQueue;

Expand All @@ -94,4 +99,16 @@ private slots:

/// Flag for pausing
bool _pause;

struct SMOOTHING_CFG
{
bool pause;
int64_t settlingTime;
int64_t updateInterval;
unsigned outputDelay;
bool continuousOutput;
};

/// config list
QVector<SMOOTHING_CFG> _cfgList;
};