2013-10-27 18:04:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <vector>
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
// Qt includes
|
2017-08-04 12:01:45 +02:00
|
|
|
#include <QVector>
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
// hyperion incluse
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
#include <utils/Components.h>
|
2013-10-27 18:04:37 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// settings
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
|
|
|
class QTimer;
|
|
|
|
class Logger;
|
|
|
|
class Hyperion;
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
/// Linear Smooting class
|
|
|
|
///
|
|
|
|
/// This class processes the requested led values and forwards them to the device after applying
|
|
|
|
/// a linear smoothing effect. This class can be handled as a generic LedDevice.
|
2016-08-14 10:46:44 +02:00
|
|
|
class LinearColorSmoothing : public LedDevice
|
2013-10-27 18:04:37 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param LedDevice the led device
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @param config The configuration document smoothing
|
|
|
|
/// @param hyperion The hyperion parent instance
|
|
|
|
///
|
|
|
|
LinearColorSmoothing(LedDevice *ledDevice, const QJsonDocument& config, Hyperion* hyperion);
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
virtual ~LinearColorSmoothing();
|
|
|
|
|
|
|
|
/// write updated values as input for the smoothing filter
|
|
|
|
///
|
|
|
|
/// @param ledValues The color-value per led
|
2017-08-04 12:01:45 +02:00
|
|
|
/// @return Zero on success else negative
|
2013-10-27 18:04:37 +01:00
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
virtual int write(const std::vector<ColorRgb> &ledValues);
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// Switch the leds off
|
|
|
|
virtual int switchOff();
|
|
|
|
|
2016-09-08 16:32:42 +02:00
|
|
|
void setEnable(bool enable);
|
2017-03-30 06:20:20 +02:00
|
|
|
void setPause(bool pause);
|
|
|
|
bool pause() { return _pause; } ;
|
|
|
|
bool enabled() { return LedDevice::enabled() && !_pause; };
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Add a new smoothing cfg which can be used with selectConfig()
|
|
|
|
/// @param settlingTime_ms The buffer time
|
|
|
|
/// @param ledUpdateFrequency_hz The frequency of update
|
|
|
|
/// @param updateDelay The delay
|
|
|
|
///
|
|
|
|
/// @return The index of the cfg which can be passed to selectConfig()
|
|
|
|
///
|
2017-08-04 12:01:45 +02:00
|
|
|
unsigned addConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0);
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief select a smoothing cfg given by cfg index from addConfig()
|
|
|
|
/// @param cfg The index to use
|
|
|
|
/// @param force Overwrite in any case the current values (used for cfg 0 settings udpate)
|
|
|
|
///
|
|
|
|
/// @return On success return else false (and falls back to cfg 0)
|
|
|
|
///
|
|
|
|
bool selectConfig(unsigned cfg, const bool& force = false);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @ Helper methods to start the timer with delay (see delayStartSmooth())
|
|
|
|
///
|
|
|
|
void startTimerDelayed();
|
|
|
|
void stopTimer();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor
|
|
|
|
/// @param type settingyType from enum
|
|
|
|
/// @param config configuration object
|
|
|
|
///
|
|
|
|
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
|
2017-08-04 12:01:45 +02:00
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
private slots:
|
|
|
|
/// Timer callback which writes updated led values to the led device
|
|
|
|
void updateLeds();
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Delay timer slot to workaround the leddevice reconstruction segfault (dangling pointer)
|
|
|
|
void delayStartTimer();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Handle component state changes
|
|
|
|
/// @param component The component
|
|
|
|
/// @param state The requested state
|
|
|
|
///
|
|
|
|
void componentStateChange(const hyperion::Components component, const bool state);
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
private:
|
2014-09-22 21:28:38 +02:00
|
|
|
/**
|
|
|
|
* Pushes the colors into the output queue and popping the head to the led-device
|
|
|
|
*
|
|
|
|
* @param ledColors The colors to queue
|
|
|
|
*/
|
|
|
|
void queueColors(const std::vector<ColorRgb> & ledColors);
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
/// The led device
|
|
|
|
LedDevice * _ledDevice;
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Logger instance
|
|
|
|
Logger* _log;
|
|
|
|
|
|
|
|
/// Hyperion instance
|
|
|
|
Hyperion* _hyperion;
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
/// The interval at which to update the leds (msec)
|
2017-08-04 12:01:45 +02:00
|
|
|
int64_t _updateInterval;
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// The time after which the updated led values have been fully applied (msec)
|
2017-08-04 12:01:45 +02:00
|
|
|
int64_t _settlingTime;
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// The Qt timer object
|
2018-12-27 23:11:32 +01:00
|
|
|
QTimer * _timer;
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// The timestamp at which the target data should be fully applied
|
|
|
|
int64_t _targetTime;
|
|
|
|
|
|
|
|
/// The target led data
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> _targetValues;
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
/// The timestamp of the previously written led data
|
|
|
|
int64_t _previousTime;
|
|
|
|
|
|
|
|
/// The previously written led data
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> _previousValues;
|
2014-09-22 21:28:38 +02:00
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
/// The number of updates to keep in the output queue (delayed) before being output
|
2017-08-04 12:01:45 +02:00
|
|
|
unsigned _outputDelay;
|
2016-07-13 11:18:12 +02:00
|
|
|
/// The output queue
|
2014-09-22 21:28:38 +02:00
|
|
|
std::list<std::vector<ColorRgb> > _outputQueue;
|
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
/// Prevent sending data to device when no intput data is sent
|
2016-05-26 07:01:10 +02:00
|
|
|
bool _writeToLedsEnable;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
/// Flag for dis/enable continuous output to led device regardless there is new data or not
|
|
|
|
bool _continuousOutput;
|
2017-03-30 06:20:20 +02:00
|
|
|
|
|
|
|
/// Flag for pausing
|
|
|
|
bool _pause;
|
2017-08-04 12:01:45 +02:00
|
|
|
|
|
|
|
struct SMOOTHING_CFG
|
|
|
|
{
|
|
|
|
bool pause;
|
|
|
|
int64_t settlingTime;
|
|
|
|
int64_t updateInterval;
|
|
|
|
unsigned outputDelay;
|
|
|
|
};
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// smooth config list
|
2017-08-04 12:01:45 +02:00
|
|
|
QVector<SMOOTHING_CFG> _cfgList;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2017-08-04 12:01:45 +02:00
|
|
|
unsigned _currentConfigId;
|
2013-10-27 18:04:37 +01:00
|
|
|
};
|