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. --- arduino/rgb/.rgb.ino.swo | Bin 20480 -> 0 bytes arduino/rgb/rgb.ino | 4 +- qt/RGBController/Makefile | 30 +- qt/RGBController/RGBController | Bin 97400 -> 107032 bytes qt/RGBController/RGBController.pro | 7 +- qt/RGBController/RGBController.pro.user | 2 +- qt/RGBController/controllerwindow.cpp | 335 +++++++++++----- qt/RGBController/controllerwindow.h | 87 +++-- qt/RGBController/controllerwindow.o | Bin 105712 -> 132072 bytes qt/RGBController/controllerwindow.ui | 18 +- qt/RGBController/main.o | Bin 3176 -> 3176 bytes qt/RGBController/moc_controllerwindow.cpp | 87 +++-- qt/RGBController/moc_controllerwindow.o | Bin 16920 -> 17448 bytes qt/RGBController/moc_predefs.h | 2 +- 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 ++ qt/RGBController/serial_communication.cpp | 58 --- qt/RGBController/serial_communication.h | 25 -- qt/RGBController/serial_communication.o | Bin 10376 -> 0 bytes qt/RGBController/ui_controllerwindow.h | 27 +- qt/build-RGBController-Desktop-Debug/Makefile | 27 +- qt/build-RGBController-Desktop-Debug/RGBController | Bin 1384272 -> 1614688 bytes qt/build-RGBController-Desktop-Debug/moc_predefs.h | 2 +- .../moc_serial.cpp | 114 ++++++ qt/console/Makefile | 1 + qt/console/main.cpp | 6 +- qt/console/rgb | Bin 21056 -> 25360 bytes 30 files changed, 1152 insertions(+), 319 deletions(-) delete mode 100644 arduino/rgb/.rgb.ino.swo mode change 100755 => 100644 qt/RGBController/controllerwindow.ui 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 delete mode 100644 qt/RGBController/serial_communication.cpp delete mode 100644 qt/RGBController/serial_communication.h delete mode 100644 qt/RGBController/serial_communication.o create mode 100644 qt/build-RGBController-Desktop-Debug/moc_serial.cpp diff --git a/arduino/rgb/.rgb.ino.swo b/arduino/rgb/.rgb.ino.swo deleted file mode 100644 index 2ab1ac4..0000000 Binary files a/arduino/rgb/.rgb.ino.swo and /dev/null differ diff --git a/arduino/rgb/rgb.ino b/arduino/rgb/rgb.ino index 195eff2..aa35aa0 100644 --- a/arduino/rgb/rgb.ino +++ b/arduino/rgb/rgb.ino @@ -104,7 +104,6 @@ void parse(String com) { String p1; String p2; - p1 = com.substring(0, com.indexOf("=")); p2 = com.substring(com.indexOf("=") + 1); @@ -176,6 +175,8 @@ void parse(String com) bf = p2.toInt(); if (p1.equalsIgnoreCase("bt")) bt = p2.toInt(); + if (p1.equalsIgnoreCase("ping")) + Serial.write("ping=pong\n"); } String line; @@ -202,6 +203,5 @@ void loop() { line += c; } - } } diff --git a/qt/RGBController/Makefile b/qt/RGBController/Makefile index efaa9b4..415befe 100644 --- a/qt/RGBController/Makefile +++ b/qt/RGBController/Makefile @@ -49,11 +49,9 @@ OBJECTS_DIR = ./ ####### Files SOURCES = main.cpp \ - controllerwindow.cpp \ - serial_communication.cpp moc_controllerwindow.cpp + controllerwindow.cpp moc_controllerwindow.cpp OBJECTS = main.o \ controllerwindow.o \ - serial_communication.o \ moc_controllerwindow.o DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/common/unix.conf \ @@ -166,6 +164,8 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/modules/qt_lib_multimediawidgets_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_network.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_network_private.pri \ + /usr/lib/qt/mkspecs/modules/qt_lib_networkauth.pri \ + /usr/lib/qt/mkspecs/modules/qt_lib_networkauth_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_nfc.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_nfc_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_opengl.pri \ @@ -276,10 +276,8 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/features/exceptions.prf \ /usr/lib/qt/mkspecs/features/yacc.prf \ /usr/lib/qt/mkspecs/features/lex.prf \ - RGBController.pro controllerwindow.h \ - serial_communication.h main.cpp \ - controllerwindow.cpp \ - serial_communication.cpp + RGBController.pro controllerwindow.h main.cpp \ + controllerwindow.cpp QMAKE_TARGET = RGBController DESTDIR = TARGET = RGBController @@ -402,6 +400,8 @@ Makefile: RGBController.pro /usr/lib/qt/mkspecs/linux-g++/qmake.conf /usr/lib/qt /usr/lib/qt/mkspecs/modules/qt_lib_multimediawidgets_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_network.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_network_private.pri \ + /usr/lib/qt/mkspecs/modules/qt_lib_networkauth.pri \ + /usr/lib/qt/mkspecs/modules/qt_lib_networkauth_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_nfc.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_nfc_private.pri \ /usr/lib/qt/mkspecs/modules/qt_lib_opengl.pri \ @@ -630,6 +630,8 @@ Makefile: RGBController.pro /usr/lib/qt/mkspecs/linux-g++/qmake.conf /usr/lib/qt /usr/lib/qt/mkspecs/modules/qt_lib_multimediawidgets_private.pri: /usr/lib/qt/mkspecs/modules/qt_lib_network.pri: /usr/lib/qt/mkspecs/modules/qt_lib_network_private.pri: +/usr/lib/qt/mkspecs/modules/qt_lib_networkauth.pri: +/usr/lib/qt/mkspecs/modules/qt_lib_networkauth_private.pri: /usr/lib/qt/mkspecs/modules/qt_lib_nfc.pri: /usr/lib/qt/mkspecs/modules/qt_lib_nfc_private.pri: /usr/lib/qt/mkspecs/modules/qt_lib_opengl.pri: @@ -761,8 +763,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 serial_communication.h $(DISTDIR)/ - $(COPY_FILE) --parents main.cpp controllerwindow.cpp serial_communication.cpp $(DISTDIR)/ + $(COPY_FILE) --parents controllerwindow.h $(DISTDIR)/ + $(COPY_FILE) --parents main.cpp controllerwindow.cpp $(DISTDIR)/ $(COPY_FILE) --parents controllerwindow.ui $(DISTDIR)/ @@ -798,8 +800,7 @@ moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp compiler_moc_header_make_all: moc_controllerwindow.cpp compiler_moc_header_clean: -$(DEL_FILE) moc_controllerwindow.cpp -moc_controllerwindow.cpp: serial_communication.h \ - ui_controllerwindow.h \ +moc_controllerwindow.cpp: ui_controllerwindow.h \ controllerwindow.h \ moc_predefs.h \ /usr/bin/moc @@ -825,20 +826,13 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean compiler_ui ####### Compile main.o: main.cpp controllerwindow.h \ - serial_communication.h \ ui_controllerwindow.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp controllerwindow.o: controllerwindow.cpp controllerwindow.h \ - serial_communication.h \ ui_controllerwindow.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o controllerwindow.o controllerwindow.cpp -serial_communication.o: serial_communication.cpp serial_communication.h \ - controllerwindow.h \ - ui_controllerwindow.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o serial_communication.o serial_communication.cpp - moc_controllerwindow.o: moc_controllerwindow.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_controllerwindow.o moc_controllerwindow.cpp diff --git a/qt/RGBController/RGBController b/qt/RGBController/RGBController index 98307b6..318ea1e 100755 Binary files a/qt/RGBController/RGBController and b/qt/RGBController/RGBController differ diff --git a/qt/RGBController/RGBController.pro b/qt/RGBController/RGBController.pro index d075466..2496348 100755 --- a/qt/RGBController/RGBController.pro +++ b/qt/RGBController/RGBController.pro @@ -13,10 +13,9 @@ TEMPLATE = app SOURCES += main.cpp\ - controllerwindow.cpp \ - serial_communication.cpp + controllerwindow.cpp -HEADERS += controllerwindow.h \ - serial_communication.h + +HEADERS += controllerwindow.h FORMS += controllerwindow.ui diff --git a/qt/RGBController/RGBController.pro.user b/qt/RGBController/RGBController.pro.user index f76531e..5074773 100755 --- a/qt/RGBController/RGBController.pro.user +++ b/qt/RGBController/RGBController.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp index a0e9b52..cfc2428 100755 --- a/qt/RGBController/controllerwindow.cpp +++ b/qt/RGBController/controllerwindow.cpp @@ -4,10 +4,15 @@ controllerWindow::controllerWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::controllerWindow) { - /* TODO convert to QStandardPaths::standardLocations(QStandardPaths::AppDataLocation) */ /* this is our setup function, we set things up here */ ui->setupUi(this); info_log("RGB Controller started"); + /* serial */ + ser = new QSerialPort(this); + connect(ser, &QSerialPort::readyRead, this, &controllerWindow::read); + ptimer = new QTimer(this); + connect(ptimer, SIGNAL(timeout()), this, SLOT(ping())); + pingtries = 0; /* 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); @@ -27,32 +32,32 @@ controllerWindow::controllerWindow(QWidget *parent) : ui->r_slider->setValue(0); ui->g_slider->setValue(0); ui->b_slider->setValue(0); - ui->red_fade_button->setEnabled(false); - ui->green_fade_button->setEnabled(false); - ui->blue_fade_button->setEnabled(false); - ui->speed_button->setEnabled(false); - ui->rfrom->setEnabled(false); - ui->rto->setEnabled(false); - ui->gfrom->setEnabled(false); - ui->gto->setEnabled(false); - ui->bfrom->setEnabled(false); - ui->bto->setEnabled(false); - ui->r_speed_slider->setEnabled(false); - ui->g_speed_slider->setEnabled(false); - ui->b_speed_slider->setEnabled(false); - ui->speed_slider->setEnabled(false); - ui->r_speed_slider->setValue(0); - ui->g_speed_slider->setValue(0); - ui->b_speed_slider->setValue(0); - ui->speed_slider->setValue(0); - ui->rfrom->setValue(0); - ui->rto->setValue(0); - ui->gfrom->setValue(0); - ui->gto->setValue(0); - ui->bfrom->setValue(0); - ui->bto->setValue(0); - presetsfile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/presets.txt"; - tempfile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tmp.file"; + ui->red_fade_button->setEnabled(false); + ui->green_fade_button->setEnabled(false); + ui->blue_fade_button->setEnabled(false); + ui->speed_button->setEnabled(false); + ui->rfrom->setEnabled(false); + ui->rto->setEnabled(false); + ui->gfrom->setEnabled(false); + ui->gto->setEnabled(false); + ui->bfrom->setEnabled(false); + ui->bto->setEnabled(false); + ui->r_speed_slider->setEnabled(false); + ui->g_speed_slider->setEnabled(false); + ui->b_speed_slider->setEnabled(false); + ui->speed_slider->setEnabled(false); + ui->r_speed_slider->setValue(0); + ui->g_speed_slider->setValue(0); + ui->b_speed_slider->setValue(0); + ui->speed_slider->setValue(0); + ui->rfrom->setValue(100); + ui->rto->setValue(255); + ui->gfrom->setValue(100); + ui->gto->setValue(255); + ui->bfrom->setValue(100); + ui->bto->setValue(255); + presetsfile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/presets.txt"; + tempfile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tmp.file"; /* set some crucial ints */ preset_index = 0, r = 0, g = 0, b = 0; /* populate our serial port dropdown box */ @@ -111,7 +116,7 @@ void controllerWindow::load_presets() * -> add [0] to dropdown (name), add [1] to an array that stores all the values */ - QFile inputFile(presetsfile); + QFile inputFile(presetsfile); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); @@ -128,7 +133,7 @@ void controllerWindow::load_presets() info_log("Presets loaded"); } else { - show_msgbox("Unable to load the presets file.\n"); + show_msgbox("Unable to load the presets file.\n"); info_log("Presets file not found."); } } @@ -136,9 +141,9 @@ void controllerWindow::load_presets() void controllerWindow::save_preset(QString name) { /* this function will save our preset to file */ - if (!QDir("Folder").exists()) - QDir().mkdir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - QFile file(presetsfile); + if (!QDir("Folder").exists()) + QDir().mkdir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + QFile file(presetsfile); if(!file.open(QIODevice::Append)) { show_msgbox("Fatal error opening presets for appending text."); @@ -160,7 +165,7 @@ void controllerWindow::delete_preset(QString name) { /* * here we will delete a preset from the presets file - * process: + * process: * retrieve preset name * go through preset file line by line and write it to a seperate tmp file * if the [0] of split('=') equals the preset name, don't write it to the tmp file @@ -172,8 +177,8 @@ void controllerWindow::delete_preset(QString name) { case QMessageBox::Ok: { - info_log("deleting preset: " + name); - QFile file(tempfile); + info_log("deleting preset: " + name); + QFile file(tempfile); if(!file.open(QIODevice::Append)) { show_msgbox("Fatal error opening temp file for writing"); @@ -190,8 +195,8 @@ void controllerWindow::delete_preset(QString name) } file.close(); /* remove the current presets file then rename the temp file to presets.txt */ - QFile::remove(presetsfile); - QFile::rename(tempfile, presetsfile); + QFile::remove(presetsfile); + QFile::rename(tempfile, presetsfile); /* reload presets into memory and clear the drop down box */ ui->presets_dropdown->clear(); presets.clear(); @@ -213,8 +218,8 @@ void controllerWindow::delete_preset(QString name) void controllerWindow::serial_rgb_change(int r, int g, int b) { - /* un used function */ - portf.rgb_change(r, g, b); + /* un used function */ + rgb_change(r, g, b); } void controllerWindow::show_msgbox(QString message) @@ -243,13 +248,14 @@ int controllerWindow::show_question_box(QString message, QString omessage) void controllerWindow::on_connect_button_clicked() { - /* + /* * here we need to call our serial port connect function * if our connection is sucessful we need to enable and disable a few buttons and widgets * we must also change our rgb sliders etc */ + pingtries = 0; port = ui->arduino_port_dropdown->currentText(); - if (portf.serial_connect(port)) + if (serial_connect(port)) { // if true we are connected info_log("Connection established"); ui->arduino_status_label->setText("Connected"); @@ -271,20 +277,21 @@ void controllerWindow::on_connect_button_clicked() ui->b_slider->setEnabled(true); ui->refresh_port_button->setEnabled(false); ui->arduino_port_dropdown->setEnabled(false); - ui->red_fade_button->setEnabled(true); - ui->green_fade_button->setEnabled(true); - ui->blue_fade_button->setEnabled(true); - ui->speed_button->setEnabled(true); - ui->rfrom->setEnabled(true); - ui->rto->setEnabled(true); - ui->gfrom->setEnabled(true); - ui->gto->setEnabled(true); - ui->bfrom->setEnabled(true); - ui->bto->setEnabled(true); - ui->r_speed_slider->setEnabled(true); - ui->g_speed_slider->setEnabled(true); - ui->b_speed_slider->setEnabled(true); - ui->speed_slider->setEnabled(true); + ui->red_fade_button->setEnabled(true); + ui->green_fade_button->setEnabled(true); + ui->blue_fade_button->setEnabled(true); + ui->speed_button->setEnabled(true); + ui->rfrom->setEnabled(true); + ui->rto->setEnabled(true); + ui->gfrom->setEnabled(true); + ui->gto->setEnabled(true); + ui->bfrom->setEnabled(true); + ui->bto->setEnabled(true); + ui->r_speed_slider->setEnabled(true); + ui->g_speed_slider->setEnabled(true); + ui->b_speed_slider->setEnabled(true); + ui->speed_slider->setEnabled(true); + ptimer->start(60000); } else { info_log("Unable to connect (port in use?)"); @@ -298,7 +305,7 @@ void controllerWindow::on_disconnect_button_clicked() * here we will attempt to disconnect from our serial port * we will also enable/disable some buttons and widgets and set slider values to 0 */ - if (portf.serial_disconnect()) + if (serial_disconnect()) { info_log("Disconnected from serial port"); ui->arduino_status_label->setText("Disconnected"); @@ -322,30 +329,30 @@ void controllerWindow::on_disconnect_button_clicked() ui->r_slider->setValue(0); ui->g_slider->setValue(0); ui->b_slider->setValue(0); - ui->red_fade_button->setEnabled(false); - ui->green_fade_button->setEnabled(false); - ui->blue_fade_button->setEnabled(false); - ui->speed_button->setEnabled(false); - ui->rfrom->setEnabled(false); - ui->rto->setEnabled(false); - ui->gfrom->setEnabled(false); - ui->gto->setEnabled(false); - ui->bfrom->setEnabled(false); - ui->bto->setEnabled(false); - ui->r_speed_slider->setEnabled(false); - ui->g_speed_slider->setEnabled(false); - ui->b_speed_slider->setEnabled(false); - ui->speed_slider->setEnabled(false); - ui->r_speed_slider->setValue(0); - ui->g_speed_slider->setValue(0); - ui->b_speed_slider->setValue(0); - ui->speed_slider->setValue(0); - ui->rfrom->setValue(0); - ui->rto->setValue(0); - ui->gfrom->setValue(0); - ui->gto->setValue(0); - ui->bfrom->setValue(0); - ui->bto->setValue(0); + ui->red_fade_button->setEnabled(false); + ui->green_fade_button->setEnabled(false); + ui->blue_fade_button->setEnabled(false); + ui->speed_button->setEnabled(false); + ui->rfrom->setEnabled(false); + ui->rto->setEnabled(false); + ui->gfrom->setEnabled(false); + ui->gto->setEnabled(false); + ui->bfrom->setEnabled(false); + ui->bto->setEnabled(false); + ui->r_speed_slider->setEnabled(false); + ui->g_speed_slider->setEnabled(false); + ui->b_speed_slider->setEnabled(false); + ui->speed_slider->setEnabled(false); + ui->r_speed_slider->setValue(0); + ui->g_speed_slider->setValue(0); + ui->b_speed_slider->setValue(0); + ui->speed_slider->setValue(0); + ui->rfrom->setValue(100); + ui->rto->setValue(255); + ui->gfrom->setValue(100); + ui->gto->setValue(255); + ui->bfrom->setValue(100); + ui->bto->setValue(255); } else { /* I have no clue how we'd get here */ @@ -369,22 +376,22 @@ void controllerWindow::on_reload_preset_button_clicked() void controllerWindow::on_r_slider_valueChanged(int value) { r = value; - //serial_rgb_change(r, g, b); - portf.send("red=" + QString::number(r)); + //serial_rgb_change(r, g, b); + send("red=" + QString::number(r)); } void controllerWindow::on_g_slider_valueChanged(int value) { g = value; - //serial_rgb_change(r, g, b); - portf.send("green=" + QString::number(g)); + //serial_rgb_change(r, g, b); + send("green=" + QString::number(g)); } void controllerWindow::on_b_slider_valueChanged(int value) { b = value; - //serial_rgb_change(r, g, b); - portf.send("blue=" + QString::number(b)); + //serial_rgb_change(r, g, b); + send("blue=" + QString::number(b)); } void controllerWindow::on_red_button_clicked() @@ -410,9 +417,9 @@ void controllerWindow::on_blue_button_clicked() void controllerWindow::on_off_button_clicked() { - ui->r_slider->setValue(1); - ui->g_slider->setValue(1); - ui->b_slider->setValue(1); + ui->r_slider->setValue(1); + ui->g_slider->setValue(1); + ui->b_slider->setValue(1); ui->r_slider->setValue(0); ui->g_slider->setValue(0); ui->b_slider->setValue(0); @@ -460,68 +467,186 @@ void controllerWindow::on_preset_delete_button_clicked() void controllerWindow::on_red_fade_button_clicked() { - portf.send("redfade"); + send("redfade"); } void controllerWindow::on_green_fade_button_clicked() { - portf.send("greenfade"); + send("greenfade"); } void controllerWindow::on_blue_fade_button_clicked() { - portf.send("bluefade"); + send("bluefade"); } void controllerWindow::on_speed_button_clicked() { - portf.send("speed=" + QString::number(ui->speed_slider->value())); + send("speed=" + QString::number(ui->speed_slider->value())); } void controllerWindow::on_r_speed_slider_valueChanged(int value) { - portf.send("rspeed=" + QString::number(value)); + send("rspeed=" + QString::number(value)); } void controllerWindow::on_g_speed_slider_valueChanged(int value) { - portf.send("gspeed=" + QString::number(value)); + send("gspeed=" + QString::number(value)); } void controllerWindow::on_b_speed_slider_valueChanged(int value) { - portf.send("bspeed=" + QString::number(value)); + send("bspeed=" + QString::number(value)); } void controllerWindow::on_rfrom_valueChanged(int arg1) { - portf.send("rf=" + QString::number(arg1)); - ui->r_slider->setValue(arg1); + send("rf=" + QString::number(arg1)); + //ui->r_slider->setValue(arg1); } void controllerWindow::on_rto_valueChanged(int arg1) { - portf.send("rt=" + QString::number(arg1)); + send("rt=" + QString::number(arg1)); } void controllerWindow::on_gfrom_valueChanged(int arg1) { - portf.send("gf=" + QString::number(arg1)); - ui->g_slider->setValue(arg1); + send("gf=" + QString::number(arg1)); + //ui->g_slider->setValue(arg1); } void controllerWindow::on_gto_valueChanged(int arg1) { -portf.send("gt=" + QString::number(arg1)); + send("gt=" + QString::number(arg1)); } void controllerWindow::on_bfrom_valueChanged(int arg1) { - portf.send("bf=" + QString::number(arg1)); - ui->b_slider->setValue(arg1); + send("bf=" + QString::number(arg1)); + //ui->b_slider->setValue(arg1); } void controllerWindow::on_bto_valueChanged(int arg1) { - portf.send("bt=" + QString::number(arg1)); + send("bt=" + QString::number(arg1)); +} + +bool controllerWindow::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 controllerWindow::serial_disconnect() +{ + /* this function disconnects from the serial port if it is connected already */ + if (ser->isOpen()) + { + ser->close(); + ptimer->stop(); + return true; + } + return false; +} + +void controllerWindow::send(QString com) +{ + data = ""; + //qDebug() << com; + data.append(com + "\n"); + if (ser->isOpen()) + ser->write(data); +} + +void controllerWindow::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 controllerWindow::read() +{ + if (serdata[serdata.size() - 1] == '\n') + { + parse(QString(serdata)); + serdata = ""; + } + else + serdata = serdata + ser->readAll(); +} + +void controllerWindow::parse(QString message) +{ + qDebug() << message; + if (message.contains("=")) + { + QString command = message.split("=")[0].remove(QRegExp("[\\n\\t\\r]")); + QString text = message.split("=")[1].remove(QRegExp("[\\n\\t\\r]")); + if (command == "msgbox") + show_msgbox(text); + if (command == "ping") + { + qDebug() << "pong from arduino"; + tping = true; + } + } +} + +void controllerWindow::on_serial_send_button_clicked() +{ + send(ui->serial_input->text()); +} +// timer after ping send, if the timer timeout()'s, disconnect, claim no connection +void controllerWindow::ping() +{ + qDebug() << "sending ping"; + send("ping\n"); + tping = false; + QTimer::singleShot(1000, this, SLOT(check_ping())); +} + +void controllerWindow::check_ping() +{ + if (tping) + { + qDebug() << "connection fine"; + tping = false; + pingtries = 0; + } + else + { + if (pingtries >= 3) + { + qDebug() << "connection lost"; + on_disconnect_button_clicked(); + show_msgbox("Disconnected from Arduino.\nNo ping response after 3 tries."); + } + else + { + pingtries++; + qDebug() << "no ping response try" << pingtries; + } + } } diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h index 0997e82..1fed07e 100755 --- a/qt/RGBController/controllerwindow.h +++ b/qt/RGBController/controllerwindow.h @@ -6,12 +6,13 @@ #include #include #include +#include #include #include #include #include #include -#include "serial_communication.h" +#include #include "ui_controllerwindow.h" namespace Ui { @@ -25,7 +26,6 @@ class controllerWindow : public QMainWindow public: explicit controllerWindow(QWidget *parent = 0); ~controllerWindow(); - /* public functions */ void info_log(QString text); void populate_serial_list(); @@ -34,6 +34,12 @@ class controllerWindow : public QMainWindow void delete_preset(QString name); void serial_rgb_change(int r, int g, int b); void show_msgbox(QString message); + 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); + void read(); int show_question_box(QString message, QString omessage); /*public variables */ /* these three ints will hold the current value (0 - 255) of each slider */ @@ -44,71 +50,80 @@ class controllerWindow : public QMainWindow QString port; /* this int will contain the current preset index selected */ int preset_index; - QString presetsfile; - QString tempfile; + QString presetsfile; + QString tempfile; + QString port_name; + QSerialPort *ser; + QByteArray data; + QByteArray serdata; + QTimer *ptimer; + bool tping; + int pingtries; 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(); + + void on_refresh_port_button_clicked(); + + void on_reload_preset_button_clicked(); - void on_disconnect_button_clicked(); - - void on_refresh_port_button_clicked(); + void on_r_slider_valueChanged(int value); - void on_reload_preset_button_clicked(); - - void on_r_slider_valueChanged(int value); + void on_g_slider_valueChanged(int value); - void on_g_slider_valueChanged(int value); + void on_b_slider_valueChanged(int value); - void on_b_slider_valueChanged(int value); + void on_red_button_clicked(); - void on_red_button_clicked(); + void on_green_button_clicked(); - void on_green_button_clicked(); + void on_blue_button_clicked(); - void on_blue_button_clicked(); + void on_off_button_clicked(); - void on_off_button_clicked(); + void on_set_preset_button_clicked(); - void on_set_preset_button_clicked(); + void on_presets_dropdown_currentIndexChanged(int index); - void on_presets_dropdown_currentIndexChanged(int index); + void on_preset_save_button_clicked(); - void on_preset_save_button_clicked(); + void on_preset_delete_button_clicked(); - void on_preset_delete_button_clicked(); + void on_red_fade_button_clicked(); - void on_red_fade_button_clicked(); + void on_green_fade_button_clicked(); - void on_green_fade_button_clicked(); + void on_blue_fade_button_clicked(); - void on_blue_fade_button_clicked(); + void on_speed_button_clicked(); - void on_speed_button_clicked(); + void on_r_speed_slider_valueChanged(int value); - void on_r_speed_slider_valueChanged(int value); + void on_g_speed_slider_valueChanged(int value); - void on_g_speed_slider_valueChanged(int value); + void on_b_speed_slider_valueChanged(int value); - void on_b_speed_slider_valueChanged(int value); + void on_rfrom_valueChanged(int arg1); - void on_rfrom_valueChanged(int arg1); + void on_rto_valueChanged(int arg1); - void on_rto_valueChanged(int arg1); + void on_gfrom_valueChanged(int arg1); - void on_gfrom_valueChanged(int arg1); + void on_gto_valueChanged(int arg1); - void on_gto_valueChanged(int arg1); + void on_bfrom_valueChanged(int arg1); - void on_bfrom_valueChanged(int arg1); + void on_bto_valueChanged(int arg1); - void on_bto_valueChanged(int arg1); + void on_serial_send_button_clicked(); + void ping(); + void check_ping(); private: Ui::controllerWindow *ui; - /* serial communication object */ - serial_communication portf; }; #endif // CONTROLLERWINDOW_H diff --git a/qt/RGBController/controllerwindow.o b/qt/RGBController/controllerwindow.o index e17bfd6..99fc93f 100644 Binary files a/qt/RGBController/controllerwindow.o and b/qt/RGBController/controllerwindow.o differ diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui old mode 100755 new mode 100644 index ca1d807..837abf2 --- a/qt/RGBController/controllerwindow.ui +++ b/qt/RGBController/controllerwindow.ui @@ -9,7 +9,7 @@ 0 0 - 232 + 238 629 @@ -53,6 +53,9 @@ + + + @@ -60,9 +63,6 @@ - - - @@ -403,6 +403,16 @@ + + + + Send + + + + + + diff --git a/qt/RGBController/main.o b/qt/RGBController/main.o index 8ace6c4..c77f1fa 100644 Binary files a/qt/RGBController/main.o and b/qt/RGBController/main.o differ diff --git a/qt/RGBController/moc_controllerwindow.cpp b/qt/RGBController/moc_controllerwindow.cpp index 3b9dff9..0603691 100644 --- a/qt/RGBController/moc_controllerwindow.cpp +++ b/qt/RGBController/moc_controllerwindow.cpp @@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_controllerWindow_t { - QByteArrayData data[33]; - char stringdata0[777]; + QByteArrayData data[36]; + char stringdata0[823]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ @@ -63,7 +63,10 @@ QT_MOC_LITERAL(28, 673, 19), // "on_rto_valueChanged" QT_MOC_LITERAL(29, 693, 21), // "on_gfrom_valueChanged" QT_MOC_LITERAL(30, 715, 19), // "on_gto_valueChanged" QT_MOC_LITERAL(31, 735, 21), // "on_bfrom_valueChanged" -QT_MOC_LITERAL(32, 757, 19) // "on_bto_valueChanged" +QT_MOC_LITERAL(32, 757, 19), // "on_bto_valueChanged" +QT_MOC_LITERAL(33, 777, 29), // "on_serial_send_button_clicked" +QT_MOC_LITERAL(34, 807, 4), // "ping" +QT_MOC_LITERAL(35, 812, 10) // "check_ping" }, "controllerWindow\0on_connect_button_clicked\0" @@ -89,7 +92,8 @@ QT_MOC_LITERAL(32, 757, 19) // "on_bto_valueChanged" "on_rfrom_valueChanged\0arg1\0" "on_rto_valueChanged\0on_gfrom_valueChanged\0" "on_gto_valueChanged\0on_bfrom_valueChanged\0" - "on_bto_valueChanged" + "on_bto_valueChanged\0on_serial_send_button_clicked\0" + "ping\0check_ping" }; #undef QT_MOC_LITERAL @@ -99,7 +103,7 @@ static const uint qt_meta_data_controllerWindow[] = { 7, // revision 0, // classname 0, 0, // classinfo - 28, 14, // methods + 31, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -107,34 +111,37 @@ static const uint qt_meta_data_controllerWindow[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags - 1, 0, 154, 2, 0x08 /* Private */, - 3, 0, 155, 2, 0x08 /* Private */, - 4, 0, 156, 2, 0x08 /* Private */, - 5, 0, 157, 2, 0x08 /* Private */, - 6, 1, 158, 2, 0x08 /* Private */, - 8, 1, 161, 2, 0x08 /* Private */, - 9, 1, 164, 2, 0x08 /* Private */, - 10, 0, 167, 2, 0x08 /* Private */, - 11, 0, 168, 2, 0x08 /* Private */, - 12, 0, 169, 2, 0x08 /* Private */, - 13, 0, 170, 2, 0x08 /* Private */, - 14, 0, 171, 2, 0x08 /* Private */, - 15, 1, 172, 2, 0x08 /* Private */, - 17, 0, 175, 2, 0x08 /* Private */, - 18, 0, 176, 2, 0x08 /* Private */, - 19, 0, 177, 2, 0x08 /* Private */, - 20, 0, 178, 2, 0x08 /* Private */, - 21, 0, 179, 2, 0x08 /* Private */, - 22, 0, 180, 2, 0x08 /* Private */, - 23, 1, 181, 2, 0x08 /* Private */, - 24, 1, 184, 2, 0x08 /* Private */, - 25, 1, 187, 2, 0x08 /* Private */, - 26, 1, 190, 2, 0x08 /* Private */, - 28, 1, 193, 2, 0x08 /* Private */, - 29, 1, 196, 2, 0x08 /* Private */, - 30, 1, 199, 2, 0x08 /* Private */, - 31, 1, 202, 2, 0x08 /* Private */, - 32, 1, 205, 2, 0x08 /* Private */, + 1, 0, 169, 2, 0x08 /* Private */, + 3, 0, 170, 2, 0x08 /* Private */, + 4, 0, 171, 2, 0x08 /* Private */, + 5, 0, 172, 2, 0x08 /* Private */, + 6, 1, 173, 2, 0x08 /* Private */, + 8, 1, 176, 2, 0x08 /* Private */, + 9, 1, 179, 2, 0x08 /* Private */, + 10, 0, 182, 2, 0x08 /* Private */, + 11, 0, 183, 2, 0x08 /* Private */, + 12, 0, 184, 2, 0x08 /* Private */, + 13, 0, 185, 2, 0x08 /* Private */, + 14, 0, 186, 2, 0x08 /* Private */, + 15, 1, 187, 2, 0x08 /* Private */, + 17, 0, 190, 2, 0x08 /* Private */, + 18, 0, 191, 2, 0x08 /* Private */, + 19, 0, 192, 2, 0x08 /* Private */, + 20, 0, 193, 2, 0x08 /* Private */, + 21, 0, 194, 2, 0x08 /* Private */, + 22, 0, 195, 2, 0x08 /* Private */, + 23, 1, 196, 2, 0x08 /* Private */, + 24, 1, 199, 2, 0x08 /* Private */, + 25, 1, 202, 2, 0x08 /* Private */, + 26, 1, 205, 2, 0x08 /* Private */, + 28, 1, 208, 2, 0x08 /* Private */, + 29, 1, 211, 2, 0x08 /* Private */, + 30, 1, 214, 2, 0x08 /* Private */, + 31, 1, 217, 2, 0x08 /* Private */, + 32, 1, 220, 2, 0x08 /* Private */, + 33, 0, 223, 2, 0x08 /* Private */, + 34, 0, 224, 2, 0x08 /* Private */, + 35, 0, 225, 2, 0x08 /* Private */, // slots: parameters QMetaType::Void, @@ -165,6 +172,9 @@ static const uint qt_meta_data_controllerWindow[] = { QMetaType::Void, QMetaType::Int, 27, QMetaType::Void, QMetaType::Int, 27, QMetaType::Void, QMetaType::Int, 27, + QMetaType::Void, + QMetaType::Void, + QMetaType::Void, 0 // eod }; @@ -203,6 +213,9 @@ void controllerWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int case 25: _t->on_gto_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 26: _t->on_bfrom_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 27: _t->on_bto_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 28: _t->on_serial_send_button_clicked(); break; + case 29: _t->ping(); break; + case 30: _t->check_ping(); break; default: ; } } @@ -233,13 +246,13 @@ int controllerWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 28) + if (_id < 31) qt_static_metacall(this, _c, _id, _a); - _id -= 28; + _id -= 31; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 28) + if (_id < 31) *reinterpret_cast(_a[0]) = -1; - _id -= 28; + _id -= 31; } return _id; } diff --git a/qt/RGBController/moc_controllerwindow.o b/qt/RGBController/moc_controllerwindow.o index 4cb2317..b5aef42 100644 Binary files a/qt/RGBController/moc_controllerwindow.o and b/qt/RGBController/moc_controllerwindow.o differ diff --git a/qt/RGBController/moc_predefs.h b/qt/RGBController/moc_predefs.h index 68884ac..f7a843b 100644 --- a/qt/RGBController/moc_predefs.h +++ b/qt/RGBController/moc_predefs.h @@ -131,7 +131,7 @@ #define __DBL_HAS_DENORM__ 1 #define __UINT8_TYPE__ unsigned char #define __FLT_MANT_DIG__ 24 -#define __VERSION__ "6.3.1 20170109" +#define __VERSION__ "6.3.1 20170306" #define __UINT64_C(c) c ## UL #define __cpp_unicode_characters 200704 #define _STDC_PREDEF_H 1 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 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); -} diff --git a/qt/RGBController/serial_communication.h b/qt/RGBController/serial_communication.h deleted file mode 100644 index 3499028..0000000 --- a/qt/RGBController/serial_communication.h +++ /dev/null @@ -1,25 +0,0 @@ -#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; -}; - -#endif // SERIAL_COMMUNICATION_H diff --git a/qt/RGBController/serial_communication.o b/qt/RGBController/serial_communication.o deleted file mode 100644 index 03987dd..0000000 Binary files a/qt/RGBController/serial_communication.o and /dev/null differ diff --git a/qt/RGBController/ui_controllerwindow.h b/qt/RGBController/ui_controllerwindow.h index 5c2c857..02fed42 100644 --- a/qt/RGBController/ui_controllerwindow.h +++ b/qt/RGBController/ui_controllerwindow.h @@ -37,8 +37,8 @@ public: QPushButton *preset_delete_button; QLabel *presets_label; QPushButton *disconnect_button; - QLabel *arduino_status_label; QComboBox *arduino_port_dropdown; + QLabel *arduino_status_label; QSlider *b_slider; QSlider *b_speed_slider; QTextEdit *info_log_textarea; @@ -78,13 +78,15 @@ public: QLabel *b_speed_label; QPushButton *speed_button; QSlider *speed_slider; + QPushButton *serial_send_button; + QLineEdit *serial_input; void setupUi(QMainWindow *controllerWindow) { if (controllerWindow->objectName().isEmpty()) controllerWindow->setObjectName(QStringLiteral("controllerWindow")); controllerWindow->setWindowModality(Qt::WindowModal); - controllerWindow->resize(232, 629); + controllerWindow->resize(238, 629); centralWidget = new QWidget(controllerWindow); centralWidget->setObjectName(QStringLiteral("centralWidget")); gridLayout_2 = new QGridLayout(centralWidget); @@ -116,16 +118,16 @@ public: gridLayout_2->addWidget(disconnect_button, 3, 1, 1, 1); - arduino_status_label = new QLabel(centralWidget); - arduino_status_label->setObjectName(QStringLiteral("arduino_status_label")); - - gridLayout_2->addWidget(arduino_status_label, 0, 1, 1, 1); - arduino_port_dropdown = new QComboBox(centralWidget); arduino_port_dropdown->setObjectName(QStringLiteral("arduino_port_dropdown")); gridLayout_2->addWidget(arduino_port_dropdown, 1, 1, 1, 1); + arduino_status_label = new QLabel(centralWidget); + arduino_status_label->setObjectName(QStringLiteral("arduino_status_label")); + + gridLayout_2->addWidget(arduino_status_label, 0, 1, 1, 1); + b_slider = new QSlider(centralWidget); b_slider->setObjectName(QStringLiteral("b_slider")); b_slider->setMinimumSize(QSize(120, 0)); @@ -354,6 +356,16 @@ public: gridLayout_2->addWidget(speed_slider, 18, 0, 1, 1); + serial_send_button = new QPushButton(centralWidget); + serial_send_button->setObjectName(QStringLiteral("serial_send_button")); + + gridLayout_2->addWidget(serial_send_button, 21, 1, 1, 1); + + serial_input = new QLineEdit(centralWidget); + serial_input->setObjectName(QStringLiteral("serial_input")); + + gridLayout_2->addWidget(serial_input, 21, 0, 1, 1); + controllerWindow->setCentralWidget(centralWidget); retranslateUi(controllerWindow); @@ -392,6 +404,7 @@ public: arduino_port_label->setText(QApplication::translate("controllerWindow", "Arduino port", Q_NULLPTR)); b_speed_label->setText(QApplication::translate("controllerWindow", "Blue speed", Q_NULLPTR)); speed_button->setText(QApplication::translate("controllerWindow", "Speed", Q_NULLPTR)); + serial_send_button->setText(QApplication::translate("controllerWindow", "Send", Q_NULLPTR)); } // retranslateUi }; diff --git a/qt/build-RGBController-Desktop-Debug/Makefile b/qt/build-RGBController-Desktop-Debug/Makefile index 93c69a1..1314c66 100644 --- a/qt/build-RGBController-Desktop-Debug/Makefile +++ b/qt/build-RGBController-Desktop-Debug/Makefile @@ -49,11 +49,9 @@ OBJECTS_DIR = ./ ####### Files SOURCES = ../RGBController/main.cpp \ - ../RGBController/controllerwindow.cpp \ - ../RGBController/serial_communication.cpp moc_controllerwindow.cpp + ../RGBController/controllerwindow.cpp moc_controllerwindow.cpp OBJECTS = main.o \ controllerwindow.o \ - serial_communication.o \ moc_controllerwindow.o DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/common/unix.conf \ @@ -259,6 +257,7 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/features/qt_config.prf \ /usr/lib/qt/mkspecs/linux-g++/qmake.conf \ /usr/lib/qt/mkspecs/features/spec_post.prf \ + ../RGBController/.qmake.stash \ /usr/lib/qt/mkspecs/features/exclusive_builds.prf \ /usr/lib/qt/mkspecs/features/toolchain.prf \ /usr/lib/qt/mkspecs/features/default_pre.prf \ @@ -277,10 +276,8 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/features/exceptions.prf \ /usr/lib/qt/mkspecs/features/yacc.prf \ /usr/lib/qt/mkspecs/features/lex.prf \ - ../RGBController/RGBController.pro ../RGBController/controllerwindow.h \ - ../RGBController/serial_communication.h ../RGBController/main.cpp \ - ../RGBController/controllerwindow.cpp \ - ../RGBController/serial_communication.cpp + ../RGBController/RGBController.pro ../RGBController/controllerwindow.h ../RGBController/main.cpp \ + ../RGBController/controllerwindow.cpp QMAKE_TARGET = RGBController DESTDIR = TARGET = RGBController @@ -496,6 +493,7 @@ Makefile: ../RGBController/RGBController.pro /usr/lib/qt/mkspecs/linux-g++/qmake /usr/lib/qt/mkspecs/features/qt_config.prf \ /usr/lib/qt/mkspecs/linux-g++/qmake.conf \ /usr/lib/qt/mkspecs/features/spec_post.prf \ + .qmake.stash \ /usr/lib/qt/mkspecs/features/exclusive_builds.prf \ /usr/lib/qt/mkspecs/features/toolchain.prf \ /usr/lib/qt/mkspecs/features/default_pre.prf \ @@ -725,6 +723,7 @@ Makefile: ../RGBController/RGBController.pro /usr/lib/qt/mkspecs/linux-g++/qmake /usr/lib/qt/mkspecs/features/qt_config.prf: /usr/lib/qt/mkspecs/linux-g++/qmake.conf: /usr/lib/qt/mkspecs/features/spec_post.prf: +.qmake.stash: /usr/lib/qt/mkspecs/features/exclusive_builds.prf: /usr/lib/qt/mkspecs/features/toolchain.prf: /usr/lib/qt/mkspecs/features/default_pre.prf: @@ -764,8 +763,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 ../RGBController/controllerwindow.h ../RGBController/serial_communication.h $(DISTDIR)/ - $(COPY_FILE) --parents ../RGBController/main.cpp ../RGBController/controllerwindow.cpp ../RGBController/serial_communication.cpp $(DISTDIR)/ + $(COPY_FILE) --parents ../RGBController/controllerwindow.h $(DISTDIR)/ + $(COPY_FILE) --parents ../RGBController/main.cpp ../RGBController/controllerwindow.cpp $(DISTDIR)/ $(COPY_FILE) --parents ../RGBController/controllerwindow.ui $(DISTDIR)/ @@ -801,8 +800,7 @@ moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp compiler_moc_header_make_all: moc_controllerwindow.cpp compiler_moc_header_clean: -$(DEL_FILE) moc_controllerwindow.cpp -moc_controllerwindow.cpp: ../RGBController/serial_communication.h \ - ../RGBController/ui_controllerwindow.h \ +moc_controllerwindow.cpp: ../RGBController/ui_controllerwindow.h \ ../RGBController/controllerwindow.h \ moc_predefs.h \ /usr/bin/moc @@ -828,20 +826,13 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean compiler_ui ####### Compile main.o: ../RGBController/main.cpp ../RGBController/controllerwindow.h \ - ../RGBController/serial_communication.h \ ../RGBController/ui_controllerwindow.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../RGBController/main.cpp controllerwindow.o: ../RGBController/controllerwindow.cpp ../RGBController/controllerwindow.h \ - ../RGBController/serial_communication.h \ ../RGBController/ui_controllerwindow.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o controllerwindow.o ../RGBController/controllerwindow.cpp -serial_communication.o: ../RGBController/serial_communication.cpp ../RGBController/serial_communication.h \ - ../RGBController/controllerwindow.h \ - ../RGBController/ui_controllerwindow.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o serial_communication.o ../RGBController/serial_communication.cpp - moc_controllerwindow.o: moc_controllerwindow.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_controllerwindow.o moc_controllerwindow.cpp diff --git a/qt/build-RGBController-Desktop-Debug/RGBController b/qt/build-RGBController-Desktop-Debug/RGBController index 42b00de..8091a3a 100755 Binary files a/qt/build-RGBController-Desktop-Debug/RGBController and b/qt/build-RGBController-Desktop-Debug/RGBController differ diff --git a/qt/build-RGBController-Desktop-Debug/moc_predefs.h b/qt/build-RGBController-Desktop-Debug/moc_predefs.h index 982a21d..886ee8d 100644 --- a/qt/build-RGBController-Desktop-Debug/moc_predefs.h +++ b/qt/build-RGBController-Desktop-Debug/moc_predefs.h @@ -130,7 +130,7 @@ #define __UINT8_TYPE__ unsigned char #define __NO_INLINE__ 1 #define __FLT_MANT_DIG__ 24 -#define __VERSION__ "6.3.1 20170109" +#define __VERSION__ "6.3.1 20170306" #define __UINT64_C(c) c ## UL #define __cpp_unicode_characters 200704 #define _STDC_PREDEF_H 1 diff --git a/qt/build-RGBController-Desktop-Debug/moc_serial.cpp b/qt/build-RGBController-Desktop-Debug/moc_serial.cpp new file mode 100644 index 0000000..4a63c61 --- /dev/null +++ b/qt/build-RGBController-Desktop-Debug/moc_serial.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'serial.h' +** +** Created by: The Qt Meta Object Compiler version 67 (Qt 5.8.0) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "../RGBController/serial.h" +#include +#include +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'serial.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 67 +#error "This file was generated using the moc from 5.8.0. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +struct qt_meta_stringdata_serial_t { + QByteArrayData data[3]; + char stringdata0[13]; +}; +#define QT_MOC_LITERAL(idx, ofs, len) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ + qptrdiff(offsetof(qt_meta_stringdata_serial_t, stringdata0) + ofs \ + - idx * sizeof(QByteArrayData)) \ + ) +static const qt_meta_stringdata_serial_t qt_meta_stringdata_serial = { + { +QT_MOC_LITERAL(0, 0, 6), // "serial" +QT_MOC_LITERAL(1, 7, 4), // "read" +QT_MOC_LITERAL(2, 12, 0) // "" + + }, + "serial\0read\0" +}; +#undef QT_MOC_LITERAL + +static const uint qt_meta_data_serial[] = { + + // content: + 7, // revision + 0, // classname + 0, 0, // classinfo + 1, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // slots: name, argc, parameters, tag, flags + 1, 0, 19, 2, 0x08 /* Private */, + + // slots: parameters + QMetaType::Void, + + 0 // eod +}; + +void serial::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + if (_c == QMetaObject::InvokeMetaMethod) { + serial *_t = static_cast(_o); + Q_UNUSED(_t) + switch (_id) { + case 0: _t->read(); break; + default: ; + } + } + Q_UNUSED(_a); +} + +const QMetaObject serial::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_serial.data, + qt_meta_data_serial, qt_static_metacall, Q_NULLPTR, Q_NULLPTR} +}; + + +const QMetaObject *serial::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; +} + +void *serial::qt_metacast(const char *_clname) +{ + if (!_clname) return Q_NULLPTR; + if (!strcmp(_clname, qt_meta_stringdata_serial.stringdata0)) + return static_cast(const_cast< serial*>(this)); + return QObject::qt_metacast(_clname); +} + +int serial::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + if (_id < 1) + qt_static_metacall(this, _c, _id, _a); + _id -= 1; + } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { + if (_id < 1) + *reinterpret_cast(_a[0]) = -1; + _id -= 1; + } + return _id; +} +QT_WARNING_POP +QT_END_MOC_NAMESPACE diff --git a/qt/console/Makefile b/qt/console/Makefile index aca3eae..446865f 100644 --- a/qt/console/Makefile +++ b/qt/console/Makefile @@ -804,3 +804,4 @@ uninstall: FORCE FORCE: + diff --git a/qt/console/main.cpp b/qt/console/main.cpp index ed986ce..4771303 100644 --- a/qt/console/main.cpp +++ b/qt/console/main.cpp @@ -35,9 +35,11 @@ int main(int argc, char *argv[]) QTimer::singleShot(100, check); } else - qDebug() << "nope." << argv[2]; + { + qDebug() << "Port in use."; + } } - return a.exec(); + return 0; } void check() diff --git a/qt/console/rgb b/qt/console/rgb index 938eacb..7028476 100755 Binary files a/qt/console/rgb and b/qt/console/rgb differ -- cgit v1.2.3