Added multi Orb support, Orb ID should match that of leds index with a +1 offset (index 0 = Orb id 1 etc..)

Code cleanup.


Former-commit-id: af8a6df876f334c9a65b1a936b5bb85b380d86d1
This commit is contained in:
RickDB 2016-03-14 23:19:20 +01:00
parent 0d8c4ac5fb
commit fdb164da0a
2 changed files with 16 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QTime> #include <QTime>
//#include <iostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <set> #include <set>
@ -44,16 +45,11 @@ int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
return 0; return 0;
} }
// Iterate through colors and set Orb color. // Iterate through colors and set Orb color
unsigned int idx = 0; // Start off with idx 1 as 0 is reserved for controlling all orbs at once
unsigned int idx = 1;
for (const ColorRgb& color : ledValues) for (const ColorRgb& color : ledValues)
{ {
// If color is identical skip color setter
if(color.red == lastRed && color.green == lastGreen && color.blue == lastBlue)
{
continue;
}
// Options parameter: // Options parameter:
// //
// 1 = force off // 1 = force off
@ -63,22 +59,23 @@ int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) { if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) {
// Force to black // Force to black
for (int i = 0; i < orbIds.size(); i++) { for (unsigned int i = 0; i < orbIds.size(); i++) {
setColor(orbIds[i], color, 1); if (orbIds[i] == idx)
{
setColor(idx, color, 1);
}
} }
} }
else else
{ {
// Default send color // Default send color
for (int i = 0; i < orbIds.size(); i++) { for (unsigned int i = 0; i < orbIds.size(); i++) {
setColor(orbIds[i], color, 4); if (orbIds[i] == idx)
{
setColor(idx, color, 4);
}
} }
} }
// Store current colors
lastRed = color.red;
lastGreen = color.green;
lastBlue = color.blue;
// Next light id. // Next light id.
idx++; idx++;
@ -118,8 +115,7 @@ void LedDeviceAtmoOrb::sendCommand(const QByteArray & bytes) {
int LedDeviceAtmoOrb::switchOff() { int LedDeviceAtmoOrb::switchOff() {
// Default send color // Default send color
for (int i = 0; i < orbIds.size(); i++) { for (unsigned int i = 0; i < orbIds.size(); i++) {
QByteArray bytes; QByteArray bytes;
bytes.resize(5 + numLeds * 3); bytes.resize(5 + numLeds * 3);

View File

@ -52,7 +52,7 @@ public:
/// ///
/// @param output is the multicast address of Orbs /// @param output is the multicast address of Orbs
/// ///
/// @param switchOffOnBlack kill lights for 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
/// ///