Add functions / arguments to adjust LED's
This commit is contained in:
parent
02fc46794f
commit
d39d4a687c
@ -4,7 +4,7 @@ project(Hyperion_Grabber_X11_QT VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_BUILD_TYPE Desktop)
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED)
|
||||
|
||||
59
hgx11.cpp
59
hgx11.cpp
@ -2,13 +2,35 @@
|
||||
|
||||
// public
|
||||
|
||||
hgx11::hgx11(QString addr, QString port, QString scale, QString frameskip, QString inactiveTime)
|
||||
hgx11::hgx11(QHash<QString, QString> opts)
|
||||
{
|
||||
_addr_m = (addr.isEmpty() || addr.isNull()) ? "localhost" : addr;
|
||||
_port_m = (port.toInt() > 65535 || port.toInt() < 1) ? "19444" : port;
|
||||
_scale_m = (scale.toInt() < 1 || scale.toInt() > 1000) ? "4" : scale;
|
||||
_frameskip_m = (frameskip.toInt() > 0 && frameskip.toInt() < 256) ? frameskip : "0";
|
||||
_inactiveTime_m = (inactiveTime.toInt() > 0 ? QString::number(inactiveTime.toInt() * 1000) : "0");
|
||||
QHashIterator<QString, QString> i(opts);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if ((i.key() == "a" || i.key() == "address") && !(i.value().isNull() && i.value().isEmpty())) {
|
||||
_addr_m = i.value();
|
||||
} else if ((i.key() == "p" || i.key() == "port") && (i.value().toInt() > 0 && i.value().toInt() < 65536)) {
|
||||
_port_m = i.value();
|
||||
} else if ((i.key() == "s" || i.key() == "scale") && (i.value().toInt() > 0 && i.value().toInt() < 1001)) {
|
||||
_scale_m = i.value();
|
||||
} else if ((i.key() == "f" || i.key() == "frameskip") && (i.value().toInt() > 0 && i.value().toInt() < 256)) {
|
||||
_frameskip_m = i.value();
|
||||
} else if ((i.key() == "i" || i.key() == "inactive") && (i.value().toInt() > 0)) {
|
||||
_inactiveTime_m = QString::number(i.value().toInt() * 1000);
|
||||
} else if (i.key() == "r" || i.key() == "redadjust") {
|
||||
_redAdjust_m = _parseColorArr(i.value(), 1);
|
||||
} else if (i.key() == "g" || i.key() == "greenadjust") {
|
||||
_greenAdjust_m = _parseColorArr(i.value(), 1);
|
||||
} else if (i.key() == "b" || i.key() == "blueadjust") {
|
||||
_blueAdjust_m = _parseColorArr(i.value(), 1);
|
||||
} else if (i.key() == "t" || i.key() == "temperature") {
|
||||
_temperature_m = _parseColorArr(i.value(), 1);
|
||||
} else if (i.key() == "d" || i.key() == "threshold") {
|
||||
_threshold_m = _parseColorArr(i.value(), 0);
|
||||
}else if ((i.key() == "l" || i.key() == "transform") && _parseColorArr(i.value(), 0) != "") {
|
||||
_transform_m = i.value();
|
||||
}
|
||||
}
|
||||
|
||||
_grabber_p = new hgx11grab(_scale_m.toInt(), _frameskip_m.toUShort());
|
||||
_hclient_p = new hgx11net(_addr_m, _port_m.toUShort());
|
||||
@ -16,6 +38,7 @@ hgx11::hgx11(QString addr, QString port, QString scale, QString frameskip, QStri
|
||||
|
||||
_hclient_p->imgWidth = QString::number(_grabber_p->getDest_width());
|
||||
_hclient_p->imgHeight = QString::number(_grabber_p->getDest_height());
|
||||
_hclient_p->ledAdjustments(_redAdjust_m, _greenAdjust_m, _blueAdjust_m, _temperature_m, _threshold_m, _transform_m);
|
||||
|
||||
_damage_p->start();
|
||||
|
||||
@ -43,6 +66,30 @@ hgx11::~hgx11()
|
||||
_grabber_p = nullptr;
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
QString hgx11::_parseColorArr(QString value, bool isInt)
|
||||
{
|
||||
QStringList values = value.split(',');
|
||||
if (values.size() != 3) {
|
||||
return "";
|
||||
}
|
||||
QString retVal = "[";
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (isInt && (values.at(i).toInt() < 0 || values.at(i).toInt() > 255)) {
|
||||
return "";
|
||||
}
|
||||
if (!isInt && (values.at(i).toDouble() < 0.0 || values.at(i).toDouble() > 1.0)) {
|
||||
return "";
|
||||
}
|
||||
retVal.append(values.at(i));
|
||||
retVal.append(",");
|
||||
}
|
||||
retVal.chop(1);
|
||||
retVal.append("]");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// private slots
|
||||
|
||||
void hgx11::_sendImage()
|
||||
|
||||
20
hgx11.h
20
hgx11.h
@ -13,7 +13,7 @@ class hgx11 : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
hgx11(QString, QString, QString, QString, QString);
|
||||
hgx11(QHash<QString, QString>);
|
||||
~hgx11();
|
||||
|
||||
private:
|
||||
@ -22,14 +22,22 @@ private:
|
||||
hgx11net *_hclient_p;
|
||||
QTimer *_timer_p;
|
||||
|
||||
QString _addr_m;
|
||||
QString _port_m;
|
||||
QString _scale_m;
|
||||
QString _frameskip_m;
|
||||
QString _inactiveTime_m;
|
||||
QString _addr_m = "localhost";
|
||||
QString _port_m = "19444";
|
||||
QString _scale_m = "8";
|
||||
QString _frameskip_m = "0";
|
||||
QString _inactiveTime_m = "0";
|
||||
QString _redAdjust_m = "";
|
||||
QString _greenAdjust_m = "";
|
||||
QString _blueAdjust_m = "";
|
||||
QString _temperature_m = "";
|
||||
QString _threshold_m = "";
|
||||
QString _transform_m = "";
|
||||
QString _destWidth_m;
|
||||
QString _destHeight_m;
|
||||
|
||||
QString _parseColorArr(QString, bool);
|
||||
|
||||
private slots:
|
||||
void _sendImage();
|
||||
void _inActivity();
|
||||
|
||||
121
hgx11net.cpp
121
hgx11net.cpp
@ -21,17 +21,13 @@ hgx11net::~hgx11net()
|
||||
|
||||
void hgx11net::clearLeds()
|
||||
{
|
||||
if (!_isConnected()) {
|
||||
return;
|
||||
}
|
||||
_sock_p->write("{\"command\": \"clearall\"}\n");
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"command\": \"clearall\"}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
void hgx11net::setLedColor(quint8 R, quint8 G, quint8 B)
|
||||
{
|
||||
if (!_isConnected()) {
|
||||
return;
|
||||
}
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"color\":[");
|
||||
_cmd_m.append(QString::number(R));
|
||||
@ -39,8 +35,19 @@ void hgx11net::setLedColor(quint8 R, quint8 G, quint8 B)
|
||||
_cmd_m.append(QString::number(G));
|
||||
_cmd_m.append(",");
|
||||
_cmd_m.append(QString::number(B));
|
||||
_cmd_m.append("],\"command\":\"color\",\"priority\":100}}\n");
|
||||
_sock_p->write(_cmd_m);
|
||||
_cmd_m.append("],\"command\":\"color\",\"priority\":100}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
void hgx11net::ledAdjustments(QString red, QString green, QString blue, QString temp, QString thres, QString trans)
|
||||
{
|
||||
_redAdjust_m = red;
|
||||
_greenAdjust_m = green;
|
||||
_blueAdjust_m = blue;
|
||||
_temperature_m = temp;
|
||||
_threshold_m = thres;
|
||||
_transform_m = trans;
|
||||
_ledAdjustments();
|
||||
}
|
||||
|
||||
// private
|
||||
@ -52,6 +59,7 @@ bool hgx11net::_isConnected()
|
||||
_sock_p->reset();
|
||||
_connectHost();
|
||||
connected = (_sock_p->state() == QAbstractSocket::ConnectedState);
|
||||
_ledAdjustments();
|
||||
}
|
||||
return connected;
|
||||
}
|
||||
@ -65,6 +73,99 @@ void hgx11net::_connectHost()
|
||||
}
|
||||
}
|
||||
|
||||
void hgx11net::_sendCommand()
|
||||
{
|
||||
if (!_isConnected()) {
|
||||
return;
|
||||
}
|
||||
_sock_p->write(_cmd_m);
|
||||
}
|
||||
|
||||
void hgx11net::_ledAdjustments()
|
||||
{
|
||||
_colorAdjustmentType_m = 0;
|
||||
if (_redAdjust_m != "") {
|
||||
_colorAdjustmentType_m |= REDADJUST;
|
||||
}
|
||||
if (_greenAdjust_m != "") {
|
||||
_colorAdjustmentType_m |= GREENADJUST;
|
||||
}
|
||||
if (_blueAdjust_m != "") {
|
||||
_colorAdjustmentType_m |= BLUEADJUST;
|
||||
}
|
||||
_colorAdjustment();
|
||||
_thresholdAdjustment();
|
||||
_transformdAdjustment();
|
||||
}
|
||||
|
||||
void hgx11net::_colorAdjustment()
|
||||
{
|
||||
if (!_colorAdjustmentType_m) {
|
||||
return;
|
||||
}
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"adjustment\":{");
|
||||
if (_colorAdjustmentType_m & REDADJUST) {
|
||||
_cmd_m.append("\"redAdjust\":");
|
||||
_cmd_m.append(_redAdjust_m);
|
||||
_cmd_m.append(",");
|
||||
}
|
||||
if (_colorAdjustmentType_m & GREENADJUST) {
|
||||
_cmd_m.append("\"greenAdjust\":");
|
||||
_cmd_m.append(_greenAdjust_m);
|
||||
_cmd_m.append(",");
|
||||
}
|
||||
if (_colorAdjustmentType_m & BLUEADJUST) {
|
||||
_cmd_m.append("\"blueAdjust\":");
|
||||
_cmd_m.append(_blueAdjust_m);
|
||||
_cmd_m.append(",");
|
||||
}
|
||||
_cmd_m.chop(1); // remove trailing ,
|
||||
_cmd_m.append("},\"command\":\"adjustment\"}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
void hgx11net::_thresholdAdjustment()
|
||||
{
|
||||
if (_threshold_m == "") {
|
||||
return;
|
||||
}
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"command\":\"transform\",\"transform\":{\"threshold\":");
|
||||
_cmd_m.append(_threshold_m);
|
||||
_cmd_m.append("}}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
void hgx11net::_transformdAdjustment()
|
||||
{
|
||||
if (_transform_m == "") {
|
||||
return;
|
||||
}
|
||||
QStringList values = _transform_m.split(',');
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"command\":\"transform\",\"transform\":{\"luminanceGain\":");
|
||||
_cmd_m.append(values.at(0));
|
||||
_cmd_m.append(",\"luminanceMinimum\":");
|
||||
_cmd_m.append(values.at(1));
|
||||
_cmd_m.append(",\"saturationGain\":");
|
||||
_cmd_m.append(values.at(2));
|
||||
_cmd_m.append("}}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
void hgx11net::_temperatureAdjustment()
|
||||
{
|
||||
if (_temperature_m == "") {
|
||||
return;
|
||||
}
|
||||
_cmd_m.clear();
|
||||
_cmd_m.append("{\"command\":\"temperature\",\"temperature\":{\"correctionValues\":");
|
||||
_cmd_m.append(_temperature_m);
|
||||
_cmd_m.append("}}\n");
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
// public slots
|
||||
|
||||
void hgx11net::sendImage(QByteArray *imgdata)
|
||||
@ -80,5 +181,5 @@ void hgx11net::sendImage(QByteArray *imgdata)
|
||||
_cmd_m.append(",\"imagewidth\":");
|
||||
_cmd_m.append(imgWidth);
|
||||
_cmd_m.append(",\"priority\":100}\n");
|
||||
_sock_p->write(_cmd_m);
|
||||
_sendCommand();
|
||||
}
|
||||
|
||||
19
hgx11net.h
19
hgx11net.h
@ -11,6 +11,11 @@ class hgx11net : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {
|
||||
REDADJUST = 0x01,
|
||||
BLUEADJUST = 0x02,
|
||||
GREENADJUST = 0x04,
|
||||
};
|
||||
QString imgWidth;
|
||||
QString imgHeight;
|
||||
|
||||
@ -19,15 +24,29 @@ public:
|
||||
|
||||
void clearLeds();
|
||||
void setLedColor(quint8, quint8, quint8);
|
||||
void ledAdjustments(QString, QString, QString, QString, QString, QString);
|
||||
|
||||
private:
|
||||
QTcpSocket *_sock_p;
|
||||
QByteArray _cmd_m;
|
||||
QString _host_m;
|
||||
quint16 _port_m;
|
||||
QString _redAdjust_m = "";
|
||||
QString _greenAdjust_m = "";
|
||||
QString _blueAdjust_m = "";
|
||||
QString _temperature_m = "";
|
||||
QString _threshold_m = "";
|
||||
QString _transform_m = "";
|
||||
int _colorAdjustmentType_m = 0;
|
||||
|
||||
void _sendCommand();
|
||||
void _connectHost();
|
||||
bool _isConnected();
|
||||
void _ledAdjustments();
|
||||
void _colorAdjustment();
|
||||
void _thresholdAdjustment();
|
||||
void _transformdAdjustment();
|
||||
void _temperatureAdjustment();
|
||||
|
||||
public slots:
|
||||
void sendImage(QByteArray *);
|
||||
|
||||
41
main.cpp
41
main.cpp
@ -8,7 +8,9 @@ static QCoreApplication *qapp;
|
||||
|
||||
static void quit(int sig)
|
||||
{
|
||||
if (grab != nullptr) {
|
||||
grab->~hgx11();
|
||||
}
|
||||
qapp->exit(sig);
|
||||
}
|
||||
|
||||
@ -49,6 +51,36 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication::translate("main", "seconds before turning off LEDs")
|
||||
);
|
||||
parser.addOption(inactiveTime);
|
||||
QCommandLineOption redAdjust(QStringList() << "r" << "redadjust",
|
||||
QCoreApplication::translate("main", "Adjustment of the red color (requires 3 space seperated values between 0 and 255) (ex. \"255,10,0\")"),
|
||||
QCoreApplication::translate("main", "adjusts red color of LEDs")
|
||||
);
|
||||
parser.addOption(redAdjust);
|
||||
QCommandLineOption greenAdjust(QStringList() << "g" << "greenadjust",
|
||||
QCoreApplication::translate("main", "Adjustment of the green color (requires 3 space seperated values between 0 and 255) (ex. \"75,210,0\")"),
|
||||
QCoreApplication::translate("main", "adjusts green color of LEDs")
|
||||
);
|
||||
parser.addOption(greenAdjust);
|
||||
QCommandLineOption blueAdjust(QStringList() << "b" << "blueadjust",
|
||||
QCoreApplication::translate("main", "Adjustment of the blue color (requires 3 space seperated values between 0 and 255) (ex. \"0,10,160\")"),
|
||||
QCoreApplication::translate("main", "adjusts blue color of LEDs")
|
||||
);
|
||||
parser.addOption(blueAdjust);
|
||||
QCommandLineOption temperature(QStringList() << "t" << "temperature",
|
||||
QCoreApplication::translate("main", "Adjustment of the LED color temperature (requires 3 space seperated values between 0 and 255) (ex. \"255,255,250\")"),
|
||||
QCoreApplication::translate("main", "adjusts LED color temperature")
|
||||
);
|
||||
parser.addOption(temperature);
|
||||
QCommandLineOption threshold(QStringList() << "d" << "threshold",
|
||||
QCoreApplication::translate("main", "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0) (ex. \"0.0025,0.005,0.01\")"),
|
||||
QCoreApplication::translate("main", "adjusts LED threshold")
|
||||
);
|
||||
parser.addOption(threshold);
|
||||
QCommandLineOption transform(QStringList() << "l" << "transform",
|
||||
QCoreApplication::translate("main", "Adjusts the luminance / saturation of the leds values are in this order: luminanceGain, luminanceMin, saturationL (requires 3 space seperated values between 0.0 and 1.0) (ex. \"1.0,0.01,1.0\")"),
|
||||
QCoreApplication::translate("main", "adjusts luminance / saturation")
|
||||
);
|
||||
parser.addOption(transform);
|
||||
parser.process(*qapp);
|
||||
|
||||
if (!parser.isSet("address")) {
|
||||
@ -61,7 +93,14 @@ int main(int argc, char *argv[])
|
||||
parser.showHelp();
|
||||
}
|
||||
|
||||
grab = new hgx11(parser.value("address"), parser.value("port"), parser.value("scale"), parser.value("frameskip"), parser.value("inactive"));
|
||||
QHash<QString, QString> opts;
|
||||
QString optName;
|
||||
for (int i = 0; i < parser.optionNames().size(); i++) {
|
||||
optName = parser.optionNames().at(i);
|
||||
opts.insert(optName, parser.value(optName));
|
||||
}
|
||||
|
||||
grab = new hgx11(opts);
|
||||
return qapp->exec();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user