AtmoOrb smoothing additions

* Updated smoothing options for AtmoOrb, can now choose between Orb external or Hyperion's internal smoothing.
With skipSmoothingDif you can set the maximum allowed color difference before overriding / clearing Orb smoothing during faster color change like for instance color <-> black.

* Updated inline documentation.

* Fixed command type typo in AtmoOrb device.

* Corrected variable spelling in AtmoOrb device.

* Make smoothing also match equal values for AtmoOrb smoothing differential


Former-commit-id: 3eede43c2f76fa324f0144aeac0526b8125ad149
This commit is contained in:
Rick164 2016-04-02 00:07:28 +02:00 committed by brindosch
parent b37cbd26d5
commit 02fef83bb8
3 changed files with 54 additions and 40 deletions

View File

@ -15,9 +15,9 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) {
// Not implemented // Not implemented
} }
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack, LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string &output, bool useOrbSmoothing,
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) : int transitiontime, int skipSmoothingDiff, int port, int numLeds, std::vector<unsigned int> orbIds) :
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime), multicastGroup(output.c_str()), useOrbSmoothing(useOrbSmoothing), transitiontime(transitiontime), skipSmoothingDiff(skipSmoothingDiff),
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) { multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
manager = new QNetworkAccessManager(); manager = new QNetworkAccessManager();
groupAddress = QHostAddress(multicastGroup); groupAddress = QHostAddress(multicastGroup);
@ -35,30 +35,40 @@ int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues) {
return 0; return 0;
} }
// Iterate through colors and set Orb color // Command options:
// 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 // 1 = force off
// 2 = use lamp smoothing and validate by Orb ID // 2 = use lamp smoothing and validate by Orb ID
// 4 = validate by Orb ID // 4 = validate by Orb ID
//
if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) { // When setting useOrbSmoothing = true it's recommended to disable Hyperion's own smoothing as it will conflict (double smoothing)
// Force to black int commandType = 4;
if(useOrbSmoothing)
{
commandType = 2;
}
// 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) {
// If color difference is higher than skipSmoothingDiff than we skip Orb smoothing (if enabled) and send it right away
if ((skipSmoothingDiff != 0 && useOrbSmoothing) && (abs(color.red - lastRed) >= skipSmoothingDiff || abs(color.blue - lastBlue) >= skipSmoothingDiff ||
abs(color.green - lastGreen) >= skipSmoothingDiff))
{
// Skip Orb smoothing when using (command type 4)
for (unsigned int i = 0; i < orbIds.size(); i++) { for (unsigned int i = 0; i < orbIds.size(); i++) {
if (orbIds[i] == idx) { if (orbIds[i] == idx) {
setColor(idx, color, 1); setColor(idx, color, 4);
} }
} }
} }
else { else {
// Default send color // Send color
for (unsigned int i = 0; i < orbIds.size(); i++) { for (unsigned int i = 0; i < orbIds.size(); i++) {
if (orbIds[i] == idx) { if (orbIds[i] == idx) {
setColor(idx, color, 4); setColor(idx, color, commandType);
} }
} }
} }
@ -80,7 +90,7 @@ void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb &color, int c
bytes[2] = 0xEE; bytes[2] = 0xEE;
// Command type // Command type
bytes[3] = 2; bytes[3] = commandType;
// Orb ID // Orb ID
bytes[4] = orbId; bytes[4] = orbId;

View File

@ -48,21 +48,21 @@ public:
/// ///
/// @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 transitiontime is optional and not used at the moment /// @param transitiontime is optional and not used at the moment
/// ///
/// @param useOrbSmoothing use Orbs own (external) smoothing algorithm (default: false)
///
/// @param skipSmoothingDiff minimal color (0-255) difference to override smoothing so that if current and previously received colors are higher than set dif we override smoothing
///
/// @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 useOrbSmoothing =
false, int transitiontime = 0, int port = 49692, int numLeds = 24, false, int transitiontime = 0, int skipSmoothingDiff = 0, int port = 49692, int numLeds = 24,
std::vector<unsigned int> orbIds = std::vector < unsigned int std::vector<unsigned int> orbIds = std::vector < unsigned int>());
>());
/// ///
/// Destructor of this device /// Destructor of this device
@ -87,12 +87,15 @@ private:
/// String containing multicast group IP address /// String containing multicast group IP address
QString multicastGroup; QString multicastGroup;
/// Switch off when detecting black /// use Orbs own (external) smoothing algorithm
bool switchOffOnBlack; bool useOrbSmoothing;
/// Transition time between colors (not implemented) /// Transition time between colors (not implemented)
int transitiontime; int transitiontime;
// Maximum allowed color difference, will skip Orb (external) smoothing once reached
int skipSmoothingDiff;
/// Multicast port to send data to /// Multicast port to send data to
int multiCastGroupPort; int multiCastGroupPort;

View File

@ -249,8 +249,9 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
else if (type == "atmoorb") else if (type == "atmoorb")
{ {
const std::string output = deviceConfig["output"].asString(); const std::string output = deviceConfig["output"].asString();
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool(); const bool useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool();
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt(); const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
const int skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt();
const int port = deviceConfig.get("port", 1).asInt(); const int port = deviceConfig.get("port", 1).asInt();
const int numLeds = deviceConfig.get("numLeds", 1).asInt(); const int numLeds = deviceConfig.get("numLeds", 1).asInt();
const std::string orbId = deviceConfig["orbIds"].asString(); const std::string orbId = deviceConfig["orbIds"].asString();
@ -273,7 +274,7 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
orbIds.push_back(atoi(orbId.c_str())); orbIds.push_back(atoi(orbId.c_str()));
} }
device = new LedDeviceAtmoOrb(output, switchOffOnBlack, transitiontime, port, numLeds, orbIds); device = new LedDeviceAtmoOrb(output, useOrbSmoothing, transitiontime, skipSmoothingDiff, port, numLeds, orbIds);
} }
else if (type == "file") else if (type == "file")
{ {