-
-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy pathLedString.cpp
103 lines (87 loc) · 2.65 KB
/
LedString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// STL includes
#include <cstring>
#include <iostream>
// hyperion includes
#include <hyperion/LedString.h>
#include <utils/Logger.h>
// QT includes
#include <QJsonObject>
std::vector<Led>& LedString::leds()
{
return _leds;
}
const std::vector<Led>& LedString::leds() const
{
return _leds;
}
std::vector<int>& LedString::blacklistedLedIds()
{
return _blacklistedLedIds;
}
const std::vector<int>& LedString::blacklistedLedIds() const
{
return _blacklistedLedIds;
}
bool LedString::hasBlackListedLeds()
{
if (_blacklistedLedIds.size() > 0)
{
return true;
}
else
{
return false;
}
}
/**
* 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
* @param ledsUsed The maximum number of LEDs used from the configuration
* @return The constructed ledstring
*/
LedString LedString::createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder, int maxLeds)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);
int configuredLeds = static_cast<int>(ledConfigArray.size());
int ledsUsed = configuredLeds;
if (ledsUsed > maxLeds)
{
ledsUsed = maxLeds;
Warning(Logger::getInstance("HYPERION"),"More LEDs configured [%d] via the layout than supported by the device [%d]. Using first [%d] layout entries", configuredLeds, maxLeds, ledsUsed);
}
for (signed i = 0; i < ledsUsed; ++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.blacklistedLedIds().push_back(i);
}
ledString.leds().push_back(led);
}
return ledString;
}