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>
|
#include <set>
|
||||||
|
|
||||||
AtmoOrbLight::AtmoOrbLight(unsigned int id) {
|
AtmoOrbLight::AtmoOrbLight(unsigned int id) {
|
||||||
// Not implemented
|
// Not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack,
|
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack,
|
||||||
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) :
|
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) :
|
||||||
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime),
|
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime),
|
||||||
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
|
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
|
||||||
manager = new QNetworkAccessManager();
|
manager = new QNetworkAccessManager();
|
||||||
groupAddress = QHostAddress(multicastGroup);
|
groupAddress = QHostAddress(multicastGroup);
|
||||||
|
|
||||||
udpSocket = new QUdpSocket(this);
|
udpSocket = new QUdpSocket(this);
|
||||||
udpSocket->bind(multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
|
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 not in multicast group return
|
||||||
if (!joinedMulticastgroup)
|
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;
|
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) {
|
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++) {
|
|
||||||
QByteArray bytes;
|
QByteArray bytes;
|
||||||
bytes.resize(5 + numLeds * 3);
|
bytes.resize(5 + numLeds * 3);
|
||||||
bytes.fill('\0');
|
bytes.fill('\0');
|
||||||
|
|
||||||
// Command identifier: C0FFEE
|
// Command identifier: C0FFEE
|
||||||
bytes[0] = 0xC0;
|
bytes[0] = 0xC0;
|
||||||
@ -116,21 +80,52 @@ int LedDeviceAtmoOrb::switchOff() {
|
|||||||
bytes[2] = 0xEE;
|
bytes[2] = 0xEE;
|
||||||
|
|
||||||
// Command type
|
// Command type
|
||||||
bytes[3] = 1;
|
bytes[3] = 2;
|
||||||
|
|
||||||
// Orb ID
|
// Orb ID
|
||||||
bytes[4] = orbIds[i];
|
bytes[4] = orbId;
|
||||||
|
|
||||||
// RED / GREEN / BLUE
|
// RED / GREEN / BLUE
|
||||||
bytes[5] = 0;
|
bytes[5] = color.red;
|
||||||
bytes[6] = 0;
|
bytes[6] = color.green;
|
||||||
bytes[7] = 0;
|
bytes[7] = color.blue;
|
||||||
|
|
||||||
sendCommand(bytes);
|
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() {
|
LedDeviceAtmoOrb::~LedDeviceAtmoOrb() {
|
||||||
delete manager;
|
delete manager;
|
||||||
}
|
}
|
@ -16,13 +16,13 @@ class QUdpSocket;
|
|||||||
|
|
||||||
class AtmoOrbLight {
|
class AtmoOrbLight {
|
||||||
public:
|
public:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Constructs the light.
|
/// Constructs the light.
|
||||||
///
|
///
|
||||||
/// @param id the orb id
|
/// @param id the orb id
|
||||||
AtmoOrbLight(unsigned int id);
|
AtmoOrbLight(unsigned int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,91 +33,97 @@ public:
|
|||||||
* @author RickDB (github)
|
* @author RickDB (github)
|
||||||
*/
|
*/
|
||||||
class LedDeviceAtmoOrb : public QObject, public LedDevice {
|
class LedDeviceAtmoOrb : public QObject, public LedDevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
// Last color sent
|
// Last color sent
|
||||||
int lastRed;
|
int lastRed;
|
||||||
int lastGreen;
|
int lastGreen;
|
||||||
int lastBlue;
|
int lastBlue;
|
||||||
|
|
||||||
// Multicast status
|
// Multicast status
|
||||||
bool joinedMulticastgroup;
|
bool joinedMulticastgroup;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Constructs the device.
|
/// Constructs the device.
|
||||||
///
|
///
|
||||||
/// @param output is the multicast address of Orbs
|
/// @param output is the multicast address of Orbs
|
||||||
///
|
///
|
||||||
/// @param switchOffOnBlack turn off Orbs on black (default: false)
|
/// @param switchOffOnBlack turn off Orbs on black (default: false)
|
||||||
///
|
///
|
||||||
/// @param transitiontime is optional and not used at the moment
|
/// @param transitiontime is optional and not used at the moment
|
||||||
///
|
///
|
||||||
/// @param port is the multicast port.
|
/// @param port is the multicast port.
|
||||||
///
|
///
|
||||||
/// @param numLeds is the total amount of leds per Orb
|
/// @param numLeds is the total amount of leds per Orb
|
||||||
///
|
///
|
||||||
/// @param array containing orb ids
|
/// @param array containing orb ids
|
||||||
///
|
///
|
||||||
LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack =
|
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>());
|
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();
|
|
||||||
|
///
|
||||||
|
/// 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:
|
private:
|
||||||
/// QNetworkAccessManager object for sending requests.
|
/// QNetworkAccessManager object for sending requests.
|
||||||
QNetworkAccessManager* manager;
|
QNetworkAccessManager *manager;
|
||||||
|
|
||||||
/// String containing multicast group IP address
|
/// String containing multicast group IP address
|
||||||
QString multicastGroup;
|
QString multicastGroup;
|
||||||
|
|
||||||
/// Switch off when detecting black
|
/// Switch off when detecting black
|
||||||
bool switchOffOnBlack;
|
bool switchOffOnBlack;
|
||||||
|
|
||||||
/// Transition time between colors (not implemented)
|
/// Transition time between colors (not implemented)
|
||||||
int transitiontime;
|
int transitiontime;
|
||||||
|
|
||||||
/// Multicast port to send data to
|
/// Multicast port to send data to
|
||||||
int multiCastGroupPort;
|
int multiCastGroupPort;
|
||||||
|
|
||||||
/// Number of leds in Orb, used to determine buffer size
|
/// Number of leds in Orb, used to determine buffer size
|
||||||
int numLeds;
|
int numLeds;
|
||||||
|
|
||||||
/// QHostAddress object of multicast group IP address
|
/// QHostAddress object of multicast group IP address
|
||||||
QHostAddress groupAddress;
|
QHostAddress groupAddress;
|
||||||
|
|
||||||
/// QUdpSocket object used to send data over
|
/// QUdpSocket object used to send data over
|
||||||
QUdpSocket *udpSocket;
|
QUdpSocket *udpSocket;
|
||||||
|
|
||||||
/// Array of the orb ids.
|
/// Array of the orb ids.
|
||||||
std::vector<unsigned int> orbIds;
|
std::vector<unsigned int> orbIds;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set Orbcolor
|
/// Set Orbcolor
|
||||||
///
|
///
|
||||||
/// @param orbId the orb id
|
/// @param orbId the orb id
|
||||||
///
|
///
|
||||||
/// @param color which color to set
|
/// @param color which color to set
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// @param commandType which type of command to send (off / smoothing / etc..)
|
/// @param commandType which type of command to send (off / smoothing / etc..)
|
||||||
///
|
///
|
||||||
void setColor(unsigned int orbId, const ColorRgb& color, int commandType);
|
void setColor(unsigned int orbId, const ColorRgb &color, int commandType);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Send Orb command
|
/// Send Orb command
|
||||||
///
|
///
|
||||||
/// @param bytes the byte array containing command to send over multicast
|
/// @param bytes the byte array containing command to send over multicast
|
||||||
///
|
///
|
||||||
void sendCommand(const QByteArray & bytes);
|
void sendCommand(const QByteArray &bytes);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user