mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Code reformatted.
Former-commit-id: 6f3688791602efb33389c3ba789e7a8a723ee290
This commit is contained in:
parent
dcc6a9b449
commit
e5545eaac0
@ -12,103 +12,67 @@
|
||||
#include <set>
|
||||
|
||||
AtmoOrbLight::AtmoOrbLight(unsigned int id) {
|
||||
// Not implemented
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack,
|
||||
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) :
|
||||
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime),
|
||||
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
|
||||
manager = new QNetworkAccessManager();
|
||||
groupAddress = QHostAddress(multicastGroup);
|
||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack,
|
||||
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) :
|
||||
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime),
|
||||
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
|
||||
manager = new QNetworkAccessManager();
|
||||
groupAddress = QHostAddress(multicastGroup);
|
||||
|
||||
udpSocket = new QUdpSocket(this);
|
||||
udpSocket->bind(multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
|
||||
udpSocket = new QUdpSocket(this);
|
||||
udpSocket->bind(multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
|
||||
|
||||
joinedMulticastgroup = udpSocket->joinMulticastGroup(groupAddress);
|
||||
joinedMulticastgroup = udpSocket->joinMulticastGroup(groupAddress);
|
||||
}
|
||||
|
||||
int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
|
||||
int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues) {
|
||||
|
||||
// If not in multicast group return
|
||||
if (!joinedMulticastgroup)
|
||||
{
|
||||
// If not in multicast group return
|
||||
if (!joinedMulticastgroup) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Iterate through colors and set Orb color
|
||||
// Start off with idx 1 as 0 is reserved for controlling all orbs at once
|
||||
unsigned int idx = 1;
|
||||
for (const ColorRgb &color : ledValues) {
|
||||
// Options parameter:
|
||||
//
|
||||
// 1 = force off
|
||||
// 2 = use lamp smoothing and validate by Orb ID
|
||||
// 4 = validate by Orb ID
|
||||
//
|
||||
|
||||
if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) {
|
||||
// Force to black
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
if (orbIds[i] == idx) {
|
||||
setColor(idx, color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Default send color
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
if (orbIds[i] == idx) {
|
||||
setColor(idx, color, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Next light id.
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Iterate through colors and set Orb color
|
||||
// Start off with idx 1 as 0 is reserved for controlling all orbs at once
|
||||
unsigned int idx = 1;
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
// Options parameter:
|
||||
//
|
||||
// 1 = force off
|
||||
// 2 = use lamp smoothing and validate by Orb ID
|
||||
// 4 = validate by Orb ID
|
||||
//
|
||||
|
||||
if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) {
|
||||
// Force to black
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
if (orbIds[i] == idx)
|
||||
{
|
||||
setColor(idx, color, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default send color
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
if (orbIds[i] == idx)
|
||||
{
|
||||
setColor(idx, color, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Next light id.
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb& color, int commandType) {
|
||||
QByteArray bytes;
|
||||
bytes.resize(5 + numLeds * 3);
|
||||
bytes.fill('\0');
|
||||
|
||||
// Command identifier: C0FFEE
|
||||
bytes[0] = 0xC0;
|
||||
bytes[1] = 0xFF;
|
||||
bytes[2] = 0xEE;
|
||||
|
||||
// Command type
|
||||
bytes[3] = 2;
|
||||
|
||||
// Orb ID
|
||||
bytes[4] = orbId;
|
||||
|
||||
// RED / GREEN / BLUE
|
||||
bytes[5] = color.red;
|
||||
bytes[6] = color.green;
|
||||
bytes[7] = color.blue;
|
||||
|
||||
sendCommand(bytes);
|
||||
}
|
||||
|
||||
void LedDeviceAtmoOrb::sendCommand(const QByteArray & bytes) {
|
||||
QByteArray datagram = bytes;
|
||||
udpSocket->writeDatagram(datagram.data(), datagram.size(),
|
||||
groupAddress, multiCastGroupPort);
|
||||
}
|
||||
|
||||
int LedDeviceAtmoOrb::switchOff() {
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb &color, int commandType) {
|
||||
QByteArray bytes;
|
||||
bytes.resize(5 + numLeds * 3);
|
||||
bytes.fill('\0');
|
||||
bytes.fill('\0');
|
||||
|
||||
// Command identifier: C0FFEE
|
||||
bytes[0] = 0xC0;
|
||||
@ -116,21 +80,52 @@ int LedDeviceAtmoOrb::switchOff() {
|
||||
bytes[2] = 0xEE;
|
||||
|
||||
// Command type
|
||||
bytes[3] = 1;
|
||||
bytes[3] = 2;
|
||||
|
||||
// Orb ID
|
||||
bytes[4] = orbIds[i];
|
||||
bytes[4] = orbId;
|
||||
|
||||
// RED / GREEN / BLUE
|
||||
bytes[5] = 0;
|
||||
bytes[6] = 0;
|
||||
bytes[7] = 0;
|
||||
bytes[5] = color.red;
|
||||
bytes[6] = color.green;
|
||||
bytes[7] = color.blue;
|
||||
|
||||
sendCommand(bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LedDeviceAtmoOrb::sendCommand(const QByteArray &bytes) {
|
||||
QByteArray datagram = bytes;
|
||||
udpSocket->writeDatagram(datagram.data(), datagram.size(),
|
||||
groupAddress, multiCastGroupPort);
|
||||
}
|
||||
|
||||
int LedDeviceAtmoOrb::switchOff() {
|
||||
for (unsigned int i = 0; i < orbIds.size(); i++) {
|
||||
QByteArray bytes;
|
||||
bytes.resize(5 + numLeds * 3);
|
||||
bytes.fill('\0');
|
||||
|
||||
// Command identifier: C0FFEE
|
||||
bytes[0] = 0xC0;
|
||||
bytes[1] = 0xFF;
|
||||
bytes[2] = 0xEE;
|
||||
|
||||
// Command type
|
||||
bytes[3] = 1;
|
||||
|
||||
// Orb ID
|
||||
bytes[4] = orbIds[i];
|
||||
|
||||
// RED / GREEN / BLUE
|
||||
bytes[5] = 0;
|
||||
bytes[6] = 0;
|
||||
bytes[7] = 0;
|
||||
|
||||
sendCommand(bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LedDeviceAtmoOrb::~LedDeviceAtmoOrb() {
|
||||
delete manager;
|
||||
delete manager;
|
||||
}
|
@ -16,13 +16,13 @@ class QUdpSocket;
|
||||
|
||||
class AtmoOrbLight {
|
||||
public:
|
||||
unsigned int id;
|
||||
unsigned int id;
|
||||
|
||||
///
|
||||
/// Constructs the light.
|
||||
///
|
||||
/// @param id the orb id
|
||||
AtmoOrbLight(unsigned int id);
|
||||
///
|
||||
/// Constructs the light.
|
||||
///
|
||||
/// @param id the orb id
|
||||
AtmoOrbLight(unsigned int id);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -33,91 +33,97 @@ public:
|
||||
* @author RickDB (github)
|
||||
*/
|
||||
class LedDeviceAtmoOrb : public QObject, public LedDevice {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Last color sent
|
||||
int lastRed;
|
||||
int lastGreen;
|
||||
int lastBlue;
|
||||
// Last color sent
|
||||
int lastRed;
|
||||
int lastGreen;
|
||||
int lastBlue;
|
||||
|
||||
// Multicast status
|
||||
bool joinedMulticastgroup;
|
||||
// Multicast status
|
||||
bool joinedMulticastgroup;
|
||||
|
||||
///
|
||||
/// Constructs the device.
|
||||
///
|
||||
/// @param output is the multicast address of Orbs
|
||||
///
|
||||
/// @param switchOffOnBlack turn off Orbs on black (default: false)
|
||||
///
|
||||
/// @param transitiontime is optional and not used at the moment
|
||||
///
|
||||
/// @param port is the multicast port.
|
||||
///
|
||||
/// @param numLeds is the total amount of leds per Orb
|
||||
///
|
||||
/// @param array containing orb ids
|
||||
///
|
||||
LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack =
|
||||
false, int transitiontime = 0, int port = 49692, int numLeds = 24, std::vector<unsigned int> orbIds = std::vector<unsigned int>());
|
||||
///
|
||||
/// Destructor of this device
|
||||
///
|
||||
virtual ~LedDeviceAtmoOrb();
|
||||
///
|
||||
/// Constructs the device.
|
||||
///
|
||||
/// @param output is the multicast address of Orbs
|
||||
///
|
||||
/// @param switchOffOnBlack turn off Orbs on black (default: false)
|
||||
///
|
||||
/// @param transitiontime is optional and not used at the moment
|
||||
///
|
||||
/// @param port is the multicast port.
|
||||
///
|
||||
/// @param numLeds is the total amount of leds per Orb
|
||||
///
|
||||
/// @param array containing orb ids
|
||||
///
|
||||
LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack =
|
||||
false, int transitiontime = 0, int port = 49692, int numLeds = 24,
|
||||
std::vector<unsigned int> orbIds = std::vector < unsigned int
|
||||
|
||||
>());
|
||||
|
||||
///
|
||||
/// Destructor of this device
|
||||
///
|
||||
virtual ~LedDeviceAtmoOrb();
|
||||
|
||||
///
|
||||
/// 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);
|
||||
|
||||
virtual int switchOff();
|
||||
|
||||
///
|
||||
/// 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);
|
||||
virtual int switchOff();
|
||||
private:
|
||||
/// QNetworkAccessManager object for sending requests.
|
||||
QNetworkAccessManager* manager;
|
||||
/// QNetworkAccessManager object for sending requests.
|
||||
QNetworkAccessManager *manager;
|
||||
|
||||
/// String containing multicast group IP address
|
||||
QString multicastGroup;
|
||||
/// String containing multicast group IP address
|
||||
QString multicastGroup;
|
||||
|
||||
/// Switch off when detecting black
|
||||
bool switchOffOnBlack;
|
||||
/// Switch off when detecting black
|
||||
bool switchOffOnBlack;
|
||||
|
||||
/// Transition time between colors (not implemented)
|
||||
int transitiontime;
|
||||
/// Transition time between colors (not implemented)
|
||||
int transitiontime;
|
||||
|
||||
/// Multicast port to send data to
|
||||
int multiCastGroupPort;
|
||||
/// Multicast port to send data to
|
||||
int multiCastGroupPort;
|
||||
|
||||
/// Number of leds in Orb, used to determine buffer size
|
||||
int numLeds;
|
||||
/// Number of leds in Orb, used to determine buffer size
|
||||
int numLeds;
|
||||
|
||||
/// QHostAddress object of multicast group IP address
|
||||
QHostAddress groupAddress;
|
||||
/// QHostAddress object of multicast group IP address
|
||||
QHostAddress groupAddress;
|
||||
|
||||
/// QUdpSocket object used to send data over
|
||||
QUdpSocket *udpSocket;
|
||||
/// QUdpSocket object used to send data over
|
||||
QUdpSocket *udpSocket;
|
||||
|
||||
/// Array of the orb ids.
|
||||
std::vector<unsigned int> orbIds;
|
||||
/// Array of the orb ids.
|
||||
std::vector<unsigned int> orbIds;
|
||||
|
||||
///
|
||||
/// 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);
|
||||
///
|
||||
/// 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);
|
||||
///
|
||||
/// Send Orb command
|
||||
///
|
||||
/// @param bytes the byte array containing command to send over multicast
|
||||
///
|
||||
void sendCommand(const QByteArray &bytes);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user