2020-07-12 20:27:56 +02:00
|
|
|
#ifndef LEDEVICEATMOORB_H
|
|
|
|
#define LEDEVICEATMOORB_H
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// Qt includes
|
2020-07-12 20:27:56 +02:00
|
|
|
#include <QUdpSocket>
|
2016-05-26 23:44:27 +02:00
|
|
|
#include <QHostAddress>
|
2017-03-04 22:17:42 +01:00
|
|
|
#include <QVector>
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
// LedDevice includes
|
2016-05-26 23:44:27 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
|
|
|
|
class QUdpSocket;
|
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
///
|
|
|
|
/// Implementation of the LedDevice interface for sending to
|
|
|
|
/// AtmoOrb devices via network
|
|
|
|
///
|
2016-08-14 10:46:44 +02:00
|
|
|
class LedDeviceAtmoOrb : public LedDevice
|
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs an AtmoOrb LED-device
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-02-10 15:21:58 +01:00
|
|
|
explicit LedDeviceAtmoOrb(const QJsonObject &deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the LedDevice
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~LedDeviceAtmoOrb() override;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs the LED-device
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
|
|
|
/// @return LedDevice constructed
|
|
|
|
///
|
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
///
|
|
|
|
/// @brief Discover AtmoOrb devices available (for configuration).
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
|
|
|
///
|
2020-09-14 17:20:00 +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-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send an update to the AtmoOrb device to identify it.
|
|
|
|
///
|
|
|
|
/// Following parameters are required
|
|
|
|
/// @code
|
|
|
|
/// {
|
|
|
|
/// "orbId" : "orb identifier in the range of (1-255)",
|
|
|
|
/// }
|
|
|
|
///@endcode
|
|
|
|
///
|
|
|
|
/// @param[in] params Parameters to address device
|
|
|
|
///
|
|
|
|
virtual void identify(const QJsonObject& params) override;
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the device's configuration
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +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
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2016-09-23 08:49:22 +02:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
///
|
|
|
|
/// @brief Closes the output device.
|
|
|
|
///
|
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int close() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int write(const std::vector<ColorRgb> & ledValues) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
private:
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Set Orbcolor
|
|
|
|
///
|
|
|
|
/// @param orbId the orb id
|
|
|
|
/// @param color which color to set
|
|
|
|
/// @param commandType which type of command to send (off / smoothing / etc..)
|
|
|
|
///
|
|
|
|
void setColor(int orbId, const ColorRgb &color, int commandType);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send Orb command
|
|
|
|
///
|
|
|
|
/// @param bytes the byte array containing command to send over multicast
|
|
|
|
///
|
|
|
|
void sendCommand(const QByteArray &bytes);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
/// QUdpSocket object used to send data over
|
|
|
|
QUdpSocket * _udpSocket;
|
|
|
|
|
|
|
|
/// QHostAddress object of multicast group IP address
|
|
|
|
QHostAddress _groupAddress;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
/// String containing multicast group IP address
|
2016-08-14 10:46:44 +02:00
|
|
|
QString _multicastGroup;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
/// Multicast port to send data to
|
|
|
|
quint16 _multiCastGroupPort;
|
|
|
|
|
|
|
|
// Multicast status
|
2020-06-28 23:05:32 +02:00
|
|
|
bool _joinedMulticastgroup;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
/// use Orbs own (external) smoothing algorithm
|
2016-08-14 10:46:44 +02:00
|
|
|
bool _useOrbSmoothing;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// Maximum allowed color difference, will skip Orb (external) smoothing once reached
|
2016-08-14 10:46:44 +02:00
|
|
|
int _skipSmoothingDiff;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
/// Array of the orb ids.
|
2020-02-10 15:21:58 +01:00
|
|
|
QVector<int> _orbIds;
|
|
|
|
|
|
|
|
// Last send color map
|
|
|
|
QMap<int, int> lastColorRedMap;
|
|
|
|
QMap<int, int> lastColorGreenMap;
|
|
|
|
QMap<int, int> lastColorBlueMap;
|
2020-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
QMultiMap<int, QHostAddress> _services;
|
2016-10-13 21:59:58 +02:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICEATMOORB_H
|