mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
multi fix commit (#112)
* multi fix commit - refactoring leddevicefactory - adalight: default for "delayAfterConnect" is 1s now - needed for most arduino's because of there special behaviour on open - fadecandy: new option for disabling configuration send - if you want to keep your fadecandy defaults - Hyperion.cpp: simplify createSmoothing discussed in #105 - smoothing: -- add option for continuous output -- when updatedelay>0 and continousOutput is disabled, buffer is flushed correctly after no input is detected * add doxygen to travis
This commit is contained in:
@@ -481,47 +481,31 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOr
|
||||
}
|
||||
|
||||
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
|
||||
{
|
||||
{
|
||||
Logger * log = Logger::getInstance("Core");
|
||||
std::string type = smoothingConfig.get("type", "none").asString();
|
||||
std::string type = smoothingConfig.get("type", "linear").asString();
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
|
||||
type = "linear"; // TODO currently hardcoded type, delete it if we have more types
|
||||
if ( ! smoothingConfig.get("enable", true).asBool() )
|
||||
{
|
||||
Info(log,"Smoothing disabled in config");
|
||||
Info(log,"Smoothing disabled");
|
||||
return ledDevice;
|
||||
}
|
||||
if (type == "none")
|
||||
{
|
||||
Info(log, "Smoothing set to none");
|
||||
return ledDevice;
|
||||
}
|
||||
else if (type == "linear")
|
||||
{
|
||||
if (!smoothingConfig.isMember("time_ms"))
|
||||
{
|
||||
Error(log, "Unable to create smoothing of type linear because of missing parameter 'time_ms'");
|
||||
}
|
||||
else if (!smoothingConfig.isMember("updateFrequency"))
|
||||
{
|
||||
Error(log, "Unable to create smoothing of type linear because of missing parameter 'updateFrequency'");
|
||||
}
|
||||
else
|
||||
{
|
||||
const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt();
|
||||
Info(log, "Creating linear smoothing");
|
||||
return new LinearColorSmoothing(
|
||||
ledDevice,
|
||||
smoothingConfig["updateFrequency"].asDouble(),
|
||||
smoothingConfig["time_ms"].asInt(),
|
||||
updateDelay);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(log, "Unknown smoothing type %s.", type.c_str());
|
||||
}
|
||||
|
||||
if (type == "linear")
|
||||
{
|
||||
Info(log, "Creating linear smoothing");
|
||||
return new LinearColorSmoothing(
|
||||
ledDevice,
|
||||
smoothingConfig.get("updateFrequency", 25.0).asDouble(),
|
||||
smoothingConfig.get("time_ms", 200).asInt(),
|
||||
smoothingConfig.get("updateDelay", 0).asUInt(),
|
||||
smoothingConfig.get("continuousOutput", false).asBool()
|
||||
);
|
||||
}
|
||||
|
||||
Error(log, "Smoothing disabled, because of unknown type '%s'.", type.c_str());
|
||||
return ledDevice;
|
||||
}
|
||||
|
||||
|
@@ -3,26 +3,24 @@
|
||||
|
||||
#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);
|
||||
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
|
||||
|
||||
Info(Logger::getInstance("Smoothing"), "Created linear-smoothing with interval_ms: %d, settlingTime_ms: %d, updateDelay: %d",
|
||||
Info(Logger::getInstance("Smoothing"),
|
||||
"Created linear-smoothing with interval: %d ms, settlingTime: %d ms, updateDelay: %d frames",
|
||||
_updateInterval, settlingTime_ms, _outputDelay );
|
||||
}
|
||||
|
||||
@@ -84,7 +82,7 @@ void LinearColorSmoothing::updateLeds()
|
||||
_previousTime = now;
|
||||
|
||||
queueColors(_previousValues);
|
||||
_writeToLedsEnable = false;
|
||||
_writeToLedsEnable = _continuousOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -116,14 +114,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();
|
||||
@@ -75,11 +75,14 @@ private:
|
||||
/// The previously written led data
|
||||
std::vector<ColorRgb> _previousValues;
|
||||
|
||||
/** The number of updates to keep in the output queue (delayed) before being output */
|
||||
/// The number of updates to keep in the output queue (delayed) before being output
|
||||
const unsigned _outputDelay;
|
||||
/** The output queue */
|
||||
/// The output queue
|
||||
std::list<std::vector<ColorRgb> > _outputQueue;
|
||||
|
||||
// prevent sending data to device when no intput data is sent
|
||||
/// 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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user