Details coming soon.

This commit is contained in:
Paulchen-Panther
2018-12-27 23:11:32 +01:00
parent e3be03ea73
commit d762aa2f3e
186 changed files with 6156 additions and 5444 deletions

View File

@@ -1,5 +1,6 @@
// Qt includes
#include <QDateTime>
#include <QTimer>
#include "LinearColorSmoothing.h"
#include <hyperion/Hyperion.h>
@@ -8,38 +9,60 @@
using namespace hyperion;
// ledUpdateFrequency_hz = 0 > cause divide by zero!
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput)
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, const QJsonDocument& config, Hyperion* hyperion)
: LedDevice()
, _ledDevice(ledDevice)
, _updateInterval(1000 / ledUpdateFrequency_hz)
, _settlingTime(settlingTime_ms)
, _timer()
, _outputDelay(updateDelay)
, _log(Logger::getInstance("SMOOTHING"))
, _hyperion(hyperion)
, _updateInterval(1000)
, _settlingTime(200)
, _timer(new QTimer(this))
, _outputDelay(0)
, _writeToLedsEnable(true)
, _continuousOutput(continuousOutput)
, _continuousOutput(false)
, _pause(false)
, _currentConfigId(0)
{
_log = Logger::getInstance("Smoothing");
_timer.setSingleShot(false);
_timer.setInterval(_updateInterval);
Debug(_log, "Instance created");
// set initial state to true, as LedDevice::enabled() is true by default
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, true);
// init cfg 0 (default)
_cfgList.append({false, 200, 25, 0});
handleSettingsUpdate(settings::SMOOTHING, config);
selectConfig( addConfig(_settlingTime, ledUpdateFrequency_hz, updateDelay) );
// add pause on cfg 1
SMOOTHING_CFG cfg = {true, 100, 50, 0};
SMOOTHING_CFG cfg = {true};
_cfgList.append(cfg);
Info( _log, "smoothing cfg %d: pause", _cfgList.count()-1);
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
// listen for comp changes
connect(_hyperion, &Hyperion::componentStateChanged, this, &LinearColorSmoothing::componentStateChange);
// timer
connect(_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
}
LinearColorSmoothing::~LinearColorSmoothing()
{
// Make sure to switch off the underlying led-device (because switchOff is no longer forwarded)
_ledDevice->switchOff();
delete _ledDevice;
}
void LinearColorSmoothing::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
{
if(type == settings::SMOOTHING)
{
QJsonObject obj = config.object();
_continuousOutput = obj["continuousOutput"].toBool(true);
SMOOTHING_CFG cfg = {false, obj["time_ms"].toInt(200), unsigned(1000.0/obj["updateFrequency"].toDouble(25.0)), unsigned(obj["updateDelay"].toInt(0))};
_cfgList[0] = cfg;
// if current id is 0, we need to apply the settings (forced)
if(!_currentConfigId)
selectConfig(0, true);
if(enabled() != obj["enable"].toBool(true))
setEnable(obj["enable"].toBool(true));
}
}
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
@@ -53,7 +76,7 @@ int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
_previousTime = QDateTime::currentMSecsSinceEpoch();
_previousValues = ledValues;
_timer.start();
_timer->start();
}
else
{
@@ -150,6 +173,11 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
}
}
void LinearColorSmoothing::componentStateChange(const hyperion::Components component, const bool state)
{
if(component == hyperion::COMP_SMOOTHING)
setEnable(state);
}
void LinearColorSmoothing::setEnable(bool enable)
{
@@ -157,9 +185,11 @@ void LinearColorSmoothing::setEnable(bool enable)
if (!enable)
{
_timer.stop();
_timer->stop();
_previousValues.clear();
}
// update comp register
_hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, enable);
}
void LinearColorSmoothing::setPause(bool pause)
@@ -171,14 +201,14 @@ unsigned LinearColorSmoothing::addConfig(int settlingTime_ms, double ledUpdateFr
{
SMOOTHING_CFG cfg = {false, settlingTime_ms, int64_t(1000.0/ledUpdateFrequency_hz), updateDelay};
_cfgList.append(cfg);
Info( _log, "smoothing cfg %d: interval: %d ms, settlingTime: %d ms, updateDelay: %d frames", _cfgList.count()-1, cfg.updateInterval, cfg.settlingTime, cfg.outputDelay );
//Debug( _log, "smoothing cfg %d: interval: %d ms, settlingTime: %d ms, updateDelay: %d frames", _cfgList.count()-1, cfg.updateInterval, cfg.settlingTime, cfg.outputDelay );
return _cfgList.count() - 1;
}
bool LinearColorSmoothing::selectConfig(unsigned cfg)
bool LinearColorSmoothing::selectConfig(unsigned cfg, const bool& force)
{
if (_currentConfigId == cfg)
if (_currentConfigId == cfg && !force)
{
return true;
}
@@ -191,20 +221,34 @@ bool LinearColorSmoothing::selectConfig(unsigned cfg)
if (_cfgList[cfg].updateInterval != _updateInterval)
{
_timer.stop();
_timer->stop();
_updateInterval = _cfgList[cfg].updateInterval;
_timer.setInterval(_updateInterval);
_timer.start();
_timer->setInterval(_updateInterval);
_timer->start();
}
_currentConfigId = cfg;
InfoIf( enabled() && !_pause, _log, "set smoothing cfg: %d, interval: %d ms, settlingTime: %d ms, updateDelay: %d frames", _currentConfigId, _updateInterval, _settlingTime, _outputDelay );
//DebugIf( enabled() && !_pause, _log, "set smoothing cfg: %d, interval: %d ms, settlingTime: %d ms, updateDelay: %d frames", _currentConfigId, _updateInterval, _settlingTime, _outputDelay );
InfoIf( _pause, _log, "set smoothing cfg: %d, pause", _currentConfigId );
return true;
}
// reset to default
_currentConfigId = 0;
return false;
}
void LinearColorSmoothing::startTimerDelayed()
{
QTimer::singleShot(500, this, SLOT(delayStartTimer()));
}
void LinearColorSmoothing::stopTimer()
{
_timer->stop();
}
void LinearColorSmoothing::delayStartTimer()
{
_timer->start();
}