Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 2a77b55

Browse files
committed
Updated the way colororder is configured per led
1 parent 91881cd commit 2a77b55

File tree

4 files changed

+70
-19
lines changed

4 files changed

+70
-19
lines changed

include/hyperion/Hyperion.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ public slots:
153153

154154
public:
155155
static ColorOrder createColorOrder(const Json::Value & deviceConfig);
156-
static LedString createLedString(const Json::Value & ledsConfig);
156+
/**
157+
* Construct the 'led-string' with the integration area definition per led and the color
158+
* ordering of the RGB channels
159+
* @param ledsConfig The configuration of the led areas
160+
* @param deviceOrder The default RGB channel ordering
161+
* @return The constructed ledstring
162+
*/
163+
static LedString createLedString(const Json::Value & ledsConfig, const ColorOrder deviceOrder);
157164

158165
static MultiColorTransform * createLedColorsTransform(const unsigned ledCnt, const Json::Value & colorTransformConfig);
159166
static ColorTransform * createColorTransform(const Json::Value & transformConfig);
@@ -188,9 +195,6 @@ private slots:
188195
/// The transformation from raw colors to led colors
189196
MultiColorTransform * _raw2ledTransform;
190197

191-
/// Value with the desired color byte order
192-
ColorOrder _colorOrder;
193-
194198
/// The actual LedDevice
195199
LedDevice * _device;
196200

include/hyperion/LedString.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,60 @@ namespace Json { class Value; }
1515
/// Enumeration containing the possible orders of device color byte data
1616
enum ColorOrder
1717
{
18-
ORDER_RGB, ORDER_RBG, ORDER_GRB, ORDER_BRG, ORDER_GBR, ORDER_BGR, ORDER_DEFAULT
18+
ORDER_RGB, ORDER_RBG, ORDER_GRB, ORDER_BRG, ORDER_GBR, ORDER_BGR
1919
};
2020

21+
inline std::string colorOrderToString(const ColorOrder colorOrder)
22+
{
23+
switch (colorOrder)
24+
{
25+
case ORDER_RGB:
26+
return "rgb";
27+
case ORDER_RBG:
28+
return "rbg";
29+
case ORDER_GRB:
30+
return "grb";
31+
case ORDER_BRG:
32+
return "brg";
33+
case ORDER_GBR:
34+
return "gbr";
35+
case ORDER_BGR:
36+
return "bgr";
37+
default:
38+
return "not-a-colororder";
39+
}
40+
}
41+
inline ColorOrder stringToColorOrder(const std::string & order)
42+
{
43+
if (order == "rgb")
44+
{
45+
return ORDER_RGB;
46+
}
47+
else if (order == "bgr")
48+
{
49+
return ORDER_BGR;
50+
}
51+
else if (order == "rbg")
52+
{
53+
return ORDER_RBG;
54+
}
55+
else if (order == "brg")
56+
{
57+
return ORDER_BRG;
58+
}
59+
else if (order == "gbr")
60+
{
61+
return ORDER_GBR;
62+
}
63+
else if (order == "grb")
64+
{
65+
return ORDER_GRB;
66+
}
67+
68+
std::cout << "Unknown color order defined (" << order << "). Using RGB." << std::endl;
69+
return ORDER_RGB;
70+
}
71+
2172
///
2273
/// The Led structure contains the definition of the image portion used to determine a single led's
2374
/// color.

libsrc/hyperion/Hyperion.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,22 @@ RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colo
187187
return transform;
188188
}
189189

190-
LedString Hyperion::createLedString(const Json::Value& ledsConfig)
190+
LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOrder deviceOrder)
191191
{
192192
LedString ledString;
193193

194+
const std::string deviceOrderStr = colorOrderToString(deviceOrder);
194195
for (const Json::Value& ledConfig : ledsConfig)
195196
{
196197
Led led;
197198
led.index = ledConfig["index"].asInt();
199+
198200
const Json::Value& hscanConfig = ledConfig["hscan"];
199201
const Json::Value& vscanConfig = ledConfig["vscan"];
200202
led.minX_frac = std::max(0.0, std::min(1.0, hscanConfig["minimum"].asDouble()));
201203
led.maxX_frac = std::max(0.0, std::min(1.0, hscanConfig["maximum"].asDouble()));
202204
led.minY_frac = std::max(0.0, std::min(1.0, vscanConfig["minimum"].asDouble()));
203205
led.maxY_frac = std::max(0.0, std::min(1.0, vscanConfig["maximum"].asDouble()));
204-
if (ledConfig.get("colorOrder", false).asBool()) {
205-
led.colorOrder = createColorOrder(ledConfig);
206-
} else {
207-
led.colorOrder = ORDER_DEFAULT;
208-
}
209-
210206

211207
// Fix if the user swapped min and max
212208
if (led.minX_frac > led.maxX_frac)
@@ -218,6 +214,10 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
218214
std::swap(led.minY_frac, led.maxY_frac);
219215
}
220216

217+
// Get the order of the rgb channels for this led (default is device order)
218+
const std::string ledOrderStr = ledConfig.get("colorOrder", deviceOrderStr).asString();
219+
led.colorOrder = stringToColorOrder(ledOrderStr);
220+
221221
ledString.leds().push_back(led);
222222
}
223223

@@ -268,10 +268,9 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
268268

269269

270270
Hyperion::Hyperion(const Json::Value &jsonConfig) :
271-
_ledString(createLedString(jsonConfig["leds"])),
271+
_ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))),
272272
_muxer(_ledString.leds().size()),
273273
_raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])),
274-
_colorOrder(createColorOrder(jsonConfig["device"])),
275274
_device(LedDeviceFactory::construct(jsonConfig["device"])),
276275
_effectEngine(nullptr),
277276
_timer()
@@ -439,10 +438,7 @@ void Hyperion::update()
439438
int i = 0;
440439
for (ColorRgb& color : ledColors)
441440
{
442-
ColorOrder ledColorOrder = leds.at(i).colorOrder;
443-
if(ledColorOrder == ORDER_DEFAULT) {
444-
ledColorOrder = _colorOrder;
445-
}
441+
const ColorOrder ledColorOrder = leds.at(i).colorOrder;
446442
// correct the color byte order
447443
switch (ledColorOrder)
448444
{

test/TestImage2LedsMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
return -1;
2424
}
2525

26-
const LedString ledString = Hyperion::createLedString(config["leds"]);
26+
const LedString ledString = Hyperion::createLedString(config["leds"], Hyperion::createColorOrder(config["device"]));
2727

2828
const ColorRgb testColor = {64, 123, 12};
2929

0 commit comments

Comments
 (0)