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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation for the AtmoOrb
|
|
|
|
*
|
|
|
|
* To use set the device to "atmoorb".
|
|
|
|
*
|
|
|
|
* @author RickDB (github)
|
|
|
|
*/
|
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-07-12 20:27:56 +02:00
|
|
|
virtual ~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-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-07-12 20:27:56 +02:00
|
|
|
virtual 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;
|
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-07-12 20:27:56 +02:00
|
|
|
virtual 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-07-12 20:27:56 +02:00
|
|
|
virtual int write(const std::vector<ColorRgb> & ledValues) override;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// Transition time between colors (not implemented)
|
2016-08-14 10:46:44 +02:00
|
|
|
int _transitiontime;
|
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
|
|
|
|
|
|
|
/// Number of leds in Orb, used to determine buffer size
|
2016-08-14 10:46:44 +02:00
|
|
|
int _numLeds;
|
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;
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICEATMOORB_H
|