LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)

* Refactor LedDevices - Initial version
* Small renamings
* Add WLED as own device
* Lpd8806 Remove open() method
* remove dependency on Qt 5.10
* Lpd8806 Remove open() method
* Update WS281x
* Update WS2812SPI
* Add writeBlack for WLED powerOff
* WLED remove extra bracket
* Allow different Nanoleaf panel numbering sequence (Feature req.#827)
* build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826)
* Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
  - [Release notes](https://github.com/faye/websocket-extensions-node/releases)
  - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
  - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)
* Fix typos
* Nanoleaf clean-up
* Yeelight support, generalize wizard elements
* Update Yeelight to handle quota in music mode
* Yeelight extend rage for extraTimeDarkness for testing
* Clean-up - Add commentary, Remove development debug statements
* Fix brightnessSwitchOffOnMinimum typo and default value
* Yeelight support restoreOriginalState, additional Fixes
* WLED - Remove UDP-Port, as it is not configurable
* Fix merging issue
* Remove QHostAddress::operator=(const QString&)' is deprecated
* Windows compile errors and (Qt 5.15 deprecation) warnings
* Fix order includes
* LedDeviceFile Support Qt5.7 and greater
* Windows compatibility and other Fixes
* Fix Qt Version compatability
* Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support
* Disable WLED Wizard Button (until Wizard is available)
* Yeelight updates
* Add wrong log-type as per #505
* Fixes and Clean-up after clang-tidy report
* Fix udpe131 not enabled for generated CID
* Change timer into dynamic for Qt Thread-Affinity
* Hue clean-up and diyHue workaround
* Updates after review feedback by m-seker
* Add "chrono" includes
This commit is contained in:
LordGrey
2020-07-12 20:27:56 +02:00
committed by GitHub
parent 3b48d8c9d6
commit 7389068a66
125 changed files with 8864 additions and 3217 deletions

View File

@@ -12,8 +12,9 @@
#include <QtCore/qmath.h>
#include <QStringList>
// Leddevice includes
// LedDevice includes
#include <leddevice/LedDevice.h>
#include "ProviderRestApi.h"
#include "ProviderUdpSSL.h"
/**
@@ -134,7 +135,7 @@ public:
///
/// @param transitionTime the transition time between colors in multiples of 100 ms
///
void setTransitionTime(unsigned int transitionTime);
void setTransitionTime(int transitionTime);
///
/// @param color the color to set
@@ -144,7 +145,7 @@ public:
unsigned int getId() const;
bool getOnOffState() const;
unsigned int getTransitionTime() const;
int getTransitionTime() const;
CiColor getColor() const;
///
@@ -162,7 +163,7 @@ private:
unsigned int _id;
unsigned int _ledidx;
bool _on;
unsigned int _transitionTime;
int _transitionTime;
CiColor _color;
/// darkes blue color in hue lamp GAMUT = black
CiColor _colorBlack;
@@ -185,14 +186,18 @@ class LedDevicePhilipsHueBridge : public ProviderUdpSSL
public:
explicit LedDevicePhilipsHueBridge(const QJsonObject &deviceConfig);
~LedDevicePhilipsHueBridge();
~LedDevicePhilipsHueBridge() override;
///
/// Sets configuration
/// @brief Initialise the access to the REST-API wrapper
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
/// @param[in] host
/// @param[in] port
/// @param[in] authentication token
///
/// @return True, if success
///
bool initRestAPI(const QString &hostname, const int port, const QString &token );
///
/// @param route the route of the POST request.
@@ -201,28 +206,56 @@ public:
///
QJsonDocument post(const QString& route, const QString& content);
void setLightState(unsigned int lightId = 0, QString state = "");
void setLightState(unsigned int lightId = 0, const QString &state = "");
const QMap<quint16,QJsonObject>& getLightMap();
const QMap<quint16,QJsonObject>& getGroupMap();
QString getGroupName(unsigned int groupId = 0);
QString getGroupName(quint16 groupId = 0);
QJsonArray getGroupLights(quint16 groupId = 0);
QJsonArray getGroupLights(unsigned int groupId = 0);
public slots:
///
/// Connect to bridge to check availbility and user
///
virtual int open(void) override;
virtual int open( const QString& hostname, const QString& port, const QString& username );
protected:
///
/// @brief Initialise the Hue-Bridge configuration and network address details
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
virtual bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Opens the Hue-Bridge device and its SSL-connection
///
/// @return Zero on success (i.e. device is ready), else negative
///
virtual int open(void) override;
///
/// @brief Closes the Hue-Bridge device and its SSL-connection
///
/// @return Zero on success (i.e. device is closed), else negative
///
virtual int close() override;
///
/// @brief Check, if Hue API response indicate error
///
/// @param[in] response from Hue-Bridge in JSON-format
/// return True, Hue Bridge reports error
///
bool checkApiError(const QJsonDocument &response );
///REST-API wrapper
ProviderRestApi* _restApi;
/// Ip address of the bridge
QString _hostname;
QString _api_port;
int _apiPort;
/// User name for the API ("newdeveloper")
QString _username;
@@ -231,7 +264,7 @@ protected:
QJsonDocument getGroupState( unsigned int groupId );
QJsonDocument setGroupState( unsigned int groupId, bool state);
bool isStreamOwner(const QString streamOwner);
bool isStreamOwner(const QString &streamOwner);
bool initMaps();
void log(const char* msg, const char* type, ...);
@@ -240,56 +273,10 @@ protected:
private:
///
/// Discover device via SSDP identifiers
///
/// @return True, if device was found
///
bool discoverDevice();
///
/// Get command as url
///
/// @param host Hostname or IP
/// @param port IP-Port
/// @param _auth_token Authorization token
/// @param Endpoint command for request
/// @return Url to execute endpoint/command
///
QString getUrl(QString host, QString port, QString auth_token, QString endpoint) const;
///
/// Execute GET request
///
/// @param url GET request for url
/// @return Response from device
///
QJsonDocument getJson(QString url);
///
/// Execute PUT request
///
/// @param Url for PUT request
/// @param json Command for request
/// @return Response from device
///
QJsonDocument putJson(QString url, QString json);
///
/// Handle replys for GET and PUT requests
///
/// @param reply Network reply
/// @return Response for request, if no error
///
QJsonDocument handleReply(QNetworkReply* const &reply );
QJsonDocument getAllBridgeInfos();
void setBridgeConfig( QJsonDocument doc );
void setLightsMap( QJsonDocument doc );
void setGroupMap( QJsonDocument doc );
/// QNetworkAccessManager for sending requests.
QNetworkAccessManager* _networkmanager;
void setBridgeConfig( const QJsonDocument &doc );
void setLightsMap( const QJsonDocument &doc );
void setGroupMap( const QJsonDocument &doc );
//Philips Hue Bridge details
QString _deviceModel;
@@ -320,105 +307,209 @@ class LedDevicePhilipsHue: public LedDevicePhilipsHueBridge
public:
///
/// Constructs specific LedDevice
/// @brief Constructs LED-device for Philips Hue Lights system
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDevicePhilipsHue(const QJsonObject &deviceConfig);
///
/// Destructor of this device
/// @brief Destructor of the LED-device
///
virtual ~LedDevicePhilipsHue();
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// Sets configuration
/// @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.
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
/// Switch the device on
virtual int switchOn() override;
/// Switch the device off
virtual int switchOff() override;
/// creates new PhilipsHueLight(s) based on user lightid with bridge feedback
/// @return A JSON structure holding a list of devices found
///
/// @param map Map of lightid/value pairs of bridge
///
void newLights(QMap<quint16, QJsonObject> map);
virtual QJsonObject discover() override;
///
/// @brief Get the Hue Bridge device's resource properties
///
/// Following parameters are required
/// @code
/// {
/// "host" : "hostname or IP [:port]",
/// "user" : "username",
/// "filter": "resource to query", root "/" is used, if empty
/// }
///@endcode
///
/// @param[in] params Parameters to query device
/// @return A JSON structure holding the device's properties
///
virtual QJsonObject getProperties(const QJsonObject& params) override;
///
/// @brief Send an update to the device to identify it.
///
/// Used in context of a set of devices of the same type.
///
/// @param[in] params Parameters to address device
///
virtual void identify(const QJsonObject& params) override;
///
/// @brief Get the number of LEDs supported by the device.
///
/// @return Number of device's LEDs
///
unsigned int getLightsCount() const { return _lightsCount; }
void setLightsCount( unsigned int lightsCount);
bool initStream();
bool getStreamGroupState();
bool setStreamGroupState(bool state);
bool startStream();
bool stopStream();
void setOnOffState(PhilipsHueLight& light, bool on);
void setTransitionTime(PhilipsHueLight& light);
void setColor(PhilipsHueLight& light, CiColor& color);
void setState(PhilipsHueLight& light, bool on, const CiColor& color);
void restoreOriginalState();
public slots:
///
/// Closes the output device.
/// Includes switching-off the device and stopping refreshes
/// @brief Stops the device.
///
virtual void close() override;
private slots:
/// creates new PhilipsHueLight(s) based on user lightid with bridge feedback
/// Includes switching-off the device and stopping refreshes.
///
/// @param map Map of lightid/value pairs of bridge
///
bool updateLights(QMap<quint16, QJsonObject> map);
void noSignalTimeout();
virtual void stop() override;
protected:
///
/// Opens and initiatialises the output device
/// Initialise the device's configuration
///
/// @return Zero on succes (i.e. device is ready and enabled) else negative
/// @param deviceConfig Device's configuration in JSON
/// @return True, if success
///
virtual bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Opens the output device
///
/// @return Zero on success (i.e. device is ready), else negative
///
virtual int open() override;
///
/// Get Philips Hue device details and configuration
/// @brief Closes the output device.
///
/// @return True, if Nanoleaf device capabilities fit configuration
/// @return Zero on success (i.e. device is closed), else negative
///
bool initLeds();
bool reinitLeds();
virtual int close() override;
///
/// Writes the RGB-Color values to the leds.
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param[in] ledValues The RGB-color per led
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
/// @return Zero on success else negative
virtual int write(const std::vector<ColorRgb>& ledValues) override;
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
/// @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() override;
///
/// @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() override;
///
/// @brief Power-/turn on the LED-device.
///
/// Powers-/Turns on the LED hardware, if supported.
///
/// @return True, if success
///
virtual bool powerOn() override;
///
/// @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() override;
///
/// @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() override;
///
/// @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() override;
private slots:
void noSignalTimeout();
private:
bool initLeds();
///
/// @brief Creates new PhilipsHueLight(s) based on user lightid with bridge feedback
///
/// @param map Map of lightid/value pairs of bridge
///
void newLights(QMap<quint16, QJsonObject> map);
bool setLights();
int writeSingleLights(const std::vector<ColorRgb>& ledValues);
/// creates new PhilipsHueLight(s) based on user lightid with bridge feedback
///
/// @param map Map of lightid/value pairs of bridge
///
bool updateLights(const QMap<quint16, QJsonObject> &map);
///
/// @brief Set the number of LEDs supported by the device.
///
/// @rparam[in] Number of device's LEDs
//
void setLightsCount( unsigned int lightsCount);
bool openStream();
bool getStreamGroupState();
bool setStreamGroupState(bool state);
bool startStream();
bool stopStream();
void writeStream();
int writeSingleLights(const std::vector<ColorRgb>& ledValues);
bool noSignalDetection();
@@ -430,21 +521,20 @@ private:
bool _switchOffOnBlack;
/// The brightness factor to multiply on color change.
double _brightnessFactor;
/// Transition time in multiples of 100 ms.
/// The default of the Hue lights is 400 ms, but we may want it snapier.
unsigned int _transitionTime;
/// Transition time in multiples of 100 ms.
/// The default of the Hue lights is 400 ms, but we may want it snappier.
int _transitionTime;
bool _isRestoreOrigState;
bool _lightStatesRestored;
bool _isInitLeds;
/// Array of the light ids.
std::vector<unsigned int> _lightIds;
std::vector<quint16> _lightIds;
/// Array to save the lamps.
std::vector<PhilipsHueLight> _lights;
unsigned int _lightsCount;
unsigned int _groupId;
quint16 _groupId;
double _brightnessMin;
double _brightnessMax;
@@ -452,7 +542,7 @@ private:
bool _allLightsBlack;
QTimer* _blackLightsTimer;
unsigned int _blackLightsTimeout;
int _blackLightsTimeout;
double _brightnessThreshold;
int _handshake_timeout_min;
@@ -466,4 +556,5 @@ private:
int start_retry_left;
int stop_retry_left;
};