2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
2016-06-17 01:25:40 +02:00
|
|
|
#include <exception>
|
2013-11-11 10:00:37 +01:00
|
|
|
|
2013-08-21 16:25:27 +02:00
|
|
|
// QT includes
|
2013-08-14 17:02:09 +02:00
|
|
|
#include <QDateTime>
|
2013-11-29 23:22:49 +01:00
|
|
|
#include <QThread>
|
2013-11-22 11:48:10 +01:00
|
|
|
#include <QRegExp>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2013-08-14 17:02:09 +02:00
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
// JsonSchema include
|
|
|
|
#include <utils/jsonschema/JsonFactory.h>
|
|
|
|
|
|
|
|
// hyperion include
|
|
|
|
#include <hyperion/Hyperion.h>
|
2013-08-15 21:11:02 +02:00
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
2015-12-22 10:01:47 +01:00
|
|
|
#include <hyperion/ColorTransform.h>
|
|
|
|
#include <hyperion/ColorCorrection.h>
|
2016-04-02 00:04:11 +02:00
|
|
|
#include <hyperion/ColorAdjustment.h>
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
#include <leddevice/LedDeviceFactory.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-11-20 09:25:49 +01:00
|
|
|
#include "MultiColorTransform.h"
|
2015-12-22 10:01:47 +01:00
|
|
|
#include "MultiColorCorrection.h"
|
2016-04-02 00:04:11 +02:00
|
|
|
#include "MultiColorAdjustment.h"
|
2013-10-27 18:04:37 +01:00
|
|
|
#include "LinearColorSmoothing.h"
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// effect engine includes
|
|
|
|
#include <effectengine/EffectEngine.h>
|
|
|
|
|
2016-06-17 01:25:40 +02:00
|
|
|
Hyperion* Hyperion::_hyperion = nullptr;
|
|
|
|
|
|
|
|
Hyperion* Hyperion::initInstance(const Json::Value& jsonConfig, const std::string configFile)
|
|
|
|
{
|
|
|
|
if ( Hyperion::_hyperion != nullptr )
|
|
|
|
throw std::runtime_error("Hyperion::initInstance can be called only one time");
|
|
|
|
Hyperion::_hyperion = new Hyperion(jsonConfig,configFile);
|
|
|
|
|
|
|
|
return Hyperion::_hyperion;
|
|
|
|
}
|
|
|
|
|
|
|
|
Hyperion* Hyperion::getInstance()
|
|
|
|
{
|
|
|
|
if ( Hyperion::_hyperion == nullptr )
|
|
|
|
throw std::runtime_error("Hyperion::getInstance used without call of Hyperion::initInstance before");
|
|
|
|
|
|
|
|
return Hyperion::_hyperion;
|
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2015-01-01 19:31:04 +01:00
|
|
|
ColorOrder Hyperion::createColorOrder(const Json::Value &deviceConfig)
|
2013-11-04 20:52:57 +01:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION ERROR: Unknown color order defined (" << order << "). Using RGB." << std::endl;
|
2013-11-04 20:52:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ORDER_RGB;
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
ColorTransform * Hyperion::createColorTransform(const Json::Value & transformConfig)
|
2013-11-20 09:25:49 +01:00
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const std::string id = transformConfig.get("id", "default").asString();
|
|
|
|
|
|
|
|
RgbChannelTransform * redTransform = createRgbChannelTransform(transformConfig["red"]);
|
|
|
|
RgbChannelTransform * greenTransform = createRgbChannelTransform(transformConfig["green"]);
|
|
|
|
RgbChannelTransform * blueTransform = createRgbChannelTransform(transformConfig["blue"]);
|
|
|
|
|
|
|
|
HsvTransform * hsvTransform = createHsvTransform(transformConfig["hsv"]);
|
2015-12-22 10:01:47 +01:00
|
|
|
HslTransform * hslTransform = createHslTransform(transformConfig["hsl"]);
|
2013-11-20 09:25:49 +01:00
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
ColorTransform * transform = new ColorTransform();
|
|
|
|
transform->_id = id;
|
|
|
|
transform->_rgbRedTransform = *redTransform;
|
|
|
|
transform->_rgbGreenTransform = *greenTransform;
|
|
|
|
transform->_rgbBlueTransform = *blueTransform;
|
|
|
|
transform->_hsvTransform = *hsvTransform;
|
2015-12-22 10:01:47 +01:00
|
|
|
transform->_hslTransform = *hslTransform;
|
|
|
|
|
2013-11-20 09:25:49 +01:00
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
// Cleanup the allocated individual transforms
|
|
|
|
delete redTransform;
|
|
|
|
delete greenTransform;
|
|
|
|
delete blueTransform;
|
|
|
|
delete hsvTransform;
|
2015-12-22 10:01:47 +01:00
|
|
|
delete hslTransform;
|
2013-11-20 09:25:49 +01:00
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
ColorCorrection * Hyperion::createColorCorrection(const Json::Value & correctionConfig)
|
|
|
|
{
|
|
|
|
const std::string id = correctionConfig.get("id", "default").asString();
|
|
|
|
|
|
|
|
RgbChannelCorrection * rgbCorrection = createRgbChannelCorrection(correctionConfig["correctionValues"]);
|
|
|
|
|
|
|
|
ColorCorrection * correction = new ColorCorrection();
|
|
|
|
correction->_id = id;
|
|
|
|
correction->_rgbCorrection = *rgbCorrection;
|
|
|
|
|
|
|
|
// Cleanup the allocated individual transforms
|
|
|
|
delete rgbCorrection;
|
|
|
|
|
|
|
|
return correction;
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
|
|
|
|
ColorAdjustment * Hyperion::createColorAdjustment(const Json::Value & adjustmentConfig)
|
|
|
|
{
|
|
|
|
const std::string id = adjustmentConfig.get("id", "default").asString();
|
|
|
|
|
|
|
|
RgbChannelAdjustment * redAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureRed"],RED);
|
|
|
|
RgbChannelAdjustment * greenAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureGreen"],GREEN);
|
|
|
|
RgbChannelAdjustment * blueAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureBlue"],BLUE);
|
|
|
|
|
|
|
|
ColorAdjustment * adjustment = new ColorAdjustment();
|
|
|
|
adjustment->_id = id;
|
|
|
|
adjustment->_rgbRedAdjustment = *redAdjustment;
|
|
|
|
adjustment->_rgbGreenAdjustment = *greenAdjustment;
|
|
|
|
adjustment->_rgbBlueAdjustment = *blueAdjustment;
|
|
|
|
|
|
|
|
// Cleanup the allocated individual adjustments
|
|
|
|
delete redAdjustment;
|
|
|
|
delete greenAdjustment;
|
|
|
|
delete blueAdjustment;
|
|
|
|
|
|
|
|
return adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, const Json::Value & colorConfig)
|
|
|
|
{
|
|
|
|
// Create the result, the transforms are added to this
|
|
|
|
MultiColorTransform * transform = new MultiColorTransform(ledCnt);
|
|
|
|
|
|
|
|
const Json::Value transformConfig = colorConfig.get("transform", Json::nullValue);
|
|
|
|
if (transformConfig.isNull())
|
|
|
|
{
|
|
|
|
// Old style color transformation config (just one for all leds)
|
|
|
|
ColorTransform * colorTransform = createColorTransform(colorConfig);
|
|
|
|
transform->addTransform(colorTransform);
|
|
|
|
transform->setTransformForLed(colorTransform->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else if (!transformConfig.isArray())
|
|
|
|
{
|
|
|
|
ColorTransform * colorTransform = createColorTransform(transformConfig);
|
|
|
|
transform->addTransform(colorTransform);
|
|
|
|
transform->setTransformForLed(colorTransform->_id, 0, ledCnt-1);
|
2013-11-20 09:25:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
2013-11-20 09:25:49 +01:00
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
for (Json::UInt i = 0; i < transformConfig.size(); ++i)
|
|
|
|
{
|
|
|
|
const Json::Value & config = transformConfig[i];
|
|
|
|
ColorTransform * colorTransform = createColorTransform(config);
|
|
|
|
transform->addTransform(colorTransform);
|
|
|
|
|
2013-12-13 22:58:09 +01:00
|
|
|
const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed();
|
|
|
|
if (ledIndicesStr.compare("*") == 0)
|
|
|
|
{
|
|
|
|
// Special case for indices '*' => all leds
|
|
|
|
transform->setTransformForLed(colorTransform->_id, 0, ledCnt-1);
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorTransform '" << colorTransform->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl;
|
2013-12-13 22:58:09 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
if (!overallExp.exactMatch(ledIndicesStr))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cerr << "HYPERION ERROR: Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl;
|
2013-11-22 11:48:10 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorTransform '" << colorTransform->_id << "' => [";
|
2013-11-22 11:48:10 +01:00
|
|
|
|
|
|
|
const QStringList ledIndexList = ledIndicesStr.split(",");
|
|
|
|
for (int i=0; i<ledIndexList.size(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
std::cout << ", ";
|
|
|
|
}
|
|
|
|
if (ledIndexList[i].contains("-"))
|
|
|
|
{
|
|
|
|
QStringList ledIndices = ledIndexList[i].split("-");
|
|
|
|
int startInd = ledIndices[0].toInt();
|
|
|
|
int endInd = ledIndices[1].toInt();
|
|
|
|
|
|
|
|
transform->setTransformForLed(colorTransform->_id, startInd, endInd);
|
|
|
|
std::cout << startInd << "-" << endInd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int index = ledIndexList[i].toInt();
|
|
|
|
transform->setTransformForLed(colorTransform->_id, index, index);
|
|
|
|
std::cout << index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "]" << std::endl;
|
|
|
|
}
|
2013-11-20 09:25:49 +01:00
|
|
|
}
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
MultiColorCorrection * Hyperion::createLedColorsCorrection(const unsigned ledCnt, const Json::Value & colorConfig)
|
|
|
|
{
|
|
|
|
// Create the result, the corrections are added to this
|
|
|
|
MultiColorCorrection * correction = new MultiColorCorrection(ledCnt);
|
|
|
|
|
|
|
|
const Json::Value correctionConfig = colorConfig.get("correction", Json::nullValue);
|
|
|
|
if (correctionConfig.isNull())
|
|
|
|
{
|
|
|
|
// Old style color correction config (just one for all leds)
|
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(colorConfig);
|
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else if (!correctionConfig.isArray())
|
|
|
|
{
|
2016-04-02 00:04:11 +02:00
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(correctionConfig);
|
2015-12-22 10:01:47 +01:00
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
|
|
|
|
|
|
|
for (Json::UInt i = 0; i < correctionConfig.size(); ++i)
|
|
|
|
{
|
|
|
|
const Json::Value & config = correctionConfig[i];
|
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(config);
|
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
|
|
|
|
const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed();
|
|
|
|
if (ledIndicesStr.compare("*") == 0)
|
|
|
|
{
|
|
|
|
// Special case for indices '*' => all leds
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorCorrection '" << colorCorrection->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl;
|
2015-12-22 10:01:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overallExp.exactMatch(ledIndicesStr))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cerr << "HYPERION ERROR: Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl;
|
2015-12-22 10:01:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorCorrection '" << colorCorrection->_id << "' => [";
|
2015-12-22 10:01:47 +01:00
|
|
|
|
|
|
|
const QStringList ledIndexList = ledIndicesStr.split(",");
|
|
|
|
for (int i=0; i<ledIndexList.size(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
std::cout << ", ";
|
|
|
|
}
|
|
|
|
if (ledIndexList[i].contains("-"))
|
|
|
|
{
|
|
|
|
QStringList ledIndices = ledIndexList[i].split("-");
|
|
|
|
int startInd = ledIndices[0].toInt();
|
|
|
|
int endInd = ledIndices[1].toInt();
|
|
|
|
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, startInd, endInd);
|
|
|
|
std::cout << startInd << "-" << endInd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int index = ledIndexList[i].toInt();
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, index, index);
|
|
|
|
std::cout << index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "]" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return correction;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiColorCorrection * Hyperion::createLedColorsTemperature(const unsigned ledCnt, const Json::Value & colorConfig)
|
|
|
|
{
|
|
|
|
// Create the result, the corrections are added to this
|
|
|
|
MultiColorCorrection * correction = new MultiColorCorrection(ledCnt);
|
|
|
|
|
|
|
|
const Json::Value correctionConfig = colorConfig.get("temperature", Json::nullValue);
|
|
|
|
if (correctionConfig.isNull())
|
|
|
|
{
|
|
|
|
// Old style color correction config (just one for all leds)
|
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(colorConfig);
|
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else if (!correctionConfig.isArray())
|
|
|
|
{
|
2016-04-02 00:04:11 +02:00
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(correctionConfig);
|
2015-12-22 10:01:47 +01:00
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
|
|
|
|
|
|
|
for (Json::UInt i = 0; i < correctionConfig.size(); ++i)
|
|
|
|
{
|
|
|
|
const Json::Value & config = correctionConfig[i];
|
|
|
|
ColorCorrection * colorCorrection = createColorCorrection(config);
|
|
|
|
correction->addCorrection(colorCorrection);
|
|
|
|
|
|
|
|
const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed();
|
|
|
|
if (ledIndicesStr.compare("*") == 0)
|
|
|
|
{
|
|
|
|
// Special case for indices '*' => all leds
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorCorrection '" << colorCorrection->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl;
|
2015-12-22 10:01:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overallExp.exactMatch(ledIndicesStr))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cerr << "HYPERION ERROR: Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl;
|
2015-12-22 10:01:47 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: ColorCorrection '" << colorCorrection->_id << "' => [";
|
2015-12-22 10:01:47 +01:00
|
|
|
|
|
|
|
const QStringList ledIndexList = ledIndicesStr.split(",");
|
|
|
|
for (int i=0; i<ledIndexList.size(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
std::cout << ", ";
|
|
|
|
}
|
|
|
|
if (ledIndexList[i].contains("-"))
|
|
|
|
{
|
|
|
|
QStringList ledIndices = ledIndexList[i].split("-");
|
|
|
|
int startInd = ledIndices[0].toInt();
|
|
|
|
int endInd = ledIndices[1].toInt();
|
|
|
|
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, startInd, endInd);
|
|
|
|
std::cout << startInd << "-" << endInd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int index = ledIndexList[i].toInt();
|
|
|
|
correction->setCorrectionForLed(colorCorrection->_id, index, index);
|
|
|
|
std::cout << index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "]" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return correction;
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt, const Json::Value & colorConfig)
|
|
|
|
{
|
|
|
|
// Create the result, the transforms are added to this
|
|
|
|
MultiColorAdjustment * adjustment = new MultiColorAdjustment(ledCnt);
|
|
|
|
|
|
|
|
const Json::Value adjustmentConfig = colorConfig.get("channelAdjustment", Json::nullValue);
|
|
|
|
if (adjustmentConfig.isNull())
|
|
|
|
{
|
|
|
|
// Old style color transformation config (just one for all leds)
|
|
|
|
ColorAdjustment * colorAdjustment = createColorAdjustment(colorConfig);
|
|
|
|
adjustment->addAdjustment(colorAdjustment);
|
|
|
|
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else if (!adjustmentConfig.isArray())
|
|
|
|
{
|
|
|
|
ColorAdjustment * colorAdjustment = createColorAdjustment(adjustmentConfig);
|
|
|
|
adjustment->addAdjustment(colorAdjustment);
|
|
|
|
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
|
|
|
|
|
|
|
for (Json::UInt i = 0; i < adjustmentConfig.size(); ++i)
|
|
|
|
{
|
|
|
|
const Json::Value & config = adjustmentConfig[i];
|
|
|
|
ColorAdjustment * colorAdjustment = createColorAdjustment(config);
|
|
|
|
adjustment->addAdjustment(colorAdjustment);
|
|
|
|
|
|
|
|
const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed();
|
|
|
|
if (ledIndicesStr.compare("*") == 0)
|
|
|
|
{
|
|
|
|
// Special case for indices '*' => all leds
|
|
|
|
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
|
|
|
std::cout << "HYPERION INFO: ColorAdjustment '" << colorAdjustment->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overallExp.exactMatch(ledIndicesStr))
|
|
|
|
{
|
|
|
|
std::cerr << "HYPERION ERROR: Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "HYPERION INFO: ColorAdjustment '" << colorAdjustment->_id << "' => [";
|
|
|
|
|
|
|
|
const QStringList ledIndexList = ledIndicesStr.split(",");
|
|
|
|
for (int i=0; i<ledIndexList.size(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
std::cout << ", ";
|
|
|
|
}
|
|
|
|
if (ledIndexList[i].contains("-"))
|
|
|
|
{
|
|
|
|
QStringList ledIndices = ledIndexList[i].split("-");
|
|
|
|
int startInd = ledIndices[0].toInt();
|
|
|
|
int endInd = ledIndices[1].toInt();
|
|
|
|
|
|
|
|
adjustment->setAdjustmentForLed(colorAdjustment->_id, startInd, endInd);
|
|
|
|
std::cout << startInd << "-" << endInd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int index = ledIndexList[i].toInt();
|
|
|
|
adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index);
|
|
|
|
std::cout << index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "]" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return adjustment;
|
|
|
|
}
|
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig)
|
2013-08-21 21:50:17 +02:00
|
|
|
{
|
2013-10-17 09:44:42 +02:00
|
|
|
const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble();
|
|
|
|
const double valueGain = hsvConfig.get("valueGain", 1.0).asDouble();
|
|
|
|
|
|
|
|
return new HsvTransform(saturationGain, valueGain);
|
2013-08-21 21:50:17 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
HslTransform * Hyperion::createHslTransform(const Json::Value & hslConfig)
|
|
|
|
{
|
|
|
|
const double saturationGain = hslConfig.get("saturationGain", 1.0).asDouble();
|
|
|
|
const double luminanceGain = hslConfig.get("luminanceGain", 1.0).asDouble();
|
2016-05-23 00:00:48 +02:00
|
|
|
const double luminanceMinimum = hslConfig.get("luminanceMinimum", 0.0).asDouble();
|
2015-12-22 10:01:47 +01:00
|
|
|
|
2016-05-23 00:00:48 +02:00
|
|
|
return new HslTransform(saturationGain, luminanceGain, luminanceMinimum);
|
2015-12-22 10:01:47 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
RgbChannelTransform* Hyperion::createRgbChannelTransform(const Json::Value& colorConfig)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2013-10-17 09:44:42 +02:00
|
|
|
const double threshold = colorConfig.get("threshold", 0.0).asDouble();
|
|
|
|
const double gamma = colorConfig.get("gamma", 1.0).asDouble();
|
|
|
|
const double blacklevel = colorConfig.get("blacklevel", 0.0).asDouble();
|
|
|
|
const double whitelevel = colorConfig.get("whitelevel", 1.0).asDouble();
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-11-19 21:17:59 +01:00
|
|
|
RgbChannelTransform* transform = new RgbChannelTransform(threshold, gamma, blacklevel, whitelevel);
|
2013-08-13 11:10:45 +02:00
|
|
|
return transform;
|
|
|
|
}
|
2013-10-27 18:04:37 +01:00
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
RgbChannelCorrection* Hyperion::createRgbChannelCorrection(const Json::Value& colorConfig)
|
|
|
|
{
|
|
|
|
const int varR = colorConfig.get("red", 255).asInt();
|
|
|
|
const int varG = colorConfig.get("green", 255).asInt();
|
|
|
|
const int varB = colorConfig.get("blue", 255).asInt();
|
|
|
|
|
|
|
|
RgbChannelCorrection* correction = new RgbChannelCorrection(varR, varG, varB);
|
|
|
|
return correction;
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
RgbChannelAdjustment* Hyperion::createRgbChannelAdjustment(const Json::Value& colorConfig, const RgbChannel color)
|
|
|
|
{
|
2016-05-26 07:01:10 +02:00
|
|
|
int varR=0, varG=0, varB=0;
|
2016-04-02 00:04:11 +02:00
|
|
|
if (color == RED)
|
|
|
|
{
|
|
|
|
varR = colorConfig.get("redChannel", 255).asInt();
|
|
|
|
varG = colorConfig.get("greenChannel", 0).asInt();
|
|
|
|
varB = colorConfig.get("blueChannel", 0).asInt();
|
|
|
|
}
|
|
|
|
else if (color == GREEN)
|
|
|
|
{
|
|
|
|
varR = colorConfig.get("redChannel", 0).asInt();
|
|
|
|
varG = colorConfig.get("greenChannel", 255).asInt();
|
|
|
|
varB = colorConfig.get("blueChannel", 0).asInt();
|
|
|
|
}
|
|
|
|
else if (color == BLUE)
|
|
|
|
{
|
|
|
|
varR = colorConfig.get("redChannel", 0).asInt();
|
|
|
|
varG = colorConfig.get("greenChannel", 0).asInt();
|
|
|
|
varB = colorConfig.get("blueChannel", 255).asInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbChannelAdjustment* adjustment = new RgbChannelAdjustment(varR, varG, varB);
|
|
|
|
return adjustment;
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:11:33 +01:00
|
|
|
LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOrder deviceOrder)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
LedString ledString;
|
|
|
|
|
2015-02-23 16:11:33 +01:00
|
|
|
const std::string deviceOrderStr = colorOrderToString(deviceOrder);
|
2013-08-13 11:10:45 +02:00
|
|
|
for (const Json::Value& ledConfig : ledsConfig)
|
|
|
|
{
|
|
|
|
Led led;
|
|
|
|
led.index = ledConfig["index"].asInt();
|
2015-02-23 16:11:33 +01:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
const Json::Value& hscanConfig = ledConfig["hscan"];
|
|
|
|
const Json::Value& vscanConfig = ledConfig["vscan"];
|
2013-10-16 17:04:38 +02:00
|
|
|
led.minX_frac = std::max(0.0, std::min(1.0, hscanConfig["minimum"].asDouble()));
|
|
|
|
led.maxX_frac = std::max(0.0, std::min(1.0, hscanConfig["maximum"].asDouble()));
|
2013-10-16 22:53:45 +02:00
|
|
|
led.minY_frac = std::max(0.0, std::min(1.0, vscanConfig["minimum"].asDouble()));
|
|
|
|
led.maxY_frac = std::max(0.0, std::min(1.0, vscanConfig["maximum"].asDouble()));
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-10-16 23:19:40 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:11:33 +01:00
|
|
|
// Get the order of the rgb channels for this led (default is device order)
|
|
|
|
const std::string ledOrderStr = ledConfig.get("colorOrder", deviceOrderStr).asString();
|
|
|
|
led.colorOrder = stringToColorOrder(ledOrderStr);
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
ledString.leds().push_back(led);
|
|
|
|
}
|
2013-11-05 16:05:00 +01:00
|
|
|
|
|
|
|
// Make sure the leds are sorted (on their indices)
|
|
|
|
std::sort(ledString.leds().begin(), ledString.leds().end(), [](const Led& lhs, const Led& rhs){ return lhs.index < rhs.index; });
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
return ledString;
|
|
|
|
}
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
|
|
|
|
{
|
2013-10-27 21:06:35 +01:00
|
|
|
std::string type = smoothingConfig.get("type", "none").asString();
|
|
|
|
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
|
|
|
|
|
|
|
if (type == "none")
|
|
|
|
{
|
2016-03-23 18:54:49 +01:00
|
|
|
std::cout << "HYPERION INFO: Not creating any smoothing" << std::endl;
|
2013-10-27 21:06:35 +01:00
|
|
|
return ledDevice;
|
|
|
|
}
|
|
|
|
else if (type == "linear")
|
|
|
|
{
|
|
|
|
if (!smoothingConfig.isMember("time_ms"))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION ERROR: Unable to create smoothing of type linear because of missing parameter 'time_ms'" << std::endl;
|
2013-10-27 21:06:35 +01:00
|
|
|
}
|
|
|
|
else if (!smoothingConfig.isMember("updateFrequency"))
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION ERROR: Unable to create smoothing of type linear because of missing parameter 'updateFrequency'" << std::endl;
|
2013-10-27 21:06:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-22 21:28:38 +02:00
|
|
|
const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt();
|
2016-03-23 18:54:49 +01:00
|
|
|
std::cout << "INFO: Creating linear smoothing" << std::endl;
|
2014-09-22 21:28:38 +02:00
|
|
|
return new LinearColorSmoothing(
|
|
|
|
ledDevice,
|
|
|
|
smoothingConfig["updateFrequency"].asDouble(),
|
|
|
|
smoothingConfig["time_ms"].asInt(),
|
|
|
|
updateDelay);
|
2013-10-27 21:06:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION ERROR: Unable to create smoothing of type " << type << std::endl;
|
2013-10-27 21:06:35 +01:00
|
|
|
}
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
return ledDevice;
|
|
|
|
}
|
|
|
|
|
2016-03-09 19:45:00 +01:00
|
|
|
MessageForwarder * Hyperion::createMessageForwarder(const Json::Value & forwarderConfig)
|
|
|
|
{
|
|
|
|
MessageForwarder * forwarder = new MessageForwarder();
|
|
|
|
if ( ! forwarderConfig.isNull() )
|
|
|
|
{
|
|
|
|
if ( ! forwarderConfig["json"].isNull() && forwarderConfig["json"].isArray() )
|
|
|
|
{
|
|
|
|
for (const Json::Value& addr : forwarderConfig["json"])
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: Json forward to " << addr.asString() << std::endl;
|
2016-03-09 19:45:00 +01:00
|
|
|
forwarder->addJsonSlave(addr.asString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! forwarderConfig["proto"].isNull() && forwarderConfig["proto"].isArray() )
|
|
|
|
{
|
|
|
|
for (const Json::Value& addr : forwarderConfig["proto"])
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
std::cout << "HYPERION INFO: Proto forward to " << addr.asString() << std::endl;
|
2016-03-09 19:45:00 +01:00
|
|
|
forwarder->addProtoSlave(addr.asString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return forwarder;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageForwarder * Hyperion::getForwarder()
|
|
|
|
{
|
|
|
|
return _messageForwarder;
|
|
|
|
}
|
2013-11-04 20:52:57 +01:00
|
|
|
|
2016-06-14 20:14:06 +02:00
|
|
|
Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) :
|
2015-02-23 16:11:33 +01:00
|
|
|
_ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))),
|
2013-08-18 13:33:56 +02:00
|
|
|
_muxer(_ledString.leds().size()),
|
2016-05-26 07:01:10 +02:00
|
|
|
_raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])),
|
2015-12-22 10:01:47 +01:00
|
|
|
_raw2ledCorrection(createLedColorsCorrection(_ledString.leds().size(), jsonConfig["color"])),
|
|
|
|
_raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])),
|
2016-05-26 07:01:10 +02:00
|
|
|
_raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])),
|
2013-12-17 19:50:15 +01:00
|
|
|
_device(LedDeviceFactory::construct(jsonConfig["device"])),
|
2013-11-24 16:10:48 +01:00
|
|
|
_effectEngine(nullptr),
|
2016-03-09 19:57:03 +01:00
|
|
|
_messageForwarder(createMessageForwarder(jsonConfig["forwarder"])),
|
2016-06-14 20:14:06 +02:00
|
|
|
_jsonConfig(jsonConfig),
|
|
|
|
_configFile(configFile),
|
2013-08-14 17:02:09 +02:00
|
|
|
_timer()
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2016-04-02 00:04:11 +02:00
|
|
|
if (!_raw2ledAdjustment->verifyAdjustments())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("HYPERION ERROR: Color adjustment incorrectly set");
|
|
|
|
}
|
2015-12-22 10:01:47 +01:00
|
|
|
if (!_raw2ledCorrection->verifyCorrections())
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error("HYPERION ERROR: Color correction incorrectly set");
|
2015-12-22 10:01:47 +01:00
|
|
|
}
|
2015-12-22 10:06:04 +01:00
|
|
|
if (!_raw2ledTemperature->verifyCorrections())
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error("HYPERION ERROR: Color temperature incorrectly set");
|
2015-12-22 10:06:04 +01:00
|
|
|
}
|
2013-11-22 11:48:10 +01:00
|
|
|
if (!_raw2ledTransform->verifyTransforms())
|
|
|
|
{
|
2016-03-23 17:40:34 +01:00
|
|
|
throw std::runtime_error("HYPERION ERROR: Color transformation incorrectly set");
|
2013-11-22 11:48:10 +01:00
|
|
|
}
|
2013-10-27 18:04:37 +01:00
|
|
|
// initialize the image processor factory
|
2014-01-20 20:46:38 +01:00
|
|
|
ImageProcessorFactory::getInstance().init(
|
|
|
|
_ledString,
|
2016-03-09 19:57:03 +01:00
|
|
|
jsonConfig["blackborderdetector"]
|
|
|
|
);
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
// initialize the color smoothing filter
|
2013-10-27 21:06:35 +01:00
|
|
|
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);
|
2013-10-27 18:04:37 +01:00
|
|
|
|
|
|
|
// setup the timer
|
2013-08-14 17:02:09 +02:00
|
|
|
_timer.setSingleShot(true);
|
|
|
|
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// create the effect engine
|
2013-11-30 12:42:08 +01:00
|
|
|
_effectEngine = new EffectEngine(this, jsonConfig["effects"]);
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
// initialize the leds
|
|
|
|
update();
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Hyperion::~Hyperion()
|
|
|
|
{
|
2013-10-27 18:04:37 +01:00
|
|
|
// switch off all leds
|
|
|
|
clearall();
|
|
|
|
_device->switchOff();
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// delete the effect engine
|
|
|
|
delete _effectEngine;
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
// Delete the Led-String
|
2013-08-18 13:33:56 +02:00
|
|
|
delete _device;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-20 09:25:49 +01:00
|
|
|
// delete the color transform
|
|
|
|
delete _raw2ledTransform;
|
2015-12-22 10:01:47 +01:00
|
|
|
|
|
|
|
// delete the color correction
|
|
|
|
delete _raw2ledCorrection;
|
2015-12-22 10:06:04 +01:00
|
|
|
|
|
|
|
// delete the color temperature correction
|
|
|
|
delete _raw2ledTemperature;
|
2016-04-02 00:04:11 +02:00
|
|
|
|
|
|
|
// delete the color adjustment
|
|
|
|
delete _raw2ledAdjustment;
|
2016-03-09 19:45:00 +01:00
|
|
|
|
|
|
|
// delete the message forwarder
|
|
|
|
delete _messageForwarder;
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 10:54:49 +02:00
|
|
|
unsigned Hyperion::getLedCount() const
|
|
|
|
{
|
2013-08-18 13:33:56 +02:00
|
|
|
return _ledString.leds().size();
|
2013-08-14 10:54:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-08 17:45:26 +01:00
|
|
|
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-18 13:33:56 +02:00
|
|
|
// create led output
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> ledColors(_ledString.leds().size(), color);
|
2013-08-18 13:33:56 +02:00
|
|
|
|
|
|
|
// set colors
|
2013-12-08 17:45:26 +01:00
|
|
|
setColors(priority, ledColors, timeout_ms, clearEffects);
|
2013-08-18 13:33:56 +02:00
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-12-08 17:45:26 +01:00
|
|
|
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms, bool clearEffects)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-12-08 17:45:26 +01:00
|
|
|
// clear effects if this call does not come from an effect
|
|
|
|
if (clearEffects)
|
|
|
|
{
|
|
|
|
_effectEngine->channelCleared(priority);
|
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
if (timeout_ms > 0)
|
|
|
|
{
|
|
|
|
const uint64_t timeoutTime = QDateTime::currentMSecsSinceEpoch() + timeout_ms;
|
2013-08-18 13:33:56 +02:00
|
|
|
_muxer.setInput(priority, ledColors, timeoutTime);
|
2013-08-14 17:02:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-18 13:33:56 +02:00
|
|
|
_muxer.setInput(priority, ledColors);
|
2013-08-14 17:02:09 +02:00
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
if (priority == _muxer.getCurrentPriority())
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-14 17:02:09 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
const std::vector<std::string> & Hyperion::getTransformIds() const
|
2013-08-19 19:57:35 +02:00
|
|
|
{
|
2013-11-22 11:48:10 +01:00
|
|
|
return _raw2ledTransform->getTransformIds();
|
|
|
|
}
|
2013-08-21 21:50:17 +02:00
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
const std::vector<std::string> & Hyperion::getCorrectionIds() const
|
|
|
|
{
|
|
|
|
return _raw2ledCorrection->getCorrectionIds();
|
|
|
|
}
|
|
|
|
|
2015-12-22 10:06:04 +01:00
|
|
|
const std::vector<std::string> & Hyperion::getTemperatureIds() const
|
|
|
|
{
|
|
|
|
return _raw2ledTemperature->getCorrectionIds();
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
const std::vector<std::string> & Hyperion::getAdjustmentIds() const
|
|
|
|
{
|
|
|
|
return _raw2ledAdjustment->getAdjustmentIds();
|
|
|
|
}
|
|
|
|
|
2013-11-22 11:48:10 +01:00
|
|
|
ColorTransform * Hyperion::getTransform(const std::string& id)
|
|
|
|
{
|
|
|
|
return _raw2ledTransform->getTransform(id);
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
ColorCorrection * Hyperion::getCorrection(const std::string& id)
|
|
|
|
{
|
|
|
|
return _raw2ledCorrection->getCorrection(id);
|
|
|
|
}
|
|
|
|
|
2015-12-22 10:06:04 +01:00
|
|
|
ColorCorrection * Hyperion::getTemperature(const std::string& id)
|
|
|
|
{
|
|
|
|
return _raw2ledTemperature->getCorrection(id);
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
ColorAdjustment * Hyperion::getAdjustment(const std::string& id)
|
|
|
|
{
|
|
|
|
return _raw2ledAdjustment->getAdjustment(id);
|
|
|
|
}
|
|
|
|
|
2013-12-03 22:56:46 +01:00
|
|
|
void Hyperion::transformsUpdated()
|
2013-08-19 19:57:35 +02:00
|
|
|
{
|
2013-08-21 21:50:17 +02:00
|
|
|
update();
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
void Hyperion::correctionsUpdated()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:13:46 +01:00
|
|
|
void Hyperion::temperaturesUpdated()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-04-02 00:04:11 +02:00
|
|
|
void Hyperion::adjustmentsUpdated()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
void Hyperion::clear(int priority)
|
|
|
|
{
|
|
|
|
if (_muxer.hasPriority(priority))
|
|
|
|
{
|
|
|
|
_muxer.clearInput(priority);
|
|
|
|
|
|
|
|
// update leds if necessary
|
2013-12-28 08:41:23 +01:00
|
|
|
if (priority < _muxer.getCurrentPriority())
|
2013-08-18 13:33:56 +02:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
2013-11-29 23:22:49 +01:00
|
|
|
|
|
|
|
// send clear signal to the effect engine
|
|
|
|
// (outside the check so the effect gets cleared even when the effect is not sending colors)
|
|
|
|
_effectEngine->channelCleared(priority);
|
2013-08-18 13:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Hyperion::clearall()
|
|
|
|
{
|
|
|
|
_muxer.clearAll();
|
|
|
|
|
|
|
|
// update leds
|
|
|
|
update();
|
2013-11-24 16:10:48 +01:00
|
|
|
|
|
|
|
// send clearall signal to the effect engine
|
|
|
|
_effectEngine->allChannelsCleared();
|
2013-08-18 13:33:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 22:39:12 +02:00
|
|
|
int Hyperion::getCurrentPriority() const
|
|
|
|
{
|
|
|
|
return _muxer.getCurrentPriority();
|
|
|
|
}
|
|
|
|
|
2013-08-19 20:33:36 +02:00
|
|
|
QList<int> Hyperion::getActivePriorities() const
|
|
|
|
{
|
|
|
|
return _muxer.getPriorities();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Hyperion::InputInfo &Hyperion::getPriorityInfo(const int priority) const
|
|
|
|
{
|
|
|
|
return _muxer.getInputInfo(priority);
|
|
|
|
}
|
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
const std::list<EffectDefinition> & Hyperion::getEffects() const
|
2013-11-24 16:10:48 +01:00
|
|
|
{
|
|
|
|
return _effectEngine->getEffects();
|
|
|
|
}
|
|
|
|
|
2016-04-24 17:07:31 +02:00
|
|
|
const std::list<ActiveEffectDefinition> & Hyperion::getActiveEffects()
|
|
|
|
{
|
|
|
|
return _effectEngine->getActiveEffects();
|
|
|
|
}
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
int Hyperion::setEffect(const std::string &effectName, int priority, int timeout)
|
|
|
|
{
|
|
|
|
return _effectEngine->runEffect(effectName, priority, timeout);
|
|
|
|
}
|
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
int Hyperion::setEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout)
|
|
|
|
{
|
|
|
|
return _effectEngine->runEffect(effectName, args, priority, timeout);
|
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
void Hyperion::update()
|
|
|
|
{
|
|
|
|
// Update the muxer, cleaning obsolete priorities
|
2013-08-18 13:33:56 +02:00
|
|
|
_muxer.setCurrentTime(QDateTime::currentMSecsSinceEpoch());
|
2013-08-14 17:02:09 +02:00
|
|
|
|
|
|
|
// Obtain the current priority channel
|
2013-08-18 13:33:56 +02:00
|
|
|
int priority = _muxer.getCurrentPriority();
|
|
|
|
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
2013-08-14 17:02:09 +02:00
|
|
|
|
2015-12-22 10:01:47 +01:00
|
|
|
// Apply the correction and the transform to each led and color-channel
|
2016-04-02 00:04:11 +02:00
|
|
|
// Avoid applying correction, the same task is performed by adjustment
|
|
|
|
// std::vector<ColorRgb> correctedColors = _raw2ledCorrection->applyCorrection(priorityInfo.ledColors);
|
2016-05-22 00:30:53 +02:00
|
|
|
std::vector<ColorRgb> transformColors =_raw2ledTransform->applyTransform(priorityInfo.ledColors);
|
|
|
|
std::vector<ColorRgb> adjustedColors = _raw2ledAdjustment->applyAdjustment(transformColors);
|
|
|
|
std::vector<ColorRgb> ledColors = _raw2ledTemperature->applyCorrection(adjustedColors);
|
2015-01-01 19:31:04 +01:00
|
|
|
const std::vector<Led>& leds = _ledString.leds();
|
|
|
|
int i = 0;
|
2013-11-11 10:00:37 +01:00
|
|
|
for (ColorRgb& color : ledColors)
|
2013-08-21 21:50:17 +02:00
|
|
|
{
|
2015-02-23 16:11:33 +01:00
|
|
|
const ColorOrder ledColorOrder = leds.at(i).colorOrder;
|
2013-11-04 20:52:57 +01:00
|
|
|
// correct the color byte order
|
2015-01-01 19:31:04 +01:00
|
|
|
switch (ledColorOrder)
|
2013-10-27 10:18:31 +01:00
|
|
|
{
|
2013-11-04 20:52:57 +01:00
|
|
|
case ORDER_RGB:
|
|
|
|
// leave as it is
|
|
|
|
break;
|
|
|
|
case ORDER_BGR:
|
2013-10-27 10:18:31 +01:00
|
|
|
std::swap(color.red, color.blue);
|
2013-11-04 20:52:57 +01:00
|
|
|
break;
|
|
|
|
case ORDER_RBG:
|
|
|
|
std::swap(color.green, color.blue);
|
|
|
|
break;
|
|
|
|
case ORDER_GRB:
|
|
|
|
std::swap(color.red, color.green);
|
|
|
|
break;
|
|
|
|
case ORDER_GBR:
|
|
|
|
{
|
2016-05-22 00:30:53 +02:00
|
|
|
std::swap(color.red, color.green);
|
|
|
|
std::swap(color.green, color.blue);
|
2013-11-04 20:52:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ORDER_BRG:
|
|
|
|
{
|
2016-05-22 00:30:53 +02:00
|
|
|
std::swap(color.red, color.blue);
|
|
|
|
std::swap(color.green, color.blue);
|
2013-11-04 20:52:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-10-27 10:18:31 +01:00
|
|
|
}
|
2015-01-01 19:31:04 +01:00
|
|
|
i++;
|
2013-08-21 21:50:17 +02:00
|
|
|
}
|
2013-08-14 17:02:09 +02:00
|
|
|
|
|
|
|
// Write the data to the device
|
2013-08-21 21:50:17 +02:00
|
|
|
_device->write(ledColors);
|
2013-08-14 17:02:09 +02:00
|
|
|
|
|
|
|
// Start the timeout-timer
|
|
|
|
if (priorityInfo.timeoutTime_ms == -1)
|
|
|
|
{
|
|
|
|
_timer.stop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int timeout_ms = std::max(0, int(priorityInfo.timeoutTime_ms - QDateTime::currentMSecsSinceEpoch()));
|
|
|
|
_timer.start(timeout_ms);
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
}
|