2020-07-12 20:27:56 +02:00
|
|
|
|
#ifndef LEDEVICE_H
|
|
|
|
|
#define LEDEVICE_H
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
|
// qt includes
|
2016-09-23 08:49:22 +02:00
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
2016-10-13 21:59:58 +02:00
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
2019-07-14 22:43:22 +02:00
|
|
|
|
#include <QTimer>
|
2020-06-28 23:05:32 +02:00
|
|
|
|
#include <QDateTime>
|
2016-09-23 08:49:22 +02:00
|
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
|
// STL includes
|
2013-07-26 22:38:34 +02:00
|
|
|
|
#include <vector>
|
2016-08-23 20:07:12 +02:00
|
|
|
|
#include <map>
|
2016-09-23 08:49:22 +02:00
|
|
|
|
#include <algorithm>
|
2016-08-14 10:46:44 +02:00
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
|
// Utility includes
|
2013-11-11 10:00:37 +01:00
|
|
|
|
#include <utils/ColorRgb.h>
|
2016-05-31 22:55:56 +02:00
|
|
|
|
#include <utils/ColorRgbw.h>
|
|
|
|
|
#include <utils/RgbToRgbw.h>
|
2016-06-25 22:08:17 +02:00
|
|
|
|
#include <utils/Logger.h>
|
2016-08-23 20:07:12 +02:00
|
|
|
|
#include <functional>
|
2017-03-21 17:55:46 +01:00
|
|
|
|
#include <utils/Components.h>
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
|
|
class LedDevice;
|
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
|
typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& );
|
2017-03-04 22:17:42 +01:00
|
|
|
|
typedef std::map<QString,LedDeviceCreateFuncType> LedDeviceRegistry;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Interface (pure virtual base class) for LED-devices.
|
2013-09-06 21:26:58 +02:00
|
|
|
|
///
|
2016-08-14 10:46:44 +02:00
|
|
|
|
class LedDevice : public QObject
|
2013-07-26 22:38:34 +02:00
|
|
|
|
{
|
2016-08-14 10:46:44 +02:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
|
public:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Constructs LED-device
|
|
|
|
|
///
|
|
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
|
|
|
|
/// @param parent QT parent
|
|
|
|
|
///
|
|
|
|
|
LedDevice(const QJsonObject& deviceConfig = QJsonObject(), QObject* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Destructor of the LED-device
|
|
|
|
|
///
|
2020-07-12 09:19:59 +02:00
|
|
|
|
~LedDevice() override;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
2019-12-08 13:12:01 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Set the current active LED-device type.
|
2019-12-08 13:12:01 +01:00
|
|
|
|
///
|
|
|
|
|
/// @param deviceType Device's type
|
|
|
|
|
///
|
2020-08-02 10:44:42 +02:00
|
|
|
|
void setActiveDeviceType(const QString& deviceType);
|
2019-12-08 13:12:01 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
///
|
|
|
|
|
/// @brief Set the number of LEDs supported by the device.
|
|
|
|
|
///
|
2020-11-01 21:56:19 +01:00
|
|
|
|
/// @param[in] ledCount Number of device LEDs, 0 = unknown number
|
2020-07-12 20:27:56 +02:00
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
|
void setLedCount(int ledCount);
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Set a device's latch time.
|
|
|
|
|
///
|
|
|
|
|
/// Latch time is the time-frame a device requires until the next update can be processed.
|
|
|
|
|
/// During that time-frame any updates done via updateLeds are skipped.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] latchTime_ms Latch time in milliseconds
|
|
|
|
|
///
|
|
|
|
|
void setLatchTime(int latchTime_ms);
|
2020-03-26 18:49:44 +01:00
|
|
|
|
|
2020-09-14 17:19:14 +02:00
|
|
|
|
///
|
|
|
|
|
/// @brief Set a device's rewrite time.
|
|
|
|
|
///
|
|
|
|
|
/// Rewrite time is the time frame a devices requires to be refreshed, if no updated happened in the meantime.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] rewriteTime_ms Rewrite time in milliseconds
|
|
|
|
|
///
|
|
|
|
|
void setRewriteTime(int rewriteTime_ms);
|
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Discover devices of this type available (for configuration).
|
|
|
|
|
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
|
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @return A JSON structure holding a list of devices found
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
|
virtual QJsonObject discover(const QJsonObject& params);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Discover first device of this type available (for configuration).
|
|
|
|
|
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @return A string of the device found
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
virtual QString discoverFirst();
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
///
|
|
|
|
|
/// @brief Get the device's properties
|
|
|
|
|
///
|
|
|
|
|
/// Used in context of a set of devices of the same type.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] params Parameters to address device
|
|
|
|
|
/// @return A JSON structure holding the device's properties
|
|
|
|
|
///
|
|
|
|
|
virtual QJsonObject getProperties(const QJsonObject& params);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Send an update to the device to identify it.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Used in context of a set of devices of the same type.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] params Parameters to address device
|
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
|
virtual void identify(const QJsonObject& /*params*/) {}
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Check, if device is properly initialised
|
|
|
|
|
///
|
|
|
|
|
/// i.e. initialisation and configuration were successful.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if device is initialised
|
|
|
|
|
///
|
|
|
|
|
bool isInitialised() const { return _isDeviceInitialised; }
|
2017-03-21 17:55:46 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
///
|
|
|
|
|
/// @brief Check, if device is ready to be used.
|
|
|
|
|
///
|
|
|
|
|
/// i.e. initialisation and opening were successful.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if device is ready
|
|
|
|
|
///
|
|
|
|
|
bool isReady() const { return _isDeviceReady; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Check, if device is in error state.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if device is in error
|
|
|
|
|
///
|
|
|
|
|
bool isInError() const { return _isDeviceInError; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Prints the color values to stdout.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] ledValues The color per led
|
|
|
|
|
///
|
|
|
|
|
static void printLedValues(const std::vector<ColorRgb>& ledValues);
|
2017-09-16 00:18:17 +02:00
|
|
|
|
|
2022-01-22 17:48:03 +01:00
|
|
|
|
///
|
|
|
|
|
/// @brief Set the common logger for LED-devices.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] log The logger to be used
|
|
|
|
|
///
|
|
|
|
|
void setLogger(Logger* log) { _log = log; }
|
|
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
|
public slots:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
2017-09-16 00:18:17 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Is called on thread start, all construction tasks and init should run here.
|
2017-09-16 00:18:17 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
virtual void start();
|
2017-09-16 00:18:17 +02:00
|
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Stops the device.
|
2016-09-23 08:49:22 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Includes switching-off the device and stopping refreshes.
|
2016-09-23 08:49:22 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
virtual void stop();
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Update the color values of the device's LEDs.
|
|
|
|
|
///
|
|
|
|
|
/// Handles refreshing of LEDs.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] ledValues The color per LED
|
|
|
|
|
/// @return Zero on success else negative (i.e. device is not ready)
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
virtual int updateLeds(const std::vector<ColorRgb>& ledValues);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
/// @brief Get the currently defined LatchTime.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
/// @return Latch time in milliseconds
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
int getLatchTime() const { return _latchTime_ms; }
|
2019-01-01 19:47:07 +01:00
|
|
|
|
|
2020-08-02 10:44:42 +02:00
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
/// @brief Get the currently defined RewriteTime.
|
2020-08-02 10:44:42 +02:00
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
/// @return Rewrite time in milliseconds
|
2020-08-02 10:44:42 +02:00
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
int getRewriteTime() const { return _refreshTimerInterval_ms; }
|
2020-08-02 10:44:42 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Get the number of LEDs supported by the device.
|
|
|
|
|
///
|
2020-11-01 21:56:19 +01:00
|
|
|
|
/// @return Number of device's LEDs, 0 = unknown number
|
2020-08-02 10:44:42 +02:00
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
|
int getLedCount() const { return _ledCount; }
|
2020-08-02 10:44:42 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Get the current active LED-device type.
|
|
|
|
|
///
|
|
|
|
|
QString getActiveDeviceType() const { return _activeDeviceType; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Get color order of device.
|
|
|
|
|
///
|
|
|
|
|
/// @return The color order
|
|
|
|
|
///
|
|
|
|
|
QString getColorOrder() const { return _colorOrder; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Get the LED-Device component's state.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if enabled
|
|
|
|
|
///
|
2020-09-14 17:19:14 +02:00
|
|
|
|
inline bool componentState() const { return _isEnabled; }
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Enables the device for output.
|
|
|
|
|
///
|
|
|
|
|
/// If the device is not ready, it will not be enabled.
|
|
|
|
|
///
|
|
|
|
|
void enable();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Disables the device for output.
|
|
|
|
|
///
|
|
|
|
|
void disable();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Switch the LEDs on.
|
|
|
|
|
///
|
|
|
|
|
/// Takes care that the device is opened and powered-on.
|
|
|
|
|
/// Depending on the configuration, the device may store its current state for later restore.
|
|
|
|
|
/// @see powerOn, storeState
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool switchOn();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Switch the LEDs off.
|
|
|
|
|
///
|
|
|
|
|
/// Takes care that the LEDs and device are switched-off and device is closed.
|
|
|
|
|
/// Depending on the configuration, the device may be powered-off or restored to its previous state.
|
|
|
|
|
/// @see powerOff, restoreState
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool switchOff();
|
|
|
|
|
|
|
|
|
|
bool switchOnOff(bool onState)
|
|
|
|
|
{
|
|
|
|
|
return onState == true ? switchOn() : switchOff();
|
|
|
|
|
}
|
2020-08-02 10:44:42 +02:00
|
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
|
signals:
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Emits whenever the LED-Device switches between on/off.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] newState The new state of the device
|
2019-01-01 19:47:07 +01:00
|
|
|
|
///
|
|
|
|
|
void enableStateChanged(bool newState);
|
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
|
protected:
|
|
|
|
|
|
2019-07-02 19:06:36 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Initialise the device's configuration.
|
2019-07-02 19:06:36 +02:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
|
/// @return True, if success
|
2019-07-02 19:06:36 +02:00
|
|
|
|
///
|
2016-12-02 12:07:24 +01:00
|
|
|
|
virtual bool init(const QJsonObject &deviceConfig);
|
2016-09-23 08:49:22 +02:00
|
|
|
|
|
2019-01-01 19:47:07 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Opens the output device.
|
2019-01-01 19:47:07 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @return Zero, on success (i.e. device is ready), else negative
|
2019-01-01 19:47:07 +01:00
|
|
|
|
///
|
|
|
|
|
virtual int open();
|
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Closes the output device.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
virtual int close();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
|
/// @return Zero on success, else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
|
|
|
|
virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
|
|
|
|
|
|
2019-12-08 13:12:01 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Writes "BLACK" to the output stream,
|
|
|
|
|
/// even if the device is not in enabled state (allowing to have a defined state during device power-off).
|
|
|
|
|
/// @note: latch-time is considered between each write
|
2019-12-08 13:12:01 +01:00
|
|
|
|
///
|
2021-04-24 19:37:29 +02:00
|
|
|
|
/// @param[in] numberOfWrites Write Black a given number of times
|
2019-12-08 13:12:01 +01:00
|
|
|
|
/// @return Zero on success else negative
|
|
|
|
|
///
|
2021-04-24 19:37:29 +02:00
|
|
|
|
virtual int writeBlack(int numberOfWrites = 1);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Writes a color to the output stream,
|
|
|
|
|
/// even if the device is not in enabled state (allowing to have a defined state during device power-off).
|
|
|
|
|
/// @note: latch-time is considered between each write
|
|
|
|
|
///
|
|
|
|
|
/// @param[in] color to be written
|
|
|
|
|
/// @param[in] numberOfWrites Write the color a given number of times
|
|
|
|
|
/// @return Zero on success else negative
|
|
|
|
|
///
|
|
|
|
|
virtual int writeColor(const ColorRgb& color, int numberOfWrites = 1);
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Power-/turn on the LED-device.
|
|
|
|
|
///
|
|
|
|
|
/// Powers-/Turns on the LED hardware, if supported.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool powerOn();
|
2019-12-08 13:12:01 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
///
|
|
|
|
|
/// @brief Power-/turn off the LED-device.
|
|
|
|
|
///
|
|
|
|
|
/// Depending on the device's capability, the device is powered-/turned off or
|
|
|
|
|
/// an off state is simulated by writing "Black to LED" (default).
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool powerOff();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Store the device's original state.
|
|
|
|
|
///
|
|
|
|
|
/// Save the device's state before hyperion color streaming starts allowing to restore state during switchOff().
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool storeState();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Restore the device's original state.
|
|
|
|
|
///
|
|
|
|
|
/// Restore the device's state as before hyperion color streaming started.
|
|
|
|
|
/// This includes the on/off state of the device.
|
|
|
|
|
///
|
|
|
|
|
/// @return True, if success
|
|
|
|
|
///
|
|
|
|
|
virtual bool restoreState();
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// @brief Converts an uint8_t array to hex string.
|
|
|
|
|
///
|
|
|
|
|
/// @param data uint8_t array
|
|
|
|
|
/// @param size of the array
|
|
|
|
|
/// @param number Number of array items to be converted.
|
|
|
|
|
/// @return array as string of hex values
|
2020-11-14 17:58:56 +01:00
|
|
|
|
QString uint8_t_to_hex_string(const uint8_t * data, const int size, int number = -1) const;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
2020-11-01 21:56:19 +01:00
|
|
|
|
///
|
|
|
|
|
/// @brief Converts a ByteArray to hex string.
|
|
|
|
|
///
|
|
|
|
|
/// @param data ByteArray
|
|
|
|
|
/// @param number Number of array items to be converted.
|
|
|
|
|
/// @return array as string of hex values
|
|
|
|
|
QString toHex(const QByteArray& data, int number = -1) const;
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Current device's type
|
|
|
|
|
QString _activeDeviceType;
|
|
|
|
|
|
|
|
|
|
/// Helper to pipe device configuration from constructor to start()
|
2019-01-01 19:47:07 +01:00
|
|
|
|
QJsonObject _devConfig;
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// The common Logger instance for all LED-devices
|
2016-06-25 22:08:17 +02:00
|
|
|
|
Logger * _log;
|
2016-08-14 10:46:44 +02:00
|
|
|
|
|
|
|
|
|
/// The buffer containing the packed RGB values
|
|
|
|
|
std::vector<uint8_t> _ledBuffer;
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Timer object which makes sure that LED data is written at a minimum rate
|
|
|
|
|
/// e.g. some devices will switch off when they do not receive data at least every 15 seconds
|
|
|
|
|
QTimer* _refreshTimer;
|
2016-10-08 08:14:36 +02:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
// Device configuration parameters
|
2016-10-08 08:14:36 +02:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Refresh interval in milliseconds
|
|
|
|
|
int _refreshTimerInterval_ms;
|
|
|
|
|
|
|
|
|
|
/// Time a device requires mandatorily between two writes (in milliseconds)
|
|
|
|
|
int _latchTime_ms;
|
|
|
|
|
|
2020-11-01 21:56:19 +01:00
|
|
|
|
/// Number of hardware LEDs supported by device.
|
|
|
|
|
uint _ledCount;
|
|
|
|
|
uint _ledRGBCount;
|
|
|
|
|
uint _ledRGBWCount;
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Does the device allow restoring the original state?
|
|
|
|
|
bool _isRestoreOrigState;
|
|
|
|
|
|
|
|
|
|
/// Device, lights state before streaming via hyperion
|
|
|
|
|
QJsonObject _orignalStateValues;
|
|
|
|
|
|
|
|
|
|
// Device states
|
|
|
|
|
/// Is the device enabled?
|
|
|
|
|
bool _isEnabled;
|
|
|
|
|
|
|
|
|
|
/// Is the device initialised?
|
|
|
|
|
bool _isDeviceInitialised;
|
|
|
|
|
|
|
|
|
|
/// Is the device ready for processing?
|
|
|
|
|
bool _isDeviceReady;
|
|
|
|
|
|
2020-09-14 17:19:14 +02:00
|
|
|
|
/// Is the device switched on?
|
|
|
|
|
bool _isOn;
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Is the device in error state and stopped?
|
|
|
|
|
bool _isDeviceInError;
|
|
|
|
|
|
|
|
|
|
/// Is the device in the switchOff process?
|
|
|
|
|
bool _isInSwitchOff;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
|
/// Timestamp of last write
|
|
|
|
|
QDateTime _lastWriteTime;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2016-11-29 23:14:15 +01:00
|
|
|
|
protected slots:
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Write the last data to the LEDs again.
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @return Zero on success else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2021-11-17 20:34:49 +01:00
|
|
|
|
virtual int rewriteLEDs();
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Set device in error state
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @param[in] errorMsg The error message to be logged
|
2020-02-10 15:21:58 +01:00
|
|
|
|
///
|
2021-04-24 19:37:29 +02:00
|
|
|
|
virtual void setInError( const QString& errorMsg);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2016-11-29 23:14:15 +01:00
|
|
|
|
private:
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Start a new refresh cycle
|
2020-02-10 15:21:58 +01:00
|
|
|
|
void startRefreshTimer();
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// @brief Stop refresh cycle
|
2020-02-10 15:21:58 +01:00
|
|
|
|
void stopRefreshTimer();
|
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Is last write refreshing enabled?
|
|
|
|
|
bool _isRefreshEnabled;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
/// Order of Colors supported by the device
|
|
|
|
|
/// "RGB", "BGR", "RBG", "BRG", "GBR", "GRB"
|
2020-02-10 15:21:58 +01:00
|
|
|
|
QString _colorOrder;
|
|
|
|
|
|
|
|
|
|
/// Last LED values written
|
2020-07-12 20:27:56 +02:00
|
|
|
|
std::vector<ColorRgb> _lastLedValues;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
#endif // LEDEVICE_H
|