mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added the option to specify the color byte order
Former-commit-id: f911d0f26c25345bbe5e9014fbc31568b7386f08
This commit is contained in:
parent
8d8c4bdfad
commit
fc1e4bc6c8
@ -16,7 +16,7 @@
|
|||||||
"type" : "ws2801",
|
"type" : "ws2801",
|
||||||
"output" : "/dev/spidev0.0",
|
"output" : "/dev/spidev0.0",
|
||||||
"rate" : 1000000,
|
"rate" : 1000000,
|
||||||
"bgr-output" : false
|
"colorOrder" : "rgb"
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:
|
/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:
|
||||||
|
@ -1 +1 @@
|
|||||||
56543287f8f9c84993d0578339da66f81efe6bdb
|
2c2798b7a2ab68721c345158caaba28670dee0ae
|
Binary file not shown.
@ -1 +1 @@
|
|||||||
26d94964cc23d092b4504771bb1c0940e4d6d66e
|
632c368d0a5ce42aff067c6ba5f63dbe108dddc9
|
@ -46,6 +46,12 @@ public:
|
|||||||
SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL
|
SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Enumeration containing the possible orders of device color byte data
|
||||||
|
enum ColorOrder
|
||||||
|
{
|
||||||
|
ORDER_RGB, ORDER_RBG, ORDER_GRB, ORDER_BRG, ORDER_GBR, ORDER_BGR
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Constructs the Hyperion instance based on the given Json configuration
|
/// Constructs the Hyperion instance based on the given Json configuration
|
||||||
///
|
///
|
||||||
@ -136,6 +142,7 @@ public:
|
|||||||
const InputInfo& getPriorityInfo(const int priority) const;
|
const InputInfo& getPriorityInfo(const int priority) const;
|
||||||
|
|
||||||
static LedDevice * createDevice(const Json::Value & deviceConfig);
|
static LedDevice * createDevice(const Json::Value & deviceConfig);
|
||||||
|
static ColorOrder createColorOrder(const Json::Value & deviceConfig);
|
||||||
static LedString createLedString(const Json::Value & ledsConfig);
|
static LedString createLedString(const Json::Value & ledsConfig);
|
||||||
static HsvTransform * createHsvTransform(const Json::Value & hsvConfig);
|
static HsvTransform * createHsvTransform(const Json::Value & hsvConfig);
|
||||||
static ColorTransform * createColorTransform(const Json::Value & colorConfig);
|
static ColorTransform * createColorTransform(const Json::Value & colorConfig);
|
||||||
@ -172,8 +179,8 @@ private:
|
|||||||
/// The BLUE-Channel (RGB) transform
|
/// The BLUE-Channel (RGB) transform
|
||||||
ColorTransform * _blueTransform;
|
ColorTransform * _blueTransform;
|
||||||
|
|
||||||
/// Flag indicating if the output should be BGR (red and blue reversed)
|
/// Value with the desired color byte order
|
||||||
bool _haveBgrOutput;
|
ColorOrder _colorOrder;
|
||||||
|
|
||||||
/// The actual LedDevice
|
/// The actual LedDevice
|
||||||
LedDevice * _device;
|
LedDevice * _device;
|
||||||
|
@ -60,6 +60,47 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Hyperion::ColorOrder Hyperion::createColorOrder(const Json::Value &deviceConfig)
|
||||||
|
{
|
||||||
|
// deprecated: force BGR when the deprecated flag is present and set to true
|
||||||
|
if (deviceConfig.get("bgr-output", false).asBool())
|
||||||
|
{
|
||||||
|
return ORDER_BGR;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string order = deviceConfig.get("colorOrder", "rgb").asString();
|
||||||
|
if (order == "rgb")
|
||||||
|
{
|
||||||
|
return ORDER_RGB;
|
||||||
|
}
|
||||||
|
else if (order == "bgr")
|
||||||
|
{
|
||||||
|
return ORDER_BGR;
|
||||||
|
}
|
||||||
|
else if (order == "rbg")
|
||||||
|
{
|
||||||
|
return ORDER_RBG;
|
||||||
|
}
|
||||||
|
else if (order == "brg")
|
||||||
|
{
|
||||||
|
return ORDER_BRG;
|
||||||
|
}
|
||||||
|
else if (order == "gbr")
|
||||||
|
{
|
||||||
|
return ORDER_GBR;
|
||||||
|
}
|
||||||
|
else if (order == "grb")
|
||||||
|
{
|
||||||
|
return ORDER_GRB;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Unknown color order defined (" << order << "). Using RGB." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ORDER_RGB;
|
||||||
|
}
|
||||||
|
|
||||||
HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig)
|
HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig)
|
||||||
{
|
{
|
||||||
const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble();
|
const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble();
|
||||||
@ -143,6 +184,7 @@ LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig,
|
|||||||
return ledDevice;
|
return ledDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
||||||
_ledString(createLedString(jsonConfig["leds"])),
|
_ledString(createLedString(jsonConfig["leds"])),
|
||||||
_muxer(_ledString.leds().size()),
|
_muxer(_ledString.leds().size()),
|
||||||
@ -150,7 +192,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
|||||||
_redTransform(createColorTransform(jsonConfig["color"]["red"])),
|
_redTransform(createColorTransform(jsonConfig["color"]["red"])),
|
||||||
_greenTransform(createColorTransform(jsonConfig["color"]["green"])),
|
_greenTransform(createColorTransform(jsonConfig["color"]["green"])),
|
||||||
_blueTransform(createColorTransform(jsonConfig["color"]["blue"])),
|
_blueTransform(createColorTransform(jsonConfig["color"]["blue"])),
|
||||||
_haveBgrOutput(jsonConfig["device"].get("bgr-output", false).asBool()),
|
_colorOrder(createColorOrder(jsonConfig["device"])),
|
||||||
_device(createDevice(jsonConfig["device"])),
|
_device(createDevice(jsonConfig["device"])),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
@ -366,9 +408,37 @@ void Hyperion::update()
|
|||||||
color.green = _greenTransform->transform(color.green);
|
color.green = _greenTransform->transform(color.green);
|
||||||
color.blue = _blueTransform->transform(color.blue);
|
color.blue = _blueTransform->transform(color.blue);
|
||||||
|
|
||||||
if (_haveBgrOutput)
|
// correct the color byte order
|
||||||
|
switch (_colorOrder)
|
||||||
{
|
{
|
||||||
|
case ORDER_RGB:
|
||||||
|
// leave as it is
|
||||||
|
break;
|
||||||
|
case ORDER_BGR:
|
||||||
std::swap(color.red, color.blue);
|
std::swap(color.red, color.blue);
|
||||||
|
break;
|
||||||
|
case ORDER_RBG:
|
||||||
|
std::swap(color.green, color.blue);
|
||||||
|
break;
|
||||||
|
case ORDER_GRB:
|
||||||
|
std::swap(color.red, color.green);
|
||||||
|
break;
|
||||||
|
case ORDER_GBR:
|
||||||
|
{
|
||||||
|
uint8_t temp = color.red;
|
||||||
|
color.red = color.green;
|
||||||
|
color.green = color.blue;
|
||||||
|
color.blue = temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ORDER_BRG:
|
||||||
|
{
|
||||||
|
uint8_t temp = color.red;
|
||||||
|
color.red = color.blue;
|
||||||
|
color.blue = color.green;
|
||||||
|
color.green = temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,11 @@
|
|||||||
"required" : true,
|
"required" : true,
|
||||||
"minimum" : 0
|
"minimum" : 0
|
||||||
},
|
},
|
||||||
"bgr-output" : {
|
"colorOrder" : {
|
||||||
|
"type" : "string",
|
||||||
|
"required" : false
|
||||||
|
},
|
||||||
|
"bgr-output" : { // deprecated
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
"required" : false
|
"required" : false
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.hyperion.hypercon.spec;
|
||||||
|
|
||||||
|
public enum ColorByteOrder {
|
||||||
|
RGB, RBG, BRG, BGR, GRB, GBR
|
||||||
|
}
|
@ -15,8 +15,8 @@ public class DeviceConfig extends Observable {
|
|||||||
public String mOutput = "/dev/spidev0.0";
|
public String mOutput = "/dev/spidev0.0";
|
||||||
/** The baudrate of the device */
|
/** The baudrate of the device */
|
||||||
public int mBaudrate = 1000000;
|
public int mBaudrate = 1000000;
|
||||||
/** Flag indicating if the red and blue should be reversed */
|
/** The order of the color bytes */
|
||||||
public boolean mBgrOutput = false;
|
public ColorByteOrder mColorByteOrder = ColorByteOrder.RGB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the JSON string of the configuration as used in the Hyperion daemon configfile
|
* Creates the JSON string of the configuration as used in the Hyperion daemon configfile
|
||||||
@ -33,7 +33,7 @@ public class DeviceConfig extends Observable {
|
|||||||
strBuf.append("\t/// - 'ws2801' this is the device (eg '/dev/spidev0.0')\n");
|
strBuf.append("\t/// - 'ws2801' this is the device (eg '/dev/spidev0.0')\n");
|
||||||
strBuf.append("\t/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')\n");
|
strBuf.append("\t/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')\n");
|
||||||
strBuf.append("\t/// * 'rate' : The baudrate of the output to the device (only applicable for 'ws2801')\n");
|
strBuf.append("\t/// * 'rate' : The baudrate of the output to the device (only applicable for 'ws2801')\n");
|
||||||
strBuf.append("\t/// * 'bgr-output' : Use BGR output instead of RGB (reverse red and blue).\n");
|
strBuf.append("\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n");
|
||||||
|
|
||||||
strBuf.append("\t\"device\" :\n");
|
strBuf.append("\t\"device\" :\n");
|
||||||
strBuf.append("\t{\n");
|
strBuf.append("\t{\n");
|
||||||
@ -42,7 +42,7 @@ public class DeviceConfig extends Observable {
|
|||||||
strBuf.append("\t\t\"type\" : \"").append(mType.name()).append("\",\n");
|
strBuf.append("\t\t\"type\" : \"").append(mType.name()).append("\",\n");
|
||||||
strBuf.append("\t\t\"output\" : \"").append(mOutput).append("\",\n");
|
strBuf.append("\t\t\"output\" : \"").append(mOutput).append("\",\n");
|
||||||
strBuf.append("\t\t\"rate\" : ").append(mBaudrate).append(",\n");
|
strBuf.append("\t\t\"rate\" : ").append(mBaudrate).append(",\n");
|
||||||
strBuf.append("\t\t\"bgr-output\" : ").append(mBgrOutput).append("\n");
|
strBuf.append("\t\t\"colorOrder\" : ").append(mColorByteOrder.name().toLowerCase()).append("\n");
|
||||||
|
|
||||||
strBuf.append("\t}");
|
strBuf.append("\t}");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user