2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
|
|
|
|
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-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>
|
|
|
|
#include <hyperion/LedDevice.h>
|
2013-08-15 21:11:02 +02:00
|
|
|
#include <hyperion/ImageProcessorFactory.h>
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-05 21:11:31 +01:00
|
|
|
#include "device/LedDeviceLpd6803.h"
|
2013-11-13 21:42:18 +01:00
|
|
|
#include "device/LedDeviceLpd8806.h"
|
2013-11-05 17:21:20 +01:00
|
|
|
#include "device/LedDeviceSedu.h"
|
2013-11-05 17:18:04 +01:00
|
|
|
#include "device/LedDeviceTest.h"
|
|
|
|
#include "device/LedDeviceWs2801.h"
|
2013-11-11 21:07:24 +01:00
|
|
|
#include "device/LedDeviceAdalight.h"
|
2013-11-13 20:15:53 +01:00
|
|
|
#include "device/LedDeviceLightpack.h"
|
2013-11-17 15:51:42 +01:00
|
|
|
#include "device/LedDeviceMultiLightpack.h"
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
#include "LinearColorSmoothing.h"
|
|
|
|
|
2013-08-23 18:24:10 +02:00
|
|
|
#include <utils/ColorTransform.h>
|
|
|
|
#include <utils/HsvTransform.h>
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
// effect engine includes
|
|
|
|
#include <effectengine/EffectEngine.h>
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
|
|
|
std::cout << "Device configuration: " << deviceConfig << std::endl;
|
2013-10-27 21:06:35 +01:00
|
|
|
|
|
|
|
std::string type = deviceConfig.get("type", "UNSPECIFIED").asString();
|
|
|
|
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
LedDevice* device = nullptr;
|
2013-10-27 21:06:35 +01:00
|
|
|
if (type == "ws2801")
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
2013-09-09 17:23:44 +02:00
|
|
|
LedDeviceWs2801* deviceWs2801 = new LedDeviceWs2801(output, rate);
|
2013-07-26 22:38:34 +02:00
|
|
|
deviceWs2801->open();
|
|
|
|
|
|
|
|
device = deviceWs2801;
|
|
|
|
}
|
2013-11-05 21:11:31 +01:00
|
|
|
else if (type == "lpd6803" || type == "ldp6803")
|
2013-11-02 06:51:41 +01:00
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
2013-11-13 21:42:18 +01:00
|
|
|
LedDeviceLpd6803* deviceLdp6803 = new LedDeviceLpd6803(output, rate);
|
2013-11-02 06:51:41 +01:00
|
|
|
deviceLdp6803->open();
|
|
|
|
|
|
|
|
device = deviceLdp6803;
|
|
|
|
}
|
2013-11-13 21:42:18 +01:00
|
|
|
else if (type == "lpd8806" || type == "ldp8806")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceLpd8806* deviceLpd8806 = new LedDeviceLpd8806(output, rate);
|
|
|
|
deviceLpd8806->open();
|
|
|
|
|
|
|
|
device = deviceLpd8806;
|
|
|
|
}
|
2013-11-05 17:21:20 +01:00
|
|
|
else if (type == "sedu")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceSedu* deviceSedu = new LedDeviceSedu(output, rate);
|
|
|
|
deviceSedu->open();
|
|
|
|
|
|
|
|
device = deviceSedu;
|
|
|
|
}
|
2013-11-11 21:07:24 +01:00
|
|
|
else if (type == "adalight")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate);
|
|
|
|
deviceAdalight->open();
|
|
|
|
|
|
|
|
device = deviceAdalight;
|
|
|
|
}
|
2013-11-13 20:15:53 +01:00
|
|
|
else if (type == "lightpack")
|
|
|
|
{
|
2013-11-13 23:10:11 +01:00
|
|
|
const std::string output = deviceConfig.get("output", "").asString();
|
|
|
|
|
2013-11-20 20:54:04 +01:00
|
|
|
LedDeviceLightpack* deviceLightpack = new LedDeviceLightpack();
|
|
|
|
deviceLightpack->open(output);
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
device = deviceLightpack;
|
|
|
|
}
|
2013-11-17 15:51:42 +01:00
|
|
|
else if (type == "multi-lightpack")
|
|
|
|
{
|
|
|
|
LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack();
|
|
|
|
deviceLightpack->open();
|
|
|
|
|
|
|
|
device = deviceLightpack;
|
|
|
|
}
|
2013-10-27 21:06:35 +01:00
|
|
|
else if (type == "test")
|
2013-08-15 21:11:02 +02:00
|
|
|
{
|
2013-11-02 06:51:41 +01:00
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
device = new LedDeviceTest(output);
|
2013-08-15 21:11:02 +02:00
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
else
|
|
|
|
{
|
2013-10-27 21:06:35 +01:00
|
|
|
std::cout << "Unable to create device " << type << std::endl;
|
2013-07-26 22:38:34 +02:00
|
|
|
// Unknown / Unimplemented device
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2013-11-04 20:52:57 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-24 11:51:52 +02:00
|
|
|
ColorTransform* Hyperion::createColorTransform(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
|
|
|
|
|
|
|
ColorTransform* transform = new ColorTransform(threshold, gamma, blacklevel, whitelevel);
|
|
|
|
return transform;
|
|
|
|
}
|
2013-10-27 18:04:37 +01:00
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
LedString Hyperion::createLedString(const Json::Value& ledsConfig)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
LedString ledString;
|
|
|
|
|
|
|
|
for (const Json::Value& ledConfig : ledsConfig)
|
|
|
|
{
|
|
|
|
Led led;
|
|
|
|
led.index = ledConfig["index"].asInt();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
{
|
|
|
|
std::cout << "Not creating any smoothing" << std::endl;
|
|
|
|
return ledDevice;
|
|
|
|
}
|
|
|
|
else if (type == "linear")
|
|
|
|
{
|
|
|
|
if (!smoothingConfig.isMember("time_ms"))
|
|
|
|
{
|
|
|
|
std::cout << "Unable to create smoothing of type linear because of missing parameter 'time_ms'" << std::endl;
|
|
|
|
}
|
|
|
|
else if (!smoothingConfig.isMember("updateFrequency"))
|
|
|
|
{
|
|
|
|
std::cout << "Unable to create smoothing of type linear because of missing parameter 'updateFrequency'" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Creating linear smoothing" << std::endl;
|
|
|
|
return new LinearColorSmoothing(ledDevice, smoothingConfig["updateFrequency"].asDouble(), smoothingConfig["time_ms"].asInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Unable to create smoothing of type " << type << std::endl;
|
|
|
|
}
|
|
|
|
|
2013-10-27 18:04:37 +01:00
|
|
|
return ledDevice;
|
|
|
|
}
|
|
|
|
|
2013-11-04 20:52:57 +01:00
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
2013-08-18 13:33:56 +02:00
|
|
|
_ledString(createLedString(jsonConfig["leds"])),
|
|
|
|
_muxer(_ledString.leds().size()),
|
2013-08-21 21:50:17 +02:00
|
|
|
_hsvTransform(createHsvTransform(jsonConfig["color"]["hsv"])),
|
2013-08-18 13:33:56 +02:00
|
|
|
_redTransform(createColorTransform(jsonConfig["color"]["red"])),
|
|
|
|
_greenTransform(createColorTransform(jsonConfig["color"]["green"])),
|
|
|
|
_blueTransform(createColorTransform(jsonConfig["color"]["blue"])),
|
2013-11-04 20:52:57 +01:00
|
|
|
_colorOrder(createColorOrder(jsonConfig["device"])),
|
2013-10-27 18:04:37 +01:00
|
|
|
_device(createDevice(jsonConfig["device"])),
|
2013-11-24 16:10:48 +01:00
|
|
|
_effectEngine(nullptr),
|
2013-08-14 17:02:09 +02:00
|
|
|
_timer()
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-10-27 18:04:37 +01:00
|
|
|
// initialize the image processor factory
|
2013-10-20 22:27:05 +02:00
|
|
|
ImageProcessorFactory::getInstance().init(_ledString, jsonConfig["blackborderdetector"].get("enable", true).asBool());
|
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-08-21 21:50:17 +02:00
|
|
|
// delete he hsv transform
|
|
|
|
delete _hsvTransform;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Delete the color-transform
|
2013-08-18 13:33:56 +02:00
|
|
|
delete _blueTransform;
|
|
|
|
delete _greenTransform;
|
|
|
|
delete _redTransform;
|
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-11-11 10:00:37 +01:00
|
|
|
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms)
|
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
|
|
|
|
setColors(priority, ledColors, timeout_ms);
|
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
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-08-19 19:57:35 +02:00
|
|
|
void Hyperion::setTransform(Hyperion::Transform transform, Hyperion::Color color, double value)
|
|
|
|
{
|
|
|
|
// select the transform of the requested color
|
|
|
|
ColorTransform * t = nullptr;
|
|
|
|
switch (color)
|
|
|
|
{
|
|
|
|
case RED:
|
|
|
|
t = _redTransform;
|
|
|
|
break;
|
|
|
|
case GREEN:
|
|
|
|
t = _greenTransform;
|
|
|
|
break;
|
|
|
|
case BLUE:
|
|
|
|
t = _blueTransform;
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-21 21:50:17 +02:00
|
|
|
break;
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set transform value
|
|
|
|
switch (transform)
|
|
|
|
{
|
2013-08-21 21:50:17 +02:00
|
|
|
case SATURATION_GAIN:
|
|
|
|
_hsvTransform->setSaturationGain(value);
|
|
|
|
break;
|
|
|
|
case VALUE_GAIN:
|
|
|
|
_hsvTransform->setValueGain(value);
|
|
|
|
break;
|
2013-08-19 19:57:35 +02:00
|
|
|
case THRESHOLD:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 19:57:35 +02:00
|
|
|
t->setThreshold(value);
|
|
|
|
break;
|
|
|
|
case GAMMA:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 19:57:35 +02:00
|
|
|
t->setGamma(value);
|
|
|
|
break;
|
|
|
|
case BLACKLEVEL:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 19:57:35 +02:00
|
|
|
t->setBlacklevel(value);
|
|
|
|
break;
|
|
|
|
case WHITELEVEL:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 19:57:35 +02:00
|
|
|
t->setWhitelevel(value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
2013-08-21 21:50:17 +02:00
|
|
|
|
|
|
|
// update the led output
|
|
|
|
update();
|
2013-08-19 19:57:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-18 13:33:56 +02:00
|
|
|
void Hyperion::clear(int priority)
|
|
|
|
{
|
|
|
|
if (_muxer.hasPriority(priority))
|
|
|
|
{
|
|
|
|
_muxer.clearInput(priority);
|
|
|
|
|
|
|
|
// update leds if necessary
|
|
|
|
if (priority < _muxer.getCurrentPriority());
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-19 20:33:36 +02:00
|
|
|
double Hyperion::getTransform(Hyperion::Transform transform, Hyperion::Color color) const
|
|
|
|
{
|
|
|
|
// select the transform of the requested color
|
|
|
|
ColorTransform * t = nullptr;
|
|
|
|
switch (color)
|
|
|
|
{
|
|
|
|
case RED:
|
|
|
|
t = _redTransform;
|
|
|
|
break;
|
|
|
|
case GREEN:
|
|
|
|
t = _greenTransform;
|
|
|
|
break;
|
|
|
|
case BLUE:
|
|
|
|
t = _blueTransform;
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-21 21:50:17 +02:00
|
|
|
break;
|
2013-08-19 20:33:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set transform value
|
|
|
|
switch (transform)
|
|
|
|
{
|
2013-08-21 21:50:17 +02:00
|
|
|
case SATURATION_GAIN:
|
|
|
|
return _hsvTransform->getSaturationGain();
|
|
|
|
case VALUE_GAIN:
|
|
|
|
return _hsvTransform->getValueGain();
|
2013-08-19 20:33:36 +02:00
|
|
|
case THRESHOLD:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 20:33:36 +02:00
|
|
|
return t->getThreshold();
|
|
|
|
case GAMMA:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 20:33:36 +02:00
|
|
|
return t->getGamma();
|
|
|
|
case BLACKLEVEL:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 20:33:36 +02:00
|
|
|
return t->getBlacklevel();
|
|
|
|
case WHITELEVEL:
|
2013-08-21 21:50:17 +02:00
|
|
|
assert (t != nullptr);
|
2013-08-19 20:33:36 +02:00
|
|
|
return t->getWhitelevel();
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 999.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> Hyperion::getActivePriorities() const
|
|
|
|
{
|
|
|
|
return _muxer.getPriorities();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Hyperion::InputInfo &Hyperion::getPriorityInfo(const int priority) const
|
|
|
|
{
|
|
|
|
return _muxer.getInputInfo(priority);
|
|
|
|
}
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
std::list<std::string> Hyperion::getEffects() const
|
|
|
|
{
|
|
|
|
return _effectEngine->getEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Hyperion::setEffect(const std::string &effectName, int priority, int timeout)
|
|
|
|
{
|
|
|
|
return _effectEngine->runEffect(effectName, 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
|
|
|
|
2013-08-21 21:50:17 +02:00
|
|
|
// Apply the transform to each led and color-channel
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> ledColors(priorityInfo.ledColors);
|
|
|
|
for (ColorRgb& color : ledColors)
|
2013-08-21 21:50:17 +02:00
|
|
|
{
|
|
|
|
_hsvTransform->transform(color.red, color.green, color.blue);
|
|
|
|
color.red = _redTransform->transform(color.red);
|
|
|
|
color.green = _greenTransform->transform(color.green);
|
|
|
|
color.blue = _blueTransform->transform(color.blue);
|
2013-10-27 10:18:31 +01:00
|
|
|
|
2013-11-04 20:52:57 +01:00
|
|
|
// correct the color byte order
|
|
|
|
switch (_colorOrder)
|
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:
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2013-10-27 10:18:31 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|