smoothing: integrate option for continuousOutput + updateDelay fix from hyperion.ng (#713)
logger: fix possible buffer overflow
This commit is contained in:
parent
d2231c0cd4
commit
d3713a8ea9
|
@ -130,7 +130,8 @@
|
|||
"type" : "linear",
|
||||
"time_ms" : 200,
|
||||
"updateFrequency" : 20.0000,
|
||||
"updateDelay" : 0
|
||||
"updateDelay" : 0,
|
||||
"continuousOutput": true
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -566,13 +566,14 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
|
|||
}
|
||||
else
|
||||
{
|
||||
const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt();
|
||||
std::cout << "INFO: Creating linear smoothing" << std::endl;
|
||||
return new LinearColorSmoothing(
|
||||
ledDevice,
|
||||
smoothingConfig["updateFrequency"].asDouble(),
|
||||
smoothingConfig["time_ms"].asInt(),
|
||||
updateDelay);
|
||||
smoothingConfig.get("updateFrequency", 25.0).asDouble(),
|
||||
smoothingConfig.get("time_ms", 200).asInt(),
|
||||
smoothingConfig.get("updateDelay", 0).asUInt(),
|
||||
smoothingConfig.get("continuousOutput", true).asBool()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3,19 +3,16 @@
|
|||
|
||||
#include "LinearColorSmoothing.h"
|
||||
|
||||
LinearColorSmoothing::LinearColorSmoothing(
|
||||
LedDevice * ledDevice,
|
||||
double ledUpdateFrequency_hz,
|
||||
int settlingTime_ms,
|
||||
unsigned updateDelay) :
|
||||
QObject(),
|
||||
LedDevice(),
|
||||
_ledDevice(ledDevice),
|
||||
_updateInterval(1000 / ledUpdateFrequency_hz),
|
||||
_settlingTime(settlingTime_ms),
|
||||
_timer(),
|
||||
_outputDelay(updateDelay),
|
||||
_writeToLedsEnable(true)
|
||||
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput)
|
||||
: QObject()
|
||||
, LedDevice()
|
||||
, _ledDevice(ledDevice)
|
||||
, _updateInterval(1000 / ledUpdateFrequency_hz)
|
||||
, _settlingTime(settlingTime_ms)
|
||||
, _timer()
|
||||
, _outputDelay(updateDelay)
|
||||
, _writeToLedsEnable(true)
|
||||
, _continuousOutput(continuousOutput)
|
||||
{
|
||||
_timer.setSingleShot(false);
|
||||
_timer.setInterval(_updateInterval);
|
||||
|
@ -83,7 +80,7 @@ void LinearColorSmoothing::updateLeds()
|
|||
_previousTime = now;
|
||||
|
||||
queueColors(_previousValues);
|
||||
_writeToLedsEnable = false;
|
||||
_writeToLedsEnable = _continuousOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -115,14 +112,18 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
|
|||
}
|
||||
else
|
||||
{
|
||||
// Push the new colors in the delay-buffer
|
||||
_outputQueue.push_back(ledColors);
|
||||
// Push new colors in the delay-buffer
|
||||
if ( _writeToLedsEnable )
|
||||
_outputQueue.push_back(ledColors);
|
||||
|
||||
// If the delay-buffer is filled pop the front and write to device
|
||||
if (_outputQueue.size() > _outputDelay)
|
||||
if (_outputQueue.size() > 0 )
|
||||
{
|
||||
if ( _writeToLedsEnable )
|
||||
if ( _outputQueue.size() > _outputDelay || !_writeToLedsEnable )
|
||||
{
|
||||
_ledDevice->write(_outputQueue.front());
|
||||
_outputQueue.pop_front();
|
||||
_outputQueue.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
/// @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)
|
||||
/// @param updateDelay The number of frames to delay outgoing led updates
|
||||
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay);
|
||||
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay, bool continuousOutput);
|
||||
|
||||
/// Destructor
|
||||
virtual ~LinearColorSmoothing();
|
||||
|
@ -82,4 +82,7 @@ private:
|
|||
|
||||
// prevent sending data to device when no intput data is sent
|
||||
bool _writeToLedsEnable;
|
||||
|
||||
/// Flag for dis/enable continuous output to led device regardless there is new data or not
|
||||
bool _continuousOutput;
|
||||
};
|
||||
|
|
|
@ -80,10 +80,11 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u
|
|||
if ( level < _minLevel )
|
||||
return;
|
||||
|
||||
char msg[512];
|
||||
const size_t max_msg_length = 1024;
|
||||
char msg[max_msg_length];
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
vsprintf (msg,fmt, args);
|
||||
vsnprintf (msg, max_msg_length, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
std::string location;
|
||||
|
|
Loading…
Reference in New Issue