summaryrefslogtreecommitdiff
path: root/qt/RGBController/old_src
diff options
context:
space:
mode:
authordaniel-Jones <daniel@danieljon.es>2017-04-07 09:17:10 +0930
committerdaniel-Jones <daniel@danieljon.es>2017-04-07 09:17:10 +0930
commit9ff573e9fe4c40ffb342ce2b215042c39b518aeb (patch)
treee4168caacbb934b072da417275ea578d26229db6 /qt/RGBController/old_src
parent1189c8c2671b2463dbca7842a81adfe00c35549c (diff)
downloadRGB-Controller-9ff573e9fe4c40ffb342ce2b215042c39b518aeb.tar.gz
RGB-Controller-9ff573e9fe4c40ffb342ce2b215042c39b518aeb.zip
Merged source into one .cpp and .h. Added serial communication from the Arduino to the host computer. Added ping/pong system to maintain a connection, once 3 failed tries have occured, the connection is force closed, this restores the ui to a desired state. A ping is sent every 60 seconds and a response is required within one second. Some debug UI additions and code is still present, to be removed.
Diffstat (limited to 'qt/RGBController/old_src')
-rwxr-xr-xqt/RGBController/old_src/old.ui430
-rw-r--r--qt/RGBController/old_src/serial.cpp86
-rw-r--r--qt/RGBController/old_src/serial.h32
-rw-r--r--qt/RGBController/old_src/serial_communication.cpp64
-rw-r--r--qt/RGBController/old_src/serial_communication.h27
5 files changed, 639 insertions, 0 deletions
diff --git a/qt/RGBController/old_src/old.ui b/qt/RGBController/old_src/old.ui
new file mode 100755
index 0000000..f05209e
--- /dev/null
+++ b/qt/RGBController/old_src/old.ui
@@ -0,0 +1,430 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>controllerWindow</class>
+ <widget class="QMainWindow" name="controllerWindow">
+ <property name="windowModality">
+ <enum>Qt::WindowModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>325</width>
+ <height>686</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>RGB Controller</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="22" column="1">
+ <widget class="QPushButton" name="preset_delete_button">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QSlider" name="g_slider">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPushButton" name="connect_button">
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QSlider" name="r_slider">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="21" column="0">
+ <widget class="QLineEdit" name="preset_name_textbox"/>
+ </item>
+ <item row="19" column="0">
+ <widget class="QSlider" name="g_speed_slider">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>500</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QPushButton" name="red_button">
+ <property name="text">
+ <string>Red</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="arduino_port_dropdown"/>
+ </item>
+ <item row="14" column="0">
+ <widget class="QPushButton" name="speed_button">
+ <property name="text">
+ <string>Speed</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="rgb_label">
+ <property name="text">
+ <string>RGB colors</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <widget class="QSlider" name="b_slider">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="15" column="0">
+ <widget class="QSlider" name="b_speed_slider">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>500</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="1">
+ <widget class="QPushButton" name="set_preset_button">
+ <property name="text">
+ <string>Set</string>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="5" column="0">
+ <widget class="QSpinBox" name="bfrom">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>100</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="fade_label">
+ <property name="text">
+ <string>Fade</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QSpinBox" name="rfrom">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>100</number>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="3">
+ <widget class="QPushButton" name="blue_fade_button">
+ <property name="text">
+ <string>Blue toggle</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
+ <widget class="QPushButton" name="red_fade_button">
+ <property name="text">
+ <string>Red toggle</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="r_to_label">
+ <property name="text">
+ <string>to</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QSpinBox" name="gfrom">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>100</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="3">
+ <widget class="QPushButton" name="green_fade_button">
+ <property name="text">
+ <string>Green toggle</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="2">
+ <widget class="QSpinBox" name="bto">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>255</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="2">
+ <widget class="QSpinBox" name="gto">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>255</number>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLabel" name="_to_label">
+ <property name="text">
+ <string>to</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QLabel" name="g_to_label">
+ <property name="text">
+ <string>to</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QSpinBox" name="rto">
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ <property name="value">
+ <number>255</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="9" column="0">
+ <widget class="QLabel" name="presets_label">
+ <property name="text">
+ <string>Presets</string>
+ </property>
+ </widget>
+ </item>
+ <item row="23" column="0">
+ <widget class="QTextEdit" name="info_log_textarea"/>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPushButton" name="disconnect_button">
+ <property name="text">
+ <string>Disconnect</string>
+ </property>
+ </widget>
+ </item>
+ <item row="20" column="0">
+ <widget class="QLabel" name="r_speed_label">
+ <property name="text">
+ <string>Red speed</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="arduino_port_label">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Arduino port</string>
+ </property>
+ </widget>
+ </item>
+ <item row="18" column="0">
+ <widget class="QLabel" name="b_speed_label">
+ <property name="text">
+ <string>Blue speed</string>
+ </property>
+ </widget>
+ </item>
+ <item row="17" column="0">
+ <widget class="QSlider" name="speed_slider">
+ <property name="minimum">
+ <number>10</number>
+ </property>
+ <property name="maximum">
+ <number>500</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="arduino_status_label">
+ <property name="text">
+ <string>&lt;font color = red&gt;Disconnected&lt;/font&gt;</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="QPushButton" name="off_button">
+ <property name="text">
+ <string>Off</string>
+ </property>
+ </widget>
+ </item>
+ <item row="16" column="0">
+ <widget class="QSlider" name="r_speed_slider">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>500</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="status_label">
+ <property name="text">
+ <string>Status</string>
+ </property>
+ </widget>
+ </item>
+ <item row="21" column="1">
+ <widget class="QPushButton" name="preset_save_button">
+ <property name="text">
+ <string>Save</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0">
+ <widget class="QComboBox" name="presets_dropdown">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1">
+ <widget class="QPushButton" name="blue_button">
+ <property name="text">
+ <string>Blue</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="refresh_port_button">
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QPushButton" name="green_button">
+ <property name="text">
+ <string>Green</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="0">
+ <widget class="QPushButton" name="reload_preset_button">
+ <property name="text">
+ <string>Reload</string>
+ </property>
+ </widget>
+ </item>
+ <item row="22" column="0">
+ <widget class="QLabel" name="info_log_label">
+ <property name="text">
+ <string>Information log</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="0">
+ <widget class="QLabel" name="g_speed_label">
+ <property name="text">
+ <string>Green speed</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/qt/RGBController/old_src/serial.cpp b/qt/RGBController/old_src/serial.cpp
new file mode 100644
index 0000000..f3f4f1e
--- /dev/null
+++ b/qt/RGBController/old_src/serial.cpp
@@ -0,0 +1,86 @@
+#include "serial.h"
+#include "controllerwindow.h"
+serial::serial(QObject *parent) : QObject(parent)
+{
+ ser = new QSerialPort(this);
+ connect(ser, &QSerialPort::readyRead, this, &serial::read);
+
+}
+
+bool serial::serial_connect(QString port)
+{
+ /* this function will attempt a ser.connection if we are not already connected */
+ if (!ser->isOpen())
+ {
+ ser->setPortName(port);
+ ser->setBaudRate(QSerialPort::Baud9600);
+ ser->setDataBits(QSerialPort::Data8);
+ ser->setParity(QSerialPort::NoParity);
+ ser->setStopBits(QSerialPort::OneStop);
+ ser->setFlowControl(QSerialPort::NoFlowControl);
+ ser->open(QIODevice::ReadWrite);
+ ser->waitForBytesWritten(9000);
+ if (ser->isWritable()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool serial::serial_disconnect()
+{
+ /* this function disconnects from the serial port if it is connected already */
+ if (ser->isOpen())
+ {
+ ser->close();
+ return true;
+ }
+ return false;
+}
+
+void serial::send(QString com)
+{
+ data = "";
+ //qDebug() << com;
+ data.append(com + "\n");
+ if (ser->isOpen())
+ ser->write(data);
+}
+
+void serial::rgb_change(int r, int g, int b)
+{
+ // NOT USED FUNCTION
+
+ /* here we send our rgb values to the serial port */
+ data = "";
+ /* the 0 is a hack, i need to look into it at some point */
+ data.append("red=" + QString::number(r) + "," + QString::number(g) + "," + QString::number(b) + "\n");
+ if (ser->isOpen())
+ ser->write(data);
+}
+
+void serial::read()
+{
+ if (serdata[serdata.size() - 1] != '\n')
+ serdata = serdata + ser->readAll();
+ if (serdata[serdata.size() - 1] == '\n')
+ {
+ qDebug() << "got data" << serdata;
+ parse(QString(serdata));
+ serdata = "";
+ }
+}
+
+void serial::parse(QString message)
+{
+ if (message.contains("="))
+ {
+ QString command = message.split("=")[0];
+ QString text = message.split("=")[1];
+ qDebug() << "command:" << command << "message:" << text;
+
+// win->info_log(text);
+ //((controllerWindow*)(parent()))->info_log("tesT");
+
+ }
+}
diff --git a/qt/RGBController/old_src/serial.h b/qt/RGBController/old_src/serial.h
new file mode 100644
index 0000000..6403887
--- /dev/null
+++ b/qt/RGBController/old_src/serial.h
@@ -0,0 +1,32 @@
+#ifndef SERIAL_H
+#define SERIAL_H
+
+#include <QObject>
+#include <QSerialPort>
+#include <QSerialPortInfo>
+#include <QDebug>
+
+class serial : public QObject
+{
+ Q_OBJECT
+ public:
+ explicit serial(QObject *parent = 0);
+
+
+ /* function declares */
+ bool serial_connect(QString port);
+ bool serial_disconnect();
+ void rgb_change(int r, int g, int b);
+ void send(QString com);
+ void parse(QString message);
+ /* variables */
+ QString port_name;
+ //QSerialPort ser;
+ QSerialPort *ser;
+ QByteArray data;
+ QByteArray serdata;
+ private slots:
+ void read();
+};
+
+#endif // SERIAL_H
diff --git a/qt/RGBController/old_src/serial_communication.cpp b/qt/RGBController/old_src/serial_communication.cpp
new file mode 100644
index 0000000..32d4863
--- /dev/null
+++ b/qt/RGBController/old_src/serial_communication.cpp
@@ -0,0 +1,64 @@
+#include "serial_communication.h"
+#include "controllerwindow.h"
+
+serial_communication::serial_communication()
+{
+ qDebug() << "serial test";
+}
+
+bool serial_communication::serial_connect(QString port)
+{
+ /* this function will attempt a serial connection if we are not already connected */
+ if (!serial.isOpen())
+ {
+ serial.setPortName(port);
+ serial.setBaudRate(QSerialPort::Baud9600);
+ serial.setDataBits(QSerialPort::Data8);
+ serial.setParity(QSerialPort::NoParity);
+ serial.setStopBits(QSerialPort::OneStop);
+ serial.setFlowControl(QSerialPort::NoFlowControl);
+ serial.open(QIODevice::ReadWrite);
+ serial.waitForBytesWritten(9000);
+ if (serial.isWritable()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool serial_communication::serial_disconnect()
+{
+ /* this function disconnects from the serial port if it is connected already */
+ if (serial.isOpen())
+ {
+ serial.close();
+ return true;
+ }
+ return false;
+}
+
+void serial_communication::send(QString com)
+{
+ data = "";
+ //qDebug() << com;
+ data.append(com + "\n");
+ if (serial.isOpen())
+ serial.write(data);
+}
+
+void serial_communication::rgb_change(int r, int g, int b)
+{
+ // NOT USED FUNCTION
+
+ /* here we send our rgb values to the serial port */
+ data = "";
+ /* the 0 is a hack, i need to look into it at some point */
+ data.append("red=" + QString::number(r) + "," + QString::number(g) + "," + QString::number(b) + "\n");
+ if (serial.isOpen())
+ serial.write(data);
+}
+
+void serial_communication::read()
+{
+ qDebug() << "serial read";
+}
diff --git a/qt/RGBController/old_src/serial_communication.h b/qt/RGBController/old_src/serial_communication.h
new file mode 100644
index 0000000..5f2826c
--- /dev/null
+++ b/qt/RGBController/old_src/serial_communication.h
@@ -0,0 +1,27 @@
+#ifndef SERIAL_COMMUNICATION_H
+#define SERIAL_COMMUNICATION_H
+
+/* includes */
+#include <QSerialPort>
+#include <QSerialPortInfo>
+#include <QDebug>
+
+
+class serial_communication
+{
+ public:
+ /* function declares */
+ serial_communication();
+ bool serial_connect(QString port);
+ bool serial_disconnect();
+ void rgb_change(int r, int g, int b);
+ void send(QString com);
+ /* variables */
+ QString port_name;
+ QSerialPort serial;
+ QByteArray data;
+ private slots:
+ void read();
+};
+
+#endif // SERIAL_COMMUNICATION_H