Details coming soon.

This commit is contained in:
Paulchen-Panther
2018-12-27 23:11:32 +01:00
parent e3be03ea73
commit d762aa2f3e
186 changed files with 6156 additions and 5444 deletions

View File

@@ -3,12 +3,14 @@
namespace hyperion
{
/**
* Enumeration of components in Hyperion.
*/
enum Components
{
COMP_INVALID,
COMP_ALL,
COMP_SMOOTHING,
COMP_BLACKBORDER,
COMP_FORWARDER,
@@ -17,6 +19,7 @@ enum Components
COMP_GRABBER,
COMP_V4L,
COMP_COLOR,
COMP_IMAGE,
COMP_EFFECT,
COMP_PROTOSERVER,
COMP_LEDDEVICE
@@ -26,6 +29,7 @@ inline const char* componentToString(Components c)
{
switch (c)
{
case COMP_ALL: return "Hyperion";
case COMP_SMOOTHING: return "Smoothing";
case COMP_BLACKBORDER: return "Blackborder detector";
case COMP_FORWARDER: return "Json/Proto forwarder";
@@ -35,6 +39,7 @@ inline const char* componentToString(Components c)
case COMP_V4L: return "V4L capture device";
case COMP_COLOR: return "Solid color";
case COMP_EFFECT: return "Effect";
case COMP_IMAGE: return "Image";
case COMP_PROTOSERVER: return "Proto Server";
case COMP_LEDDEVICE: return "LED device";
default: return "";
@@ -45,6 +50,7 @@ inline const char* componentToIdString(Components c)
{
switch (c)
{
case COMP_ALL: return "ALL";
case COMP_SMOOTHING: return "SMOOTHING";
case COMP_BLACKBORDER: return "BLACKBORDER";
case COMP_FORWARDER: return "FORWARDER";
@@ -54,6 +60,7 @@ inline const char* componentToIdString(Components c)
case COMP_V4L: return "V4L";
case COMP_COLOR: return "COLOR";
case COMP_EFFECT: return "EFFECT";
case COMP_IMAGE: return "IMAGE";
case COMP_PROTOSERVER: return "PROTOSERVER";
case COMP_LEDDEVICE: return "LEDDEVICE";
default: return "";
@@ -63,6 +70,7 @@ inline const char* componentToIdString(Components c)
inline Components stringToComponent(QString component)
{
component = component.toUpper();
if (component == "ALL") return COMP_ALL;
if (component == "SMOOTHING") return COMP_SMOOTHING;
if (component == "BLACKBORDER") return COMP_BLACKBORDER;
if (component == "FORWARDER") return COMP_FORWARDER;
@@ -72,6 +80,7 @@ inline Components stringToComponent(QString component)
if (component == "V4L") return COMP_V4L;
if (component == "COLOR") return COMP_COLOR;
if (component == "EFFECT") return COMP_EFFECT;
if (component == "IMAGE") return COMP_IMAGE;
if (component == "PROTOSERVER") return COMP_PROTOSERVER;
if (component == "LEDDEVICE") return COMP_LEDDEVICE;

View File

@@ -13,6 +13,11 @@ namespace FileUtils {
QString getBaseName( QString sourceFile);
QString getDirName( QString sourceFile);
///
/// @brief remove directory recursive given by path
/// @param[in] path Path to directory
bool removeDir(const QString& path, Logger* log);
///
/// @brief check if the file exists
/// @param[in] path The file path to check
@@ -45,9 +50,10 @@ QString getDirName( QString sourceFile);
/// @brief delete a file by given path
/// @param[in] path The file path to delete
/// @param[in] log The logger of the caller to print errors
/// @param[in] ignError Ignore errors during file delete (no log output)
/// @return true on success else false
///
bool removeFile(const QString& path, Logger* log);
bool removeFile(const QString& path, Logger* log, bool ignError=false);
///
/// @brief Convert a path that may contain special placeholders

View File

@@ -71,6 +71,38 @@ public:
memcpy(_pixels, other._pixels, other._width * other._height * sizeof(Pixel_T));
}
// Define assignment operator in terms of the copy constructor
// More to read: https://stackoverflow.com/questions/255612/dynamically-allocating-an-array-of-objects?answertab=active#tab-top
Image& operator=(Image rhs)
{
rhs.swap(*this);
return *this;
}
void swap(Image& s) noexcept
{
using std::swap;
swap(this->_width, s._width);
swap(this->_height, s._height);
swap(this->_pixels, s._pixels);
swap(this->_endOfPixels, s._endOfPixels);
}
// C++11
Image(Image&& src) noexcept
: _width(0)
, _height(0)
, _pixels(NULL)
, _endOfPixels(NULL)
{
src.swap(*this);
}
Image& operator=(Image&& src) noexcept
{
src.swap(*this);
return *this;
}
///
/// Destructor
///

View File

@@ -1,280 +0,0 @@
#pragma once
// hyperion includes
#include <utils/Logger.h>
#include <utils/jsonschema/QJsonSchemaChecker.h>
#include <utils/Components.h>
#include <hyperion/Hyperion.h>
// qt includess
#include <QJsonObject>
#include <QMutex>
#include <QString>
// createEffect helper
struct find_schema: std::unary_function<EffectSchema, bool>
{
QString pyFile;
find_schema(QString pyFile):pyFile(pyFile) { }
bool operator()(EffectSchema const& schema) const
{
return schema.pyFile == pyFile;
}
};
// deleteEffect helper
struct find_effect: std::unary_function<EffectDefinition, bool>
{
QString effectName;
find_effect(QString effectName) :effectName(effectName) { }
bool operator()(EffectDefinition const& effectDefinition) const
{
return effectDefinition.name == effectName;
}
};
class ImageProcessor;
class JsonProcessor : public QObject
{
Q_OBJECT
public:
///
/// Constructor
///
/// @param peerAddress provide the Address of the peer
/// @param log The Logger class of the creator
/// @param parent Parent QObject
/// @param noListener if true, this instance won't listen for hyperion push events
///
JsonProcessor(QString peerAddress, Logger* log, QObject* parent, bool noListener = false);
///
/// Handle an incoming JSON message
///
/// @param message the incoming message as string
///
void handleMessage(const QString & message);
///
/// send a forced serverinfo to a client
///
void forceServerInfo();
public slots:
///
/// @brief is called whenever the current Hyperion instance pushes new led raw values (if enabled)
/// @param ledColors The current ledColors
///
void streamLedcolorsUpdate(const std::vector<ColorRgb>& ledColors);
/// push images whenever hyperion emits (if enabled)
void setImage(int priority, const Image<ColorRgb> & image, int duration_ms);
/// process and push new log messages from logger (if enabled)
void incommingLogMessage(Logger::T_LOG_MESSAGE);
signals:
///
/// Signal which is emitted when a sendSuccessReply() has been executed
///
void pushReq();
///
/// Signal emits with the reply message provided with handleMessage()
///
void callbackMessage(QJsonObject);
///
/// Signal emits whenever a jsonmessage should be forwarded
///
void forwardJsonMessage(QJsonObject);
private:
/// The peer address of the client
QString _peerAddress;
/// Log instance
Logger* _log;
/// Hyperion instance
Hyperion* _hyperion;
/// The processor for translating images to led-values
ImageProcessor * _imageProcessor;
/// holds the state before off state
static std::map<hyperion::Components, bool> _componentsPrevState;
/// returns if hyperion is on or off
inline bool hyperionIsActive() { return JsonProcessor::_componentsPrevState.empty(); };
// streaming buffers
QJsonObject _streaming_leds_reply;
QJsonObject _streaming_image_reply;
QJsonObject _streaming_logging_reply;
bool _ledcolorsLedsActive = false;
/// flag to determine state of log streaming
bool _streaming_logging_activated;
/// mutex to determine state of image streaming
QMutex _image_stream_mutex;
/// mutex to determine state of led color streaming
QMutex _led_stream_mutex;
/// timeout for live video refresh
volatile qint64 _image_stream_timeout;
/// timeout for led color refresh
volatile qint64 _led_stream_timeout;
///
/// Handle an incoming JSON Color message
///
/// @param message the incoming message
///
void handleColorCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Image message
///
/// @param message the incoming message
///
void handleImageCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Effect message
///
/// @param message the incoming message
///
void handleEffectCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Effect message (Write JSON Effect)
///
/// @param message the incoming message
///
void handleCreateEffectCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Effect message (Delete JSON Effect)
///
/// @param message the incoming message
///
void handleDeleteEffectCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON System info message
///
/// @param message the incoming message
///
void handleSysInfoCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Server info message
///
/// @param message the incoming message
///
void handleServerInfoCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Clear message
///
/// @param message the incoming message
///
void handleClearCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Clearall message
///
/// @param message the incoming message
///
void handleClearallCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Adjustment message
///
/// @param message the incoming message
///
void handleAdjustmentCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON SourceSelect message
///
/// @param message the incoming message
///
void handleSourceSelectCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON GetConfig message and check subcommand
///
/// @param message the incoming message
///
void handleConfigCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON GetConfig message from handleConfigCommand()
///
/// @param message the incoming message
///
void handleSchemaGetCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON GetConfig message from handleConfigCommand()
///
/// @param message the incoming message
///
void handleConfigGetCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON SetConfig message from handleConfigCommand()
///
/// @param message the incoming message
///
void handleConfigSetCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON Component State message
///
/// @param message the incoming message
///
void handleComponentStateCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON Led Colors message
///
/// @param message the incoming message
///
void handleLedColorsCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON Logging message
///
/// @param message the incoming message
///
void handleLoggingCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON Proccessing message
///
/// @param message the incoming message
///
void handleProcessingCommand(const QJsonObject & message, const QString &command, const int tan);
/// Handle an incoming JSON VideoMode message
///
/// @param message the incoming message
///
void handleVideoModeCommand(const QJsonObject & message, const QString &command, const int tan);
///
/// Handle an incoming JSON message of unknown type
///
void handleNotImplemented();
///
/// Send a standard reply indicating success
///
void sendSuccessReply(const QString &command="", const int tan=0);
///
/// Send an error message back to the client
///
/// @param error String describing the error
///
void sendErrorReply(const QString & error, const QString &command="", const int tan=0);
};

View File

@@ -26,7 +26,7 @@ namespace JsonUtils{
bool readSchema(const QString& path, QJsonObject& obj, Logger* log);
///
/// @brief parse a json QString and get the result on success
/// @brief parse a json QString and get a QJsonObject. Overloaded funtion
/// @param[in] path The file path/name just used for log messages
/// @param[in] data Data to parse
/// @param[out] obj Retuns the parsed QJsonObject
@@ -35,6 +35,26 @@ namespace JsonUtils{
///
bool parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
///
/// @brief parse a json QString and get a QJsonArray. Overloaded function
/// @param[in] path The file path/name just used for log messages
/// @param[in] data Data to parse
/// @param[out] arr Retuns the parsed QJsonArray
/// @param[in] log The logger of the caller to print errors
/// @return true on success else false
///
bool parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log);
///
/// @brief parse a json QString and get a QJsonDocument
/// @param[in] path The file path/name just used for log messages
/// @param[in] data Data to parse
/// @param[out] doc Retuns the parsed QJsonDocument
/// @param[in] log The logger of the caller to print errors
/// @return true on success else false
///
bool parse(const QString& path, const QString& data, QJsonDocument& doc, Logger* log);
///
/// @brief Validate json data against a schema
/// @param[in] file The path/name of json file just used for log messages
@@ -45,6 +65,16 @@ namespace JsonUtils{
///
bool validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
///
/// @brief Validate json data against a schema
/// @param[in] file The path/name of json file just used for log messages
/// @param[in] json The json data
/// @param[in] schema The schema object
/// @param[in] log The logger of the caller to print errors
/// @return true on success else false
///
bool validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log);
///
/// @brief Write json data to file
/// @param[in] filenameThe file path to write

320
include/utils/hyperion.h Normal file
View File

@@ -0,0 +1,320 @@
#pragma once
#include <hyperion/ColorAdjustment.h>
#include <hyperion/MultiColorAdjustment.h>
#include <hyperion/LedString.h>
// fg effect
#include <hyperion/Hyperion.h>
///
/// @brief Provide utility methods for Hyperion class
///
namespace hyperion {
void handleInitialEffect(Hyperion* hyperion, const QJsonObject& FGEffectConfig)
{
#define FGCONFIG_ARRAY fgColorConfig.toArray()
const int FG_PRIORITY = 0;
const int DURATION_INFINITY = 0;
// initial foreground effect/color
if (FGEffectConfig["enable"].toBool(true))
{
const QString fgTypeConfig = FGEffectConfig["type"].toString("effect");
const QString fgEffectConfig = FGEffectConfig["effect"].toString("Rainbow swirl fast");
const QJsonValue fgColorConfig = FGEffectConfig["color"];
int default_fg_duration_ms = 3000;
int fg_duration_ms = FGEffectConfig["duration_ms"].toInt(default_fg_duration_ms);
if (fg_duration_ms == DURATION_INFINITY)
{
fg_duration_ms = default_fg_duration_ms;
Warning(Logger::getInstance("HYPERION"), "foreground effect duration 'infinity' is forbidden, set to default value %d ms",default_fg_duration_ms);
}
if ( fgTypeConfig.contains("color") )
{
ColorRgb fg_color = {
(uint8_t)FGCONFIG_ARRAY.at(0).toInt(0),
(uint8_t)FGCONFIG_ARRAY.at(1).toInt(0),
(uint8_t)FGCONFIG_ARRAY.at(2).toInt(0)
};
hyperion->setColor(FG_PRIORITY, fg_color, fg_duration_ms);
Info(Logger::getInstance("HYPERION"),"Inital foreground color set (%d %d %d)",fg_color.red,fg_color.green,fg_color.blue);
}
else
{
int result = hyperion->setEffect(fgEffectConfig, FG_PRIORITY, fg_duration_ms);
Info(Logger::getInstance("HYPERION"),"Inital foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed"));
}
}
#undef FGCONFIG_ARRAY
}
ColorOrder createColorOrder(const QJsonObject &deviceConfig)
{
return stringToColorOrder(deviceConfig["colorOrder"].toString("rgb"));
}
RgbTransform* createRgbTransform(const QJsonObject& colorConfig)
{
const double backlightThreshold = colorConfig["backlightThreshold"].toDouble(0.0);
const bool backlightColored = colorConfig["backlightColored"].toBool(false);
const double brightness = colorConfig["brightness"].toInt(100);
const double brightnessComp= colorConfig["brightnessCompensation"].toInt(100);
const double gammaR = colorConfig["gammaRed"].toDouble(1.0);
const double gammaG = colorConfig["gammaGreen"].toDouble(1.0);
const double gammaB = colorConfig["gammaBlue"].toDouble(1.0);
RgbTransform* transform = new RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessComp);
return transform;
}
RgbChannelAdjustment* createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString channelName, const int defaultR, const int defaultG, const int defaultB)
{
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
RgbChannelAdjustment* adjustment = new RgbChannelAdjustment(
channelConfig[0].toInt(defaultR),
channelConfig[1].toInt(defaultG),
channelConfig[2].toInt(defaultB),
"ChannelAdjust_"+channelName.toUpper()
);
return adjustment;
}
ColorAdjustment * createColorAdjustment(const QJsonObject & adjustmentConfig)
{
const QString id = adjustmentConfig["id"].toString("default");
RgbChannelAdjustment * blackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , 0, 0, 0);
RgbChannelAdjustment * whiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , 255,255,255);
RgbChannelAdjustment * redAdjustment = createRgbChannelAdjustment(adjustmentConfig, "red" , 255, 0, 0);
RgbChannelAdjustment * greenAdjustment = createRgbChannelAdjustment(adjustmentConfig, "green" , 0,255, 0);
RgbChannelAdjustment * blueAdjustment = createRgbChannelAdjustment(adjustmentConfig, "blue" , 0, 0,255);
RgbChannelAdjustment * cyanAdjustment = createRgbChannelAdjustment(adjustmentConfig, "cyan" , 0,255,255);
RgbChannelAdjustment * magentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", 255, 0,255);
RgbChannelAdjustment * yellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , 255,255, 0);
RgbTransform * rgbTransform = createRgbTransform(adjustmentConfig);
ColorAdjustment * adjustment = new ColorAdjustment();
adjustment->_id = id;
adjustment->_rgbBlackAdjustment = *blackAdjustment;
adjustment->_rgbWhiteAdjustment = *whiteAdjustment;
adjustment->_rgbRedAdjustment = *redAdjustment;
adjustment->_rgbGreenAdjustment = *greenAdjustment;
adjustment->_rgbBlueAdjustment = *blueAdjustment;
adjustment->_rgbCyanAdjustment = *cyanAdjustment;
adjustment->_rgbMagentaAdjustment = *magentaAdjustment;
adjustment->_rgbYellowAdjustment = *yellowAdjustment;
adjustment->_rgbTransform = *rgbTransform;
// Cleanup the allocated individual adjustments
delete blackAdjustment;
delete whiteAdjustment;
delete redAdjustment;
delete greenAdjustment;
delete blueAdjustment;
delete cyanAdjustment;
delete magentaAdjustment;
delete yellowAdjustment;
delete rgbTransform;
return adjustment;
}
MultiColorAdjustment * createLedColorsAdjustment(const unsigned ledCnt, const QJsonObject & colorConfig)
{
// Create the result, the transforms are added to this
MultiColorAdjustment * adjustment = new MultiColorAdjustment(ledCnt);
const QJsonValue adjustmentConfig = colorConfig["channelAdjustment"];
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
const QJsonArray & adjustmentConfigArray = adjustmentConfig.toArray();
for (signed i = 0; i < adjustmentConfigArray.size(); ++i)
{
const QJsonObject & config = adjustmentConfigArray.at(i).toObject();
ColorAdjustment * colorAdjustment = createColorAdjustment(config);
adjustment->addAdjustment(colorAdjustment);
const QString ledIndicesStr = config["leds"].toString("").trimmed();
if (ledIndicesStr.compare("*") == 0)
{
// Special case for indices '*' => all leds
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
//Info(_log, "ColorAdjustment '%s' => [0; %d]", QSTRING_CSTR(colorAdjustment->_id), ledCnt-1);
continue;
}
if (!overallExp.exactMatch(ledIndicesStr))
{
//Error(_log, "Given led indices %d not correct format: %s", i, QSTRING_CSTR(ledIndicesStr));
continue;
}
std::stringstream ss;
const QStringList ledIndexList = ledIndicesStr.split(",");
for (int i=0; i<ledIndexList.size(); ++i) {
if (i > 0)
{
ss << ", ";
}
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);
ss << startInd << "-" << endInd;
}
else
{
int index = ledIndexList[i].toInt();
adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index);
ss << index;
}
}
//Info(_log, "ColorAdjustment '%s' => [%s]", QSTRING_CSTR(colorAdjustment->_id), ss.str().c_str());
}
return adjustment;
}
/**
* 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
* @return The constructed ledstring
*/
LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);
int maxLedId = ledConfigArray.size();
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& index = ledConfigArray[i].toObject();
Led led;
led.index = index["index"].toInt();
led.clone = index["clone"].toInt(-1);
if ( led.clone < -1 || led.clone >= maxLedId )
{
//Warning(_log, "LED %d: clone index of %d is out of range, clone ignored", led.index, led.clone);
led.clone = -1;
}
if ( led.clone < 0 )
{
const QJsonObject& hscanConfig = ledConfigArray[i].toObject()["hscan"].toObject();
const QJsonObject& vscanConfig = ledConfigArray[i].toObject()["vscan"].toObject();
led.minX_frac = qMax(0.0, qMin(1.0, hscanConfig["minimum"].toDouble()));
led.maxX_frac = qMax(0.0, qMin(1.0, hscanConfig["maximum"].toDouble()));
led.minY_frac = qMax(0.0, qMin(1.0, vscanConfig["minimum"].toDouble()));
led.maxY_frac = qMax(0.0, qMin(1.0, vscanConfig["maximum"].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(index["colorOrder"].toString(deviceOrderStr));
ledString.leds().push_back(led);
}
}
// 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; });
return ledString;
}
LedString createLedStringClone(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);
int maxLedId = ledConfigArray.size();
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& index = ledConfigArray[i].toObject();
Led led;
led.index = index["index"].toInt();
led.clone = index["clone"].toInt(-1);
if ( led.clone < -1 || led.clone >= maxLedId )
{
//Warning(_log, "LED %d: clone index of %d is out of range, clone ignored", led.index, led.clone);
led.clone = -1;
}
if ( led.clone >= 0 )
{
//Debug(_log, "LED %d: clone from led %d", led.index, led.clone);
led.minX_frac = 0;
led.maxX_frac = 0;
led.minY_frac = 0;
led.maxY_frac = 0;
// Get the order of the rgb channels for this led (default is device order)
led.colorOrder = stringToColorOrder(index["colorOrder"].toString(deviceOrderStr));
ledString.leds().push_back(led);
}
}
// 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; });
return ledString;
}
QSize getLedLayoutGridSize(const QJsonArray& ledConfigArray)
{
std::vector<int> midPointsX;
std::vector<int> midPointsY;
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& index = ledConfigArray[i].toObject();
if (index["clone"].toInt(-1) < 0 )
{
const QJsonObject& hscanConfig = ledConfigArray[i].toObject()["hscan"].toObject();
const QJsonObject& vscanConfig = ledConfigArray[i].toObject()["vscan"].toObject();
double minX_frac = qMax(0.0, qMin(1.0, hscanConfig["minimum"].toDouble()));
double maxX_frac = qMax(0.0, qMin(1.0, hscanConfig["maximum"].toDouble()));
double minY_frac = qMax(0.0, qMin(1.0, vscanConfig["minimum"].toDouble()));
double maxY_frac = qMax(0.0, qMin(1.0, vscanConfig["maximum"].toDouble()));
// Fix if the user swapped min and max
if (minX_frac > maxX_frac)
{
std::swap(minX_frac, maxX_frac);
}
if (minY_frac > maxY_frac)
{
std::swap(minY_frac, maxY_frac);
}
// calculate mid point and make grid calculation
midPointsX.push_back( int(1000.0*(minX_frac + maxX_frac) / 2.0) );
midPointsY.push_back( int(1000.0*(minY_frac + maxY_frac) / 2.0) );
}
}
// remove duplicates
std::sort(midPointsX.begin(), midPointsX.end());
midPointsX.erase(std::unique(midPointsX.begin(), midPointsX.end()), midPointsX.end());
std::sort(midPointsY.begin(), midPointsY.end());
midPointsY.erase(std::unique(midPointsY.begin(), midPointsY.end()), midPointsY.end());
QSize gridSize( midPointsX.size(), midPointsY.size() );
//Debug(_log, "led layout grid: %dx%d", gridSize.width(), gridSize.height());
return gridSize;
}
};

99
include/utils/settings.h Normal file
View File

@@ -0,0 +1,99 @@
#pragma once
#include <QString>
#include <QJsonDocument>
///
/// @brief Provide util methods to work with SettingsManager class
///
namespace settings {
// all available settings sections
enum type {
BGEFFECT,
FGEFFECT,
BLACKBORDER,
BOBLSERVER,
COLOR,
DEVICE,
EFFECTS,
NETFORWARD,
SYSTEMCAPTURE,
GENERAL,
V4L2,
JSONSERVER,
LEDCONFIG,
LEDS,
LOGGER,
PROTOSERVER,
SMOOTHING,
UDPLISTENER,
WEBSERVER,
INSTCAPTURE,
NETWORK,
INVALID
};
///
/// @brief Convert settings::type to string representation
/// @param type The settings::type from enum
/// @return The settings type as string
///
inline QString typeToString(const type& type)
{
switch (type)
{
case BGEFFECT: return "backgroundEffect";
case FGEFFECT: return "foregroundEffect";
case BLACKBORDER: return "blackborderdetector";
case BOBLSERVER: return "boblightServer";
case COLOR: return "color";
case DEVICE: return "device";
case EFFECTS: return "effects";
case NETFORWARD: return "forwarder";
case SYSTEMCAPTURE: return "framegrabber";
case GENERAL: return "general";
case V4L2: return "grabberV4L2";
case JSONSERVER: return "jsonServer";
case LEDCONFIG: return "ledConfig";
case LEDS: return "leds";
case LOGGER: return "logger";
case PROTOSERVER: return "protoServer";
case SMOOTHING: return "smoothing";
case UDPLISTENER: return "udpListener";
case WEBSERVER: return "webConfig";
case INSTCAPTURE: return "instCapture";
case NETWORK: return "network";
default: return "invalid";
}
}
///
/// @brief Convert string to settings::type representation
/// @param type The string to convert
/// @return The settings type from enum
///
inline type stringToType(const QString& type)
{
if (type == "backgroundEffect") return BGEFFECT;
else if (type == "foregroundEffect") return FGEFFECT;
else if (type == "blackborderdetector") return BLACKBORDER;
else if (type == "boblightServer") return BOBLSERVER;
else if (type == "color") return COLOR;
else if (type == "device") return DEVICE;
else if (type == "effects") return EFFECTS;
else if (type == "forwarder") return NETFORWARD;
else if (type == "framegrabber") return SYSTEMCAPTURE;
else if (type == "general") return GENERAL;
else if (type == "grabberV4L2") return V4L2;
else if (type == "jsonServer") return JSONSERVER;
else if (type == "ledConfig") return LEDCONFIG;
else if (type == "leds") return LEDS;
else if (type == "logger") return LOGGER;
else if (type == "protoServer") return PROTOSERVER;
else if (type == "smoothing") return SMOOTHING;
else if (type == "udpListener") return UDPLISTENER;
else if (type == "webConfig") return WEBSERVER;
else if (type == "instCapture") return INSTCAPTURE;
else if (type == "network") return NETWORK;
else return INVALID;
}
};