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

Commit fa5a7f1

Browse files
committed
Added delay to smoothing and changed the switch off to continue sending black
1 parent 248e4c3 commit fa5a7f1

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
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

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: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
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);
@@ -25,7 +30,7 @@ LinearColorSmoothing::~LinearColorSmoothing()
2530
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
2631
{
2732
// received a new target color
28-
if (_previousValues.size() == 0)
33+
if (_previousValues.empty())
2934
{
3035
// not initialized yet
3136
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
@@ -46,17 +51,19 @@ int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
4651

4752
int LinearColorSmoothing::switchOff()
4853
{
49-
// stop smoothing filter
50-
_timer.stop();
51-
52-
// return to uninitialized state
53-
_previousValues.clear();
54-
_previousTime = 0;
55-
_targetValues.clear();
54+
// Clear the smoothing parameters
55+
std::fill(_targetValues.begin(), _targetValues.end(), ColorRgb::BLACK);
5656
_targetTime = 0;
5757

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

6269
void LinearColorSmoothing::updateLeds()
@@ -69,7 +76,7 @@ void LinearColorSmoothing::updateLeds()
6976
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
7077
_previousTime = now;
7178

72-
_ledDevice->write(_previousValues);
79+
queueColors(_previousValues);
7380
}
7481
else
7582
{
@@ -86,6 +93,23 @@ void LinearColorSmoothing::updateLeds()
8693
}
8794
_previousTime = now;
8895

89-
_ledDevice->write(_previousValues);
96+
queueColors(_previousValues);
97+
}
98+
}
99+
100+
void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
101+
{
102+
if (_outputDelay == 0)
103+
{
104+
_ledDevice->write(ledColors);
105+
}
106+
else
107+
{
108+
_outputQueue.push_back(ledColors);
109+
if (_outputQueue.size() > _outputDelay)
110+
{
111+
_ledDevice->write(_outputQueue.front());
112+
_outputQueue.pop_front();
113+
}
90114
}
91115
}

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)