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/serial_communication.cpp | 58 ------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 qt/RGBController/serial_communication.cpp (limited to 'qt/RGBController/serial_communication.cpp') diff --git a/qt/RGBController/serial_communication.cpp b/qt/RGBController/serial_communication.cpp deleted file mode 100644 index f8bd66a..0000000 --- a/qt/RGBController/serial_communication.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "serial_communication.h" -#include "controllerwindow.h" -serial_communication::serial_communication() -{ - -} - -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); -} -- cgit v1.2.3