2016-05-26 23:44:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QHostAddress>
|
2017-03-04 22:17:42 +01:00
|
|
|
#include <QMap>
|
|
|
|
#include <QVector>
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
|
|
|
|
class QUdpSocket;
|
|
|
|
|
|
|
|
class AtmoOrbLight {
|
|
|
|
public:
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Constructs the light.
|
|
|
|
///
|
|
|
|
/// @param id the orb id
|
|
|
|
AtmoOrbLight(unsigned int id);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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:
|
|
|
|
// Last send color map
|
|
|
|
QMap<int, int> lastColorRedMap;
|
|
|
|
QMap<int, int> lastColorGreenMap;
|
|
|
|
QMap<int, int> lastColorBlueMap;
|
|
|
|
|
|
|
|
// Multicast status
|
|
|
|
bool joinedMulticastgroup;
|
|
|
|
|
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// Constructs specific LedDevice
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// @param deviceConfig json device config
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceAtmoOrb(const QJsonObject &deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2016-10-13 21:59:58 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
/// constructs leddevice
|
2016-10-13 21:59:58 +02:00
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
|
|
|
/// Destructor of this device
|
|
|
|
///
|
|
|
|
virtual ~LedDeviceAtmoOrb();
|
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
virtual int switchOff();
|
|
|
|
|
|
|
|
private:
|
2016-05-26 23:44:27 +02:00
|
|
|
///
|
|
|
|
/// Sends the given led-color values to the Orbs
|
|
|
|
///
|
|
|
|
/// @param ledValues The color-value per led
|
|
|
|
/// @return Zero on success else negative
|
|
|
|
///
|
|
|
|
virtual int write(const std::vector <ColorRgb> &ledValues);
|
|
|
|
|
|
|
|
/// QNetworkAccessManager object for sending requests.
|
2016-08-14 10:46:44 +02:00
|
|
|
QNetworkAccessManager *_manager;
|
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
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// Multicast port to send data to
|
2016-08-14 10:46:44 +02:00
|
|
|
int _multiCastGroupPort;
|
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
|
|
|
|
|
|
|
/// QHostAddress object of multicast group IP address
|
2016-08-14 10:46:44 +02:00
|
|
|
QHostAddress _groupAddress;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
/// QUdpSocket object used to send data over
|
2016-08-14 10:46:44 +02:00
|
|
|
QUdpSocket * _udpSocket;
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
/// Array of the orb ids.
|
2017-03-04 22:17:42 +01:00
|
|
|
QVector<unsigned int> _orbIds;
|
2016-05-26 23:44:27 +02: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(unsigned 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-10-13 21:59:58 +02:00
|
|
|
};
|