mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
refactor: Improve utils code style (#841)
* Improve utils code style * Fix indendation Co-authored-by: brindosch <edeltraud70@gmx.de>
This commit is contained in:
parent
bfb50b8d91
commit
458113f8f9
@ -15,15 +15,13 @@ namespace NetUtils {
|
|||||||
{
|
{
|
||||||
const quint16 prevPort = port;
|
const quint16 prevPort = port;
|
||||||
QTcpServer server;
|
QTcpServer server;
|
||||||
bool corrected = false;
|
|
||||||
while (!server.listen(QHostAddress::Any, port))
|
while (!server.listen(QHostAddress::Any, port))
|
||||||
{
|
{
|
||||||
corrected = true;
|
|
||||||
Warning(log,"Port '%d' is already in use, will increment", port);
|
Warning(log,"Port '%d' is already in use, will increment", port);
|
||||||
port ++;
|
port ++;
|
||||||
}
|
}
|
||||||
server.close();
|
server.close();
|
||||||
if(corrected)
|
if(port != prevPort)
|
||||||
{
|
{
|
||||||
Warning(log, "The requested Port '%d' was already in use, will use Port '%d' instead", prevPort, port);
|
Warning(log, "The requested Port '%d' was already in use, will use Port '%d' instead", prevPort, port);
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// @note The values are updated in place.
|
/// @note The values are updated in place.
|
||||||
///
|
///
|
||||||
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w );
|
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Apply the transform the the given RGB values.
|
/// Apply the transform the the given RGB values.
|
||||||
|
@ -58,7 +58,7 @@ namespace hyperion {
|
|||||||
return stringToColorOrder(deviceConfig["colorOrder"].toString("rgb"));
|
return stringToColorOrder(deviceConfig["colorOrder"].toString("rgb"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RgbTransform* createRgbTransform(const QJsonObject& colorConfig)
|
RgbTransform createRgbTransform(const QJsonObject& colorConfig)
|
||||||
{
|
{
|
||||||
const double backlightThreshold = colorConfig["backlightThreshold"].toDouble(0.0);
|
const double backlightThreshold = colorConfig["backlightThreshold"].toDouble(0.0);
|
||||||
const bool backlightColored = colorConfig["backlightColored"].toBool(false);
|
const bool backlightColored = colorConfig["backlightColored"].toBool(false);
|
||||||
@ -68,58 +68,35 @@ namespace hyperion {
|
|||||||
const double gammaG = colorConfig["gammaGreen"].toDouble(1.0);
|
const double gammaG = colorConfig["gammaGreen"].toDouble(1.0);
|
||||||
const double gammaB = colorConfig["gammaBlue"].toDouble(1.0);
|
const double gammaB = colorConfig["gammaBlue"].toDouble(1.0);
|
||||||
|
|
||||||
RgbTransform* transform = new RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessComp);
|
return 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)
|
RgbChannelAdjustment createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString& channelName, const int defaultR, const int defaultG, const int defaultB)
|
||||||
{
|
{
|
||||||
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
|
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
|
||||||
RgbChannelAdjustment* adjustment = new RgbChannelAdjustment(
|
return RgbChannelAdjustment(
|
||||||
channelConfig[0].toInt(defaultR),
|
channelConfig[0].toInt(defaultR),
|
||||||
channelConfig[1].toInt(defaultG),
|
channelConfig[1].toInt(defaultG),
|
||||||
channelConfig[2].toInt(defaultB),
|
channelConfig[2].toInt(defaultB),
|
||||||
"ChannelAdjust_" + channelName.toUpper()
|
"ChannelAdjust_" + channelName.toUpper()
|
||||||
);
|
);
|
||||||
return adjustment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorAdjustment* createColorAdjustment(const QJsonObject & adjustmentConfig)
|
ColorAdjustment* createColorAdjustment(const QJsonObject & adjustmentConfig)
|
||||||
{
|
{
|
||||||
const QString id = adjustmentConfig["id"].toString("default");
|
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();
|
ColorAdjustment * adjustment = new ColorAdjustment();
|
||||||
adjustment->_id = id;
|
adjustment->_id = id;
|
||||||
adjustment->_rgbBlackAdjustment = *blackAdjustment;
|
adjustment->_rgbBlackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , 0, 0, 0);
|
||||||
adjustment->_rgbWhiteAdjustment = *whiteAdjustment;
|
adjustment->_rgbWhiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , 255,255,255);
|
||||||
adjustment->_rgbRedAdjustment = *redAdjustment;
|
adjustment->_rgbRedAdjustment = createRgbChannelAdjustment(adjustmentConfig, "red" , 255, 0, 0);
|
||||||
adjustment->_rgbGreenAdjustment = *greenAdjustment;
|
adjustment->_rgbGreenAdjustment = createRgbChannelAdjustment(adjustmentConfig, "green" , 0,255, 0);
|
||||||
adjustment->_rgbBlueAdjustment = *blueAdjustment;
|
adjustment->_rgbBlueAdjustment = createRgbChannelAdjustment(adjustmentConfig, "blue" , 0, 0,255);
|
||||||
adjustment->_rgbCyanAdjustment = *cyanAdjustment;
|
adjustment->_rgbCyanAdjustment = createRgbChannelAdjustment(adjustmentConfig, "cyan" , 0,255,255);
|
||||||
adjustment->_rgbMagentaAdjustment = *magentaAdjustment;
|
adjustment->_rgbMagentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", 255, 0,255);
|
||||||
adjustment->_rgbYellowAdjustment = *yellowAdjustment;
|
adjustment->_rgbYellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , 255,255, 0);
|
||||||
adjustment->_rgbTransform = *rgbTransform;
|
adjustment->_rgbTransform = createRgbTransform(adjustmentConfig);
|
||||||
|
|
||||||
// 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;
|
return adjustment;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <utils/ColorSys.h>
|
#include <utils/ColorSys.h>
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
void ColorSys::rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance)
|
void ColorSys::rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance)
|
||||||
{
|
{
|
||||||
QColor color(red,green,blue);
|
QColor color(red,green,blue);
|
||||||
|
@ -24,7 +24,6 @@ namespace FileUtils {
|
|||||||
|
|
||||||
bool removeDir(const QString& path, Logger* log)
|
bool removeDir(const QString& path, Logger* log)
|
||||||
{
|
{
|
||||||
//QDir dir(path);
|
|
||||||
if(!QDir(path).removeRecursively())
|
if(!QDir(path).removeRecursively())
|
||||||
{
|
{
|
||||||
Error(log, "Failed to remove directory: %s", QSTRING_CSTR(path));
|
Error(log, "Failed to remove directory: %s", QSTRING_CSTR(path));
|
||||||
@ -35,8 +34,7 @@ namespace FileUtils {
|
|||||||
|
|
||||||
bool fileExists(const QString& path, Logger* log, bool ignError)
|
bool fileExists(const QString& path, Logger* log, bool ignError)
|
||||||
{
|
{
|
||||||
QFile file(path);
|
if(!QFile::exists(path))
|
||||||
if(!file.exists())
|
|
||||||
{
|
{
|
||||||
ErrorIf((!ignError), log,"File does not exist: %s",QSTRING_CSTR(path));
|
ErrorIf((!ignError), log,"File does not exist: %s",QSTRING_CSTR(path));
|
||||||
return false;
|
return false;
|
||||||
|
@ -6,7 +6,7 @@ namespace Process {
|
|||||||
|
|
||||||
void restartHyperion(bool asNewProcess){}
|
void restartHyperion(bool asNewProcess){}
|
||||||
|
|
||||||
QByteArray command_exec(QString cmd, QByteArray data)
|
QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
|
||||||
{
|
{
|
||||||
return QSTRING_CSTR(QString());
|
return QSTRING_CSTR(QString());
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ void restartHyperion(bool asNewProcess)
|
|||||||
QByteArray command_exec(QString cmd, QByteArray data)
|
QByteArray command_exec(QString cmd, QByteArray data)
|
||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
QString result = "";
|
QString result;
|
||||||
|
|
||||||
std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
||||||
if (pipe)
|
if (pipe)
|
||||||
|
@ -26,7 +26,6 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algori
|
|||||||
output->blue = input.blue - output->white;
|
output->blue = input.blue - output->white;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WhiteAlgorithm::SUB_MIN_WARM_ADJUST:
|
case WhiteAlgorithm::SUB_MIN_WARM_ADJUST:
|
||||||
{
|
{
|
||||||
// http://forum.garagecube.com/viewtopic.php?t=10178
|
// http://forum.garagecube.com/viewtopic.php?t=10178
|
||||||
|
@ -133,7 +133,7 @@ void RgbTransform::updateBrightnessComponents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w )
|
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const
|
||||||
{
|
{
|
||||||
rgb = _brightness_rgb;
|
rgb = _brightness_rgb;
|
||||||
cmy = _brightness_cmy;
|
cmy = _brightness_cmy;
|
||||||
|
Loading…
Reference in New Issue
Block a user