forked from hyperion-project/hyperion.ng
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,71 @@ | ||
// STL includes | ||
|
||
#include <cstring> | ||
#include <iostream> | ||
|
||
// hyperion includes | ||
#include <hyperion/LedString.h> | ||
|
||
// QT includes | ||
#include <QJsonObject> | ||
|
||
std::vector<Led>& LedString::leds() | ||
{ | ||
return mLeds; | ||
return _leds; | ||
} | ||
|
||
const std::vector<Led>& LedString::leds() const | ||
{ | ||
return mLeds; | ||
return _leds; | ||
} | ||
|
||
/** | ||
* Construct the 'led-string' with the integration area definition per led and the color | ||
* ordering of the RGB channels | ||
* @param ledsConfig The configuration of the led areas | ||
* @param deviceOrder The default RGB channel ordering | ||
* @return The constructed ledstring | ||
*/ | ||
LedString LedString::createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder) | ||
{ | ||
LedString ledString; | ||
const QString deviceOrderStr = colorOrderToString(deviceOrder); | ||
|
||
ledString.hasBlackListedLeds = false; | ||
|
||
for (signed i = 0; i < ledConfigArray.size(); ++i) | ||
{ | ||
const QJsonObject& ledConfig = ledConfigArray[i].toObject(); | ||
Led led; | ||
|
||
led.minX_frac = qMax(0.0, qMin(1.0, ledConfig["hmin"].toDouble())); | ||
led.maxX_frac = qMax(0.0, qMin(1.0, ledConfig["hmax"].toDouble())); | ||
led.minY_frac = qMax(0.0, qMin(1.0, ledConfig["vmin"].toDouble())); | ||
led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble())); | ||
// Fix if the user swapped min and max | ||
if (led.minX_frac > led.maxX_frac) | ||
{ | ||
std::swap(led.minX_frac, led.maxX_frac); | ||
} | ||
if (led.minY_frac > led.maxY_frac) | ||
{ | ||
std::swap(led.minY_frac, led.maxY_frac); | ||
} | ||
|
||
// Get the order of the rgb channels for this led (default is device order) | ||
led.colorOrder = stringToColorOrder(ledConfig["colorOrder"].toString(deviceOrderStr)); | ||
|
||
led.isBlacklisted = false; | ||
if (led.minX_frac < std::numeric_limits<double>::epsilon() && | ||
led.maxX_frac < std::numeric_limits<double>::epsilon() && | ||
led.minY_frac < std::numeric_limits<double>::epsilon() && | ||
led.maxY_frac < std::numeric_limits<double>::epsilon() | ||
) | ||
{ | ||
led.isBlacklisted = true; | ||
ledString.hasBlackListedLeds |= led.isBlacklisted; | ||
} | ||
ledString.leds().push_back(led); | ||
} | ||
return ledString; | ||
} |