2020-07-12 20:27:56 +02:00
|
|
|
#ifndef LEDDEVICEWLED_H
|
|
|
|
#define LEDDEVICEWLED_H
|
|
|
|
|
|
|
|
// LedDevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
#include "ProviderRestApi.h"
|
|
|
|
#include "ProviderUdp.h"
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Implementation of a WLED-device
|
|
|
|
/// ...
|
|
|
|
///
|
|
|
|
///
|
|
|
|
class LedDeviceWled : public ProviderUdp
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// @brief Constructs a WLED-device
|
|
|
|
///
|
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
|
|
|
///
|
|
|
|
explicit LedDeviceWled(const QJsonObject &deviceConfig);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Destructor of the WLED-device
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~LedDeviceWled() override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Constructs the WLED-device
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
|
|
|
/// @return LedDevice constructed
|
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Discover WLED 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;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get the WLED device's resource properties
|
|
|
|
///
|
|
|
|
/// Following parameters are required
|
|
|
|
/// @code
|
|
|
|
/// {
|
|
|
|
/// "host" : "hostname or IP [:port]",
|
|
|
|
/// "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
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
QJsonObject getProperties(const QJsonObject& params) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send an update to the WLED device to identify it.
|
|
|
|
///
|
|
|
|
/// Following parameters are required
|
|
|
|
/// @code
|
|
|
|
/// {
|
|
|
|
/// "host" : "hostname or IP [:port]",
|
|
|
|
/// }
|
|
|
|
///@endcode
|
|
|
|
///
|
|
|
|
/// @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:
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Initialise the WLED device's configuration and network address details
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
|
|
|
///
|
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int write(const std::vector<ColorRgb> & ledValues) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Power-/turn on the WLED device.
|
|
|
|
///
|
2020-10-19 10:54:41 +02:00
|
|
|
/// @return True if success
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool powerOn() override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Power-/turn off the WLED device.
|
|
|
|
///
|
|
|
|
/// @return True if success
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool powerOff() override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Initialise the access to the REST-API wrapper
|
|
|
|
///
|
|
|
|
/// @param[in] host
|
|
|
|
/// @param[in] port
|
|
|
|
/// @return True, if success
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool initRestAPI(const QString &hostname, int port );
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get command to power WLED-device on or off
|
|
|
|
///
|
|
|
|
/// @param isOn True, if to switch on device
|
|
|
|
/// @return Command to switch device on/off
|
|
|
|
///
|
|
|
|
QString getOnOffRequest (bool isOn ) const;
|
|
|
|
|
|
|
|
///REST-API wrapper
|
|
|
|
ProviderRestApi* _restApi;
|
|
|
|
|
|
|
|
QString _hostname;
|
|
|
|
int _apiPort;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LEDDEVICEWLED_H
|