Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 1e45f0e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents e572c1f + 971008c commit 1e45f0e

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

config/hyperion.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"type" : "none",
8282
"time_ms" : 200,
8383
"updateFrequency" : 20.0000,
84-
"framesDelay" : 0
84+
"updateDelay" : 0
8585
}
8686
},
8787

deploy/hyperion.tar.gz

2.04 KB
Binary file not shown.

libsrc/hyperion/Hyperion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,13 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
243243
}
244244
else
245245
{
246-
// const unsigned framesDelay = smoothingConfig.get("framesDelay", Json::Value(0u)).asUInt();
246+
const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt();
247247
std::cout << "Creating linear smoothing" << std::endl;
248-
return new LinearColorSmoothing(ledDevice, smoothingConfig["updateFrequency"].asDouble(), smoothingConfig["time_ms"].asInt());
248+
return new LinearColorSmoothing(
249+
ledDevice,
250+
smoothingConfig["updateFrequency"].asDouble(),
251+
smoothingConfig["time_ms"].asInt(),
252+
updateDelay);
249253
}
250254
}
251255
else

libsrc/hyperion/LinearColorSmoothing.cpp

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33

44
#include "LinearColorSmoothing.h"
55

6-
LinearColorSmoothing::LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms) :
6+
LinearColorSmoothing::LinearColorSmoothing(
7+
LedDevice * ledDevice,
8+
double ledUpdateFrequency_hz,
9+
int settlingTime_ms,
10+
unsigned updateDelay) :
711
QObject(),
812
LedDevice(),
913
_ledDevice(ledDevice),
1014
_updateInterval(1000 / ledUpdateFrequency_hz),
1115
_settlingTime(settlingTime_ms),
12-
_timer()
16+
_timer(),
17+
_outputDelay(updateDelay)
1318
{
1419
_timer.setSingleShot(false);
1520
_timer.setInterval(_updateInterval);
1621

1722
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
23+
24+
std::cout << "Created linear-smoothing(interval_ms=" << _updateInterval << ";settlingTime_ms=" << settlingTime_ms << ";updateDelay=" << _outputDelay << std::endl;
1825
}
1926

2027
LinearColorSmoothing::~LinearColorSmoothing()
@@ -25,7 +32,7 @@ LinearColorSmoothing::~LinearColorSmoothing()
2532
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
2633
{
2734
// received a new target color
28-
if (_previousValues.size() == 0)
35+
if (_previousValues.empty())
2936
{
3037
// not initialized yet
3138
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
@@ -46,17 +53,20 @@ int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
4653

4754
int LinearColorSmoothing::switchOff()
4855
{
49-
// stop smoothing filter
50-
_timer.stop();
56+
// We will keep updating the leds (but with pure-black)
5157

52-
// return to uninitialized state
53-
_previousValues.clear();
54-
_previousTime = 0;
55-
_targetValues.clear();
58+
// Clear the smoothing parameters
59+
std::fill(_targetValues.begin(), _targetValues.end(), ColorRgb::BLACK);
5660
_targetTime = 0;
5761

58-
// finally switch off all leds
59-
return _ledDevice->switchOff();
62+
// Erase the output-queue
63+
for (unsigned i=0; i<_outputQueue.size(); ++i)
64+
{
65+
_outputQueue.push_back(_targetValues);
66+
_outputQueue.pop_front();
67+
}
68+
69+
return 0;
6070
}
6171

6272
void LinearColorSmoothing::updateLeds()
@@ -69,7 +79,7 @@ void LinearColorSmoothing::updateLeds()
6979
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
7080
_previousTime = now;
7181

72-
_ledDevice->write(_previousValues);
82+
queueColors(_previousValues);
7383
}
7484
else
7585
{
@@ -86,6 +96,26 @@ void LinearColorSmoothing::updateLeds()
8696
}
8797
_previousTime = now;
8898

89-
_ledDevice->write(_previousValues);
99+
queueColors(_previousValues);
100+
}
101+
}
102+
103+
void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
104+
{
105+
if (_outputDelay == 0)
106+
{
107+
// No output delay => immediate write
108+
_ledDevice->write(ledColors);
109+
}
110+
else
111+
{
112+
// Push the new colors in the delay-buffer
113+
_outputQueue.push_back(ledColors);
114+
// If the delay-buffer is filled pop the front and write to device
115+
if (_outputQueue.size() > _outputDelay)
116+
{
117+
_ledDevice->write(_outputQueue.front());
118+
_outputQueue.pop_front();
119+
}
90120
}
91121
}

libsrc/hyperion/LinearColorSmoothing.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class LinearColorSmoothing : public QObject, public LedDevice
2323
/// @param LedDevice the led device
2424
/// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz)
2525
/// @param settingTime The time after which the updated led values have been fully applied (sec)
26-
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime);
26+
/// @param updateDelay The number of frames to delay outgoing led updates
27+
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay);
2728

2829
/// Destructor
2930
virtual ~LinearColorSmoothing();
@@ -43,6 +44,13 @@ private slots:
4344
void updateLeds();
4445

4546
private:
47+
/**
48+
* Pushes the colors into the output queue and popping the head to the led-device
49+
*
50+
* @param ledColors The colors to queue
51+
*/
52+
void queueColors(const std::vector<ColorRgb> & ledColors);
53+
4654
/// The led device
4755
LedDevice * _ledDevice;
4856

@@ -66,4 +74,10 @@ private slots:
6674

6775
/// The previously written led data
6876
std::vector<ColorRgb> _previousValues;
77+
78+
/** The number of updates to keep in the output queue (delayed) before being output */
79+
const unsigned _outputDelay;
80+
/** The output queue */
81+
std::list<std::vector<ColorRgb> > _outputQueue;
82+
6983
};

0 commit comments

Comments
 (0)