summaryrefslogtreecommitdiff
path: root/qt/RGBController
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2017-06-04 16:26:56 +0930
committerdaniel-Jones <daniel@danieljon.es>2017-06-04 16:26:56 +0930
commitf66536d84b38aa0eb46e928fdaf13d7da790b2ee (patch)
treeba2624354136f3f0db3ec929d1eea15635527ba1 /qt/RGBController
parent2ce2f6376152402c3fc0d750720770b963a7d3cf (diff)
downloadRGB-Controller-f66536d84b38aa0eb46e928fdaf13d7da790b2ee.tar.gz
RGB-Controller-f66536d84b38aa0eb46e928fdaf13d7da790b2ee.zip
added HTML/JS/PHP pages/scripts to allow RGB changes over a web page. Integrated a server into the application to allow incoming connections and receive commands
Diffstat (limited to 'qt/RGBController')
-rw-r--r--qt/RGBController/.controllerwindow.cpp.swnbin0 -> 16384 bytes
-rw-r--r--qt/RGBController/Makefile45
-rwxr-xr-xqt/RGBController/RGBControllerbin136960 -> 143248 bytes
-rwxr-xr-xqt/RGBController/RGBController.pro6
-rwxr-xr-xqt/RGBController/controllerwindow.cpp39
-rwxr-xr-xqt/RGBController/controllerwindow.h15
-rw-r--r--qt/RGBController/controllerwindow.ui59
-rw-r--r--qt/RGBController/irc.cpp2
-rw-r--r--qt/RGBController/server.cpp54
-rw-r--r--qt/RGBController/server.h26
10 files changed, 210 insertions, 36 deletions
diff --git a/qt/RGBController/.controllerwindow.cpp.swn b/qt/RGBController/.controllerwindow.cpp.swn
new file mode 100644
index 0000000..bc195e4
--- /dev/null
+++ b/qt/RGBController/.controllerwindow.cpp.swn
Binary files differ
diff --git a/qt/RGBController/Makefile b/qt/RGBController/Makefile
index f615390..4f437ac 100644
--- a/qt/RGBController/Makefile
+++ b/qt/RGBController/Makefile
@@ -50,13 +50,17 @@ OBJECTS_DIR = ./
SOURCES = main.cpp \
controllerwindow.cpp \
- irc.cpp moc_controllerwindow.cpp \
- moc_irc.cpp
+ irc.cpp \
+ server.cpp moc_controllerwindow.cpp \
+ moc_irc.cpp \
+ moc_server.cpp
OBJECTS = main.o \
controllerwindow.o \
irc.o \
+ server.o \
moc_controllerwindow.o \
- moc_irc.o
+ moc_irc.o \
+ moc_server.o
DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
/usr/lib/qt/mkspecs/common/unix.conf \
/usr/lib/qt/mkspecs/common/linux.conf \
@@ -281,9 +285,11 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \
/usr/lib/qt/mkspecs/features/yacc.prf \
/usr/lib/qt/mkspecs/features/lex.prf \
RGBController.pro controllerwindow.h \
- irc.h main.cpp \
+ irc.h \
+ server.h main.cpp \
controllerwindow.cpp \
- irc.cpp
+ irc.cpp \
+ server.cpp
QMAKE_TARGET = RGBController
DESTDIR =
TARGET = RGBController
@@ -769,8 +775,8 @@ distdir: FORCE
@test -d $(DISTDIR) || mkdir -p $(DISTDIR)
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
$(COPY_FILE) --parents /usr/lib/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/
- $(COPY_FILE) --parents controllerwindow.h irc.h $(DISTDIR)/
- $(COPY_FILE) --parents main.cpp controllerwindow.cpp irc.cpp $(DISTDIR)/
+ $(COPY_FILE) --parents controllerwindow.h irc.h server.h $(DISTDIR)/
+ $(COPY_FILE) --parents main.cpp controllerwindow.cpp irc.cpp server.cpp $(DISTDIR)/
$(COPY_FILE) --parents controllerwindow.ui $(DISTDIR)/
@@ -803,10 +809,12 @@ compiler_moc_predefs_clean:
moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp
g++ -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -dM -E -o moc_predefs.h /usr/lib/qt/mkspecs/features/data/dummy.cpp
-compiler_moc_header_make_all: moc_controllerwindow.cpp moc_irc.cpp
+compiler_moc_header_make_all: moc_controllerwindow.cpp moc_irc.cpp moc_server.cpp
compiler_moc_header_clean:
- -$(DEL_FILE) moc_controllerwindow.cpp moc_irc.cpp
+ -$(DEL_FILE) moc_controllerwindow.cpp moc_irc.cpp moc_server.cpp
moc_controllerwindow.cpp: ui_controllerwindow.h \
+ irc.h \
+ server.h \
controllerwindow.h \
moc_predefs.h \
/usr/bin/moc
@@ -817,6 +825,11 @@ moc_irc.cpp: irc.h \
/usr/bin/moc
/usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I'/home/daniel_j/documents/school/2016 research project/RGBController/qt/RGBController' -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtSerialPort -I/usr/include/qt/QtNetwork -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include irc.h -o moc_irc.cpp
+moc_server.cpp: server.h \
+ moc_predefs.h \
+ /usr/bin/moc
+ /usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I'/home/daniel_j/documents/school/2016 research project/RGBController/qt/RGBController' -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtSerialPort -I/usr/include/qt/QtNetwork -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include server.h -o moc_server.cpp
+
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all: ui_controllerwindow.h
@@ -837,22 +850,32 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean compiler_ui
####### Compile
main.o: main.cpp controllerwindow.h \
- ui_controllerwindow.h
+ ui_controllerwindow.h \
+ irc.h \
+ server.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
controllerwindow.o: controllerwindow.cpp controllerwindow.h \
- ui_controllerwindow.h
+ ui_controllerwindow.h \
+ irc.h \
+ server.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o controllerwindow.o controllerwindow.cpp
irc.o: irc.cpp irc.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o irc.o irc.cpp
+server.o: server.cpp server.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o server.o server.cpp
+
moc_controllerwindow.o: moc_controllerwindow.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_controllerwindow.o moc_controllerwindow.cpp
moc_irc.o: moc_irc.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_irc.o moc_irc.cpp
+moc_server.o: moc_server.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_server.o moc_server.cpp
+
####### Install
install: FORCE
diff --git a/qt/RGBController/RGBController b/qt/RGBController/RGBController
index 7b54e8c..a6cfd3f 100755
--- a/qt/RGBController/RGBController
+++ b/qt/RGBController/RGBController
Binary files differ
diff --git a/qt/RGBController/RGBController.pro b/qt/RGBController/RGBController.pro
index 07060da..a4ed2e3 100755
--- a/qt/RGBController/RGBController.pro
+++ b/qt/RGBController/RGBController.pro
@@ -14,10 +14,12 @@ TEMPLATE = app
SOURCES += main.cpp\
controllerwindow.cpp \
- irc.cpp
+ irc.cpp \
+ server.cpp
HEADERS += controllerwindow.h \
- irc.h
+ irc.h \
+ server.h
FORMS += controllerwindow.ui
diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp
index 7c4f552..dd21ece 100755
--- a/qt/RGBController/controllerwindow.cpp
+++ b/qt/RGBController/controllerwindow.cpp
@@ -12,9 +12,12 @@ controllerWindow::controllerWindow(QWidget *parent) :
connect(ser, &QSerialPort::readyRead, this, &controllerWindow::read);
ptimer = new QTimer(this);
connect(ptimer, SIGNAL(timeout()), this, SLOT(ping()));
- connect (&ircbot, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString)));
+ connect(&ircbot, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString)));
+ connect(&srv, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString)));
pingtries = 0;
irccon = false;
+ pingcount = 0;
+ server_started = false;
/* disable buttons and widgets that should not be enabled yet, set slider values to 0 */
ui->disconnect_button->setEnabled(false);
ui->connect_button->setEnabled(false);
@@ -413,6 +416,7 @@ void controllerWindow::on_off_button_clicked()
ui->r_slider->setValue(0);
ui->g_slider->setValue(0);
ui->b_slider->setValue(0);
+ send("off");
}
void controllerWindow::on_set_preset_button_clicked()
@@ -616,6 +620,8 @@ void controllerWindow::ping()
send("ping\n");
tping = false;
QTimer::singleShot(1000, this, SLOT(check_ping()));
+ pingcount++;
+ ui->ping_count_label->setText("Ping: " + QString::number(pingcount));
}
void controllerWindow::check_ping()
@@ -658,6 +664,37 @@ void controllerWindow::on_irc_connect_button_clicked()
}
}
+void controllerWindow::on_server_start_button_clicked()
+{
+ if (!server_started)
+ {
+ if (srv.server_start())
+ {
+ server_started = true;
+ ui->server_start_button->setText("Stop server");
+ info_log("Server started");
+ }
+ else
+ {
+ info_log("Server could not start");
+ }
+ }
+
+ else if (server_started)
+ {
+ if (srv.server_stop())
+ {
+ server_started = false;
+ ui->server_start_button->setText("Start server");
+ info_log("Server stopped");
+ }
+ else
+ {
+ info_log("Server not not be stopped");
+ }
+ }
+}
+
void controllerWindow::cmdrecv(QString cmd)
{
qDebug() << "got cmd" << cmd;
diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h
index a9196d2..b36d70b 100755
--- a/qt/RGBController/controllerwindow.h
+++ b/qt/RGBController/controllerwindow.h
@@ -15,6 +15,7 @@
#include <QTimer>
#include "ui_controllerwindow.h"
#include "irc.h"
+#include "server.h"
namespace Ui {
class controllerWindow;
@@ -64,7 +65,7 @@ class controllerWindow : public QMainWindow
void cmdrecv(QString cmd);
private slots:
/* these slots are used to trigger button clicks and drop down items selections etc */
- void on_connect_button_clicked();
+ void on_connect_button_clicked();
void on_disconnect_button_clicked();
@@ -120,16 +121,22 @@ class controllerWindow : public QMainWindow
void on_bto_valueChanged(int arg1);
- void on_serial_send_button_clicked();
+ void on_serial_send_button_clicked();
void ping();
void check_ping();
- void on_irc_connect_button_clicked();
+ void on_irc_connect_button_clicked();
-private:
+ void on_server_start_button_clicked();
+
+
+ private:
Ui::controllerWindow *ui;
bool irccon;
irc ircbot;
+ server srv;
+ int pingcount;
+ bool server_started;
};
#endif // CONTROLLERWINDOW_H
diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui
index 63a91b1..0a10269 100644
--- a/qt/RGBController/controllerwindow.ui
+++ b/qt/RGBController/controllerwindow.ui
@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>364</width>
- <height>238</height>
+ <width>433</width>
+ <height>254</height>
</rect>
</property>
<property name="windowTitle">
@@ -21,7 +21,7 @@
<item row="7" column="1">
<widget class="QTabWidget" name="display_tab">
<property name="currentIndex">
- <number>4</number>
+ <number>5</number>
</property>
<widget class="QWidget" name="status_tab">
<attribute name="title">
@@ -528,21 +528,21 @@
</property>
</widget>
</item>
- <item row="1" column="0">
+ <item row="2" column="0">
<widget class="QLabel" name="irc_server_label">
<property name="text">
<string>Server</string>
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="5" column="0">
<widget class="QLineEdit" name="irc_server_input">
<property name="text">
<string>irc.danieljon.es</string>
</property>
</widget>
</item>
- <item row="3" column="1">
+ <item row="5" column="1">
<widget class="QSpinBox" name="irc_bot_spinbox">
<property name="maximumSize">
<size>
@@ -558,42 +558,42 @@
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="irc_channel_label">
<property name="text">
<string>Channel</string>
</property>
</widget>
</item>
- <item row="5" column="0">
+ <item row="7" column="0">
<widget class="QLineEdit" name="irc_channel_input">
<property name="text">
<string>#csgo</string>
</property>
</widget>
</item>
- <item row="6" column="0">
+ <item row="8" column="0">
<widget class="QLabel" name="irc_name_label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
- <item row="7" column="0">
+ <item row="9" column="0">
<widget class="QLineEdit" name="irc_name_input">
<property name="text">
<string>LightBot</string>
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QLabel" name="irc_port_label">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
- <item row="8" column="0">
+ <item row="10" column="0">
<widget class="QPushButton" name="irc_connect_button">
<property name="text">
<string>Connect</string>
@@ -602,15 +602,40 @@
</item>
</layout>
</widget>
+ <widget class="QWidget" name="server_tab">
+ <attribute name="title">
+ <string>Server</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_6">
+ <item row="0" column="0">
+ <layout class="QFormLayout" name="server_tab_layout">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="server_start_button">
+ <property name="text">
+ <string>Start server</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
<widget class="QWidget" name="log_tab">
<attribute name="title">
<string>Log</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
- <item row="2" column="0">
+ <item row="5" column="0">
<widget class="QLineEdit" name="serial_input"/>
</item>
- <item row="1" column="0">
+ <item row="5" column="1">
+ <widget class="QPushButton" name="serial_send_button">
+ <property name="text">
+ <string>Send</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" colspan="2">
<widget class="QTextEdit" name="info_log_textarea"/>
</item>
<item row="0" column="0">
@@ -620,10 +645,10 @@
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QPushButton" name="serial_send_button">
+ <item row="0" column="1">
+ <widget class="QLabel" name="ping_count_label">
<property name="text">
- <string>Send</string>
+ <string>Ping</string>
</property>
</widget>
</item>
diff --git a/qt/RGBController/irc.cpp b/qt/RGBController/irc.cpp
index 50f7fac..9c3c14d 100644
--- a/qt/RGBController/irc.cpp
+++ b/qt/RGBController/irc.cpp
@@ -33,7 +33,7 @@ void irc::read()
buf = "JOIN " + channel + "\r\n";
socket->write(buf.toUtf8());
}
- if (line.contains("!")) /* mostl ikely a message to handle */
+ if (line.contains("!")) /* most likely a message to handle */
handle(line);
if(socket->canReadLine())
read();
diff --git a/qt/RGBController/server.cpp b/qt/RGBController/server.cpp
new file mode 100644
index 0000000..85e43ee
--- /dev/null
+++ b/qt/RGBController/server.cpp
@@ -0,0 +1,54 @@
+#include "server.h"
+
+server::server(QObject *parent) : QObject(parent)
+{
+ srv = new QTcpServer();
+ connect(srv, SIGNAL(newConnection()), this, SLOT(new_connection()));
+}
+
+bool server::server_start()
+{
+ if (srv->listen(QHostAddress::Any, 3001))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool server::server_stop()
+{
+ srv->close();
+ if (srv->isListening())
+ return false;
+ return true;
+}
+
+void server::new_connection()
+{
+ QTcpSocket *socket;
+ socket = srv->nextPendingConnection();
+ socket->waitForReadyRead(3000);
+ handle(QString(socket->readAll()).remove(QRegExp("[\\n\\t\\r]")));
+ socket->close();
+ delete socket;
+}
+
+void server::handle(QString msg)
+{
+ if (msg.contains(";"))
+ {
+ QStringList tmp = msg.split(";");
+ for (int x = 0; x < tmp.size(); x++)
+ {
+ emit sendcmd(tmp.at(x));
+ }
+ }
+ else
+ {
+ emit sendcmd(msg);
+ }
+
+}
diff --git a/qt/RGBController/server.h b/qt/RGBController/server.h
new file mode 100644
index 0000000..8d46539
--- /dev/null
+++ b/qt/RGBController/server.h
@@ -0,0 +1,26 @@
+#ifndef SERVER_H
+#define SERVER_H
+
+#include <QTcpServer>
+#include <QTcpSocket>
+
+class server : public QObject
+{
+ Q_OBJECT
+ public:
+ explicit server(QObject *parent = 0);
+ bool server_start();
+ bool server_stop();
+ private:
+ QTcpServer *srv;
+ void handle(QString msg);
+ private slots:
+ void new_connection();
+signals:
+ void sendcmd(QString cmd);
+
+
+ public slots:
+};
+
+#endif // SERVER_H