2020-07-12 20:27:56 +02:00
|
|
|
#ifndef LEDEVICENANOLEAF_H
|
|
|
|
#define LEDEVICENANOLEAF_H
|
2019-04-08 23:13:11 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// LedDevice includes
|
2019-04-08 23:13:11 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
2020-07-12 20:27:56 +02:00
|
|
|
#include "ProviderRestApi.h"
|
2019-04-08 23:13:11 +02:00
|
|
|
#include "ProviderUdp.h"
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QString>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Implementation of the LedDevice interface for sending to
|
|
|
|
/// Nanoleaf devices via network by using the 'external control' protocol.
|
|
|
|
///
|
|
|
|
class LedDeviceNanoleaf : public ProviderUdp
|
|
|
|
{
|
|
|
|
public:
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs LED-device for Nanoleaf LightPanels (aka Aurora) or Canvas
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// following code shows all configuration options
|
2020-02-10 15:21:58 +01:00
|
|
|
/// @code
|
|
|
|
/// "device" :
|
|
|
|
/// {
|
2020-07-12 20:27:56 +02:00
|
|
|
/// "type" : "nanoleaf"
|
|
|
|
/// "host" : "hostname or IP",
|
|
|
|
/// "token": "Authentication Token",
|
2020-02-10 15:21:58 +01:00
|
|
|
/// },
|
|
|
|
///@endcode
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
explicit LedDeviceNanoleaf(const QJsonObject& deviceConfig);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the LED-device
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~LedDeviceNanoleaf() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Constructs the LED-device
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
|
|
|
/// @return LedDevice constructed
|
2020-11-14 17:58:56 +01:00
|
|
|
static LedDevice* construct(const QJsonObject& deviceConfig);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Discover Nanoleaf devices available (for configuration).
|
|
|
|
///
|
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-11-14 17:58:56 +01:00
|
|
|
QJsonObject discover(const QJsonObject& params) override;
|
2019-04-08 23:13:11 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Get the Nanoleaf device's resource properties
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// Following parameters are required
|
|
|
|
/// @code
|
|
|
|
/// {
|
|
|
|
/// "host" : "hostname or IP [:port]",
|
|
|
|
/// "token" : "authentication token",
|
|
|
|
/// "filter": "resource to query", root "/" is used, if empty
|
|
|
|
/// }
|
|
|
|
///@endcode
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] params Parameters to query device
|
|
|
|
/// @return A JSON structure holding the device's properties
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
QJsonObject getProperties(const QJsonObject& params) override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Send an update to the Nanoleaf device to identify it.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// Following parameters are required
|
|
|
|
/// @code
|
|
|
|
/// {
|
|
|
|
/// "host" : "hostname or IP [:port]",
|
|
|
|
/// "token" : "authentication token",
|
|
|
|
/// }
|
|
|
|
///@endcode
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] params Parameters to address device
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
void identify(const QJsonObject& params) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
protected:
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the Nanoleaf device's configuration and network address details
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
bool init(const QJsonObject& deviceConfig) override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens 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 ready), else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2019-04-08 23:13:11 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
|
|
|
//////
|
2020-11-14 17:58:56 +01:00
|
|
|
int write(const std::vector<ColorRgb>& ledValues) override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Power-/turn on the Nanoleaf device.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Store the device's original state.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool powerOn() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Power-/turn off the Nanoleaf device.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return True if success
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool powerOff() override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
private:
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the access to the REST-API wrapper
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] host
|
|
|
|
/// @param[in] port
|
|
|
|
/// @param[in] authentication token
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return True, if success
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
bool initRestAPI(const QString& hostname, int port, const QString& token);
|
2019-12-08 13:12:01 +01:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Get Nanoleaf device details and configuration
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return True, if Nanoleaf device capabilities fit configuration
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
bool initLedsConfiguration();
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Change Nanoleaf device to External Control (UDP) mode
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2021-03-19 22:52:04 +01:00
|
|
|
/// @return True, if success
|
|
|
|
bool changeToExternalControlMode();
|
|
|
|
///
|
|
|
|
/// @brief Change Nanoleaf device to External Control (UDP) mode
|
|
|
|
///
|
|
|
|
/// @param[out] response from device
|
|
|
|
///
|
|
|
|
/// @return True, if success
|
|
|
|
bool changeToExternalControlMode(QJsonDocument& resp);
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Get command to power Nanoleaf device on or off
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param isOn True, if to switch on device
|
|
|
|
/// @return Command to switch device on/off
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
QString getOnOffRequest(bool isOn) const;
|
2020-06-12 11:16:39 +02:00
|
|
|
|
2021-03-19 22:52:04 +01:00
|
|
|
///
|
|
|
|
/// @brief Discover Nanoleaf devices available (for configuration).
|
|
|
|
/// Nanoleaf specific ssdp discovery
|
|
|
|
///
|
|
|
|
/// @return A JSON structure holding a list of devices found
|
|
|
|
///
|
|
|
|
QJsonArray discover();
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///REST-API wrapper
|
|
|
|
ProviderRestApi* _restApi;
|
2020-06-12 11:16:39 +02:00
|
|
|
|
2021-03-19 22:52:04 +01:00
|
|
|
QString _hostName;
|
2020-07-12 20:27:56 +02:00
|
|
|
int _apiPort;
|
|
|
|
QString _authToken;
|
2020-06-12 11:16:39 +02:00
|
|
|
|
|
|
|
bool _topDown;
|
|
|
|
bool _leftRight;
|
2020-11-14 17:58:56 +01:00
|
|
|
int _startPos;
|
|
|
|
int _endPos;
|
2020-06-12 11:16:39 +02:00
|
|
|
|
|
|
|
//Nanoleaf device details
|
|
|
|
QString _deviceModel;
|
|
|
|
QString _deviceFirmwareVersion;
|
|
|
|
ushort _extControlVersion;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
/// The number of panels with LEDs
|
2020-11-14 17:58:56 +01:00
|
|
|
int _panelLedCount;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
/// Array of the panel ids.
|
2020-11-14 17:58:56 +01:00
|
|
|
QVector<int> _panelIds;
|
2019-04-08 23:13:11 +02:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICENANOLEAF_H
|