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
|
|
|
///
|
|
|
|
explicit LedDeviceNanoleaf(const QJsonObject &deviceConfig);
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the LED-device
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
|
|
|
virtual ~LedDeviceNanoleaf() override;
|
|
|
|
|
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-02-10 15:21:58 +01:00
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Discover Nanoleaf devices available (for configuration).
|
|
|
|
///
|
|
|
|
/// @return A JSON structure holding a list of devices found
|
|
|
|
///
|
|
|
|
virtual QJsonObject discover() 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
|
|
|
|
///
|
|
|
|
virtual 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
|
|
|
|
///
|
|
|
|
virtual void identify(const QJsonObject& params) override;
|
|
|
|
|
|
|
|
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-07-12 20:27:56 +02: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
|
|
|
///
|
|
|
|
virtual 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
|
|
|
|
//////
|
|
|
|
virtual 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-07-12 20:27:56 +02:00
|
|
|
virtual 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-07-12 20:27:56 +02:00
|
|
|
virtual bool powerOff() override;
|
|
|
|
|
|
|
|
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-08-08 13:09:15 +02: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
|
|
|
///
|
|
|
|
/// @return Response from device
|
2020-07-12 20:27:56 +02:00
|
|
|
///@brief
|
|
|
|
QJsonDocument changeToExternalControlMode();
|
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-07-12 20:27:56 +02:00
|
|
|
QString getOnOffRequest (bool isOn ) const;
|
2019-12-08 13:12:01 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Convert vector to hex string
|
2019-12-08 13:12:01 +01:00
|
|
|
///
|
|
|
|
/// @param uint8_t vector
|
|
|
|
/// @return vector as string of hex values
|
|
|
|
std::string uint8_vector_to_hex_string( const std::vector<uint8_t>& buffer ) const;
|
2020-06-12 11:16:39 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///REST-API wrapper
|
|
|
|
ProviderRestApi* _restApi;
|
2020-06-12 11:16:39 +02: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;
|
|
|
|
uint _startPos;
|
|
|
|
uint _endPos;
|
|
|
|
|
|
|
|
//Nanoleaf device details
|
|
|
|
QString _deviceModel;
|
|
|
|
QString _deviceFirmwareVersion;
|
|
|
|
ushort _extControlVersion;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
/// The number of panels with LEDs
|
2020-06-12 11:16:39 +02:00
|
|
|
uint _panelLedCount;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
/// Array of the panel ids.
|
2020-06-12 11:16:39 +02:00
|
|
|
QVector<uint> _panelIds;
|
|
|
|
|
2019-04-08 23:13:11 +02:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICENANOLEAF_H
|