From 9ff573e9fe4c40ffb342ce2b215042c39b518aeb Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 7 Apr 2017 09:17:10 +0930 Subject: 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. --- qt/RGBController/old_src/old.ui | 430 ++++++++++++++++++++++ qt/RGBController/old_src/serial.cpp | 86 +++++ qt/RGBController/old_src/serial.h | 32 ++ qt/RGBController/old_src/serial_communication.cpp | 64 ++++ qt/RGBController/old_src/serial_communication.h | 27 ++ 5 files changed, 639 insertions(+) create mode 100755 qt/RGBController/old_src/old.ui create mode 100644 qt/RGBController/old_src/serial.cpp create mode 100644 qt/RGBController/old_src/serial.h create mode 100644 qt/RGBController/old_src/serial_communication.cpp create mode 100644 qt/RGBController/old_src/serial_communication.h (limited to 'qt/RGBController/old_src') 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 @@ + + + controllerWindow + + + Qt::WindowModal + + + + 0 + 0 + 325 + 686 + + + + RGB Controller + + + + + + + Delete + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + 255 + + + Qt::Horizontal + + + + + + + Connect + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + 255 + + + Qt::Horizontal + + + + + + + + + + 1 + + + 500 + + + Qt::Horizontal + + + + + + + Red + + + + + + + + + + Speed + + + + + + + RGB colors + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + 255 + + + Qt::Horizontal + + + + + + + 1 + + + 500 + + + Qt::Horizontal + + + + + + + Set + + + + + + + + + 255 + + + 100 + + + + + + + Fade + + + + + + + 255 + + + 100 + + + + + + + Blue toggle + + + + + + + Red toggle + + + + + + + to + + + + + + + 255 + + + 100 + + + + + + + Green toggle + + + + + + + 255 + + + 255 + + + + + + + 255 + + + 255 + + + + + + + to + + + + + + + to + + + + + + + 255 + + + 255 + + + + + + + + + Presets + + + + + + + + + + Disconnect + + + + + + + Red speed + + + + + + + + 120 + 0 + + + + Arduino port + + + + + + + Blue speed + + + + + + + 10 + + + 500 + + + Qt::Horizontal + + + + + + + <font color = red>Disconnected</font> + + + + + + + Off + + + + + + + 1 + + + 500 + + + Qt::Horizontal + + + + + + + Status + + + + + + + Save + + + + + + + + 120 + 0 + + + + + + + + Blue + + + + + + + Refresh + + + + + + + Green + + + + + + + Reload + + + + + + + Information log + + + + + + + Green speed + + + + + + + + + + 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 +#include +#include +#include + +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 +#include +#include + + +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 -- cgit v1.2.3