diff options
Diffstat (limited to 'qt/RGBController')
-rw-r--r-- | qt/RGBController/.controllerwindow.cpp.swp | bin | 0 -> 24576 bytes | |||
-rw-r--r-- | qt/RGBController/.controllerwindow.h.swp | bin | 0 -> 12288 bytes | |||
-rwxr-xr-x | qt/RGBController/RGBController.pro.user | 2 | ||||
-rwxr-xr-x | qt/RGBController/controllerwindow.cpp | 343 | ||||
-rwxr-xr-x | qt/RGBController/controllerwindow.h | 66 | ||||
-rwxr-xr-x | qt/RGBController/controllerwindow.ui | 12 | ||||
-rw-r--r-- | qt/RGBController/serial_communication.cpp | 58 | ||||
-rw-r--r-- | qt/RGBController/serial_communication.h | 20 |
8 files changed, 262 insertions, 239 deletions
diff --git a/qt/RGBController/.controllerwindow.cpp.swp b/qt/RGBController/.controllerwindow.cpp.swp Binary files differnew file mode 100644 index 0000000..e33becb --- /dev/null +++ b/qt/RGBController/.controllerwindow.cpp.swp diff --git a/qt/RGBController/.controllerwindow.h.swp b/qt/RGBController/.controllerwindow.h.swp Binary files differnew file mode 100644 index 0000000..51c6912 --- /dev/null +++ b/qt/RGBController/.controllerwindow.h.swp diff --git a/qt/RGBController/RGBController.pro.user b/qt/RGBController/RGBController.pro.user index 1b89dcd..92130ad 100755 --- a/qt/RGBController/RGBController.pro.user +++ b/qt/RGBController/RGBController.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.0.0, 2016-05-29T21:56:23. --> +<!-- Written by QtCreator 4.0.0, 2016-05-30T20:26:17. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp index 302e3d2..c5a8e4d 100755 --- a/qt/RGBController/controllerwindow.cpp +++ b/qt/RGBController/controllerwindow.cpp @@ -4,106 +4,115 @@ controllerWindow::controllerWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::controllerWindow) { - /* this is our setup function, we set things up here */ + /* this is our setup function, we set things up here */ ui->setupUi(this); - info_log("RGB Controller started"); - /* 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); - ui->red_button->setEnabled(false); - ui->green_button->setEnabled(false); - ui->blue_button->setEnabled(false); - ui->off_button->setEnabled(false); - ui->reload_preset_button->setEnabled(false); - ui->set_preset_button->setEnabled(false); - ui->presets_dropdown->setEnabled(false); - ui->r_slider->setEnabled(false); - ui->g_slider->setEnabled(false); - ui->b_slider->setEnabled(false); - ui->r_slider->setValue(0); - ui->g_slider->setValue(0); - ui->b_slider->setValue(0); - /* set some crucial ints */ - preset_index = 0, r = 0, g = 0, b = 0; - /* populate our serial port dropdown box */ - populate_serial_list(); - /* load our presets file */ - load_presets(); + info_log("RGB Controller started"); + /* 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); + ui->red_button->setEnabled(false); + ui->green_button->setEnabled(false); + ui->blue_button->setEnabled(false); + ui->off_button->setEnabled(false); + ui->reload_preset_button->setEnabled(false); + ui->set_preset_button->setEnabled(false); + ui->presets_dropdown->setEnabled(false); + ui->r_slider->setEnabled(false); + ui->g_slider->setEnabled(false); + ui->b_slider->setEnabled(false); + ui->r_slider->setValue(0); + ui->g_slider->setValue(0); + ui->b_slider->setValue(0); + /* set some crucial ints */ + preset_index = 0, r = 0, g = 0, b = 0; + /* populate our serial port dropdown box */ + populate_serial_list(); + /* load our presets file */ + load_presets(); } controllerWindow::~controllerWindow() { - /* this function will end our program and clean up */ + /* this function will end our program and clean up */ delete ui; } void controllerWindow::info_log(QString text) { - /* this function is used to append logging information to our text area */ - ui->info_log_textarea->append(text); + /* this function is used to append logging information to our text area */ + ui->info_log_textarea->append(text); } void controllerWindow::populate_serial_list() { - /* - * things to be done here: - * - clear anything inside our serial dropdown box - * - re-populate the serial dropdown box - */ - - /* remove anything in the list */ - ui->arduino_port_dropdown->clear(); - /* populate the list */ - for (int x = 0; x < QSerialPortInfo::availablePorts().size(); x++) - { - if (!QSerialPortInfo::availablePorts().at(x).description().isEmpty()) - ui->arduino_port_dropdown->addItem(QSerialPortInfo::availablePorts().at(x).portName()); - } - if (!ui->arduino_port_dropdown->itemText(0).isEmpty()) - { - ui->connect_button->setEnabled(true); - info_log("Serial port list populated"); - } else - { - info_log("No serial port found!"); - ui->arduino_port_dropdown->addItem("None"); - } + /* + * things to be done here: + * - clear anything inside our serial dropdown box + * - re-populate the serial dropdown box + */ + + /* remove anything in the list */ + ui->arduino_port_dropdown->clear(); + /* populate the list */ + for (int x = 0; x < QSerialPortInfo::availablePorts().size(); x++) + { + if (!QSerialPortInfo::availablePorts().at(x).description().isEmpty()) + ui->arduino_port_dropdown->addItem(QSerialPortInfo::availablePorts().at(x).portName()); + } + if (!ui->arduino_port_dropdown->itemText(0).isEmpty()) + { + ui->connect_button->setEnabled(true); + info_log("Serial port list populated"); + } else + { + info_log("No serial port found!"); + ui->arduino_port_dropdown->addItem("None"); + } } void controllerWindow::load_presets() { - /* - * this function will load presets from file and put them into a drop down box - * How i plan for it to work: - * -> load file - * -> parse line by line - * -> split line at delimeter - * -> add [0] to dropdown (name), add [1] to an array that stores all the values - */ - QFile inputFile("presets.txt"); - if (inputFile.open(QIODevice::ReadOnly)) - { - QTextStream in(&inputFile); - while (!in.atEnd()) - { - QString line = in.readLine(); - if (line.contains("=")) - { - ui->presets_dropdown->addItem(line.split("=")[0]); - presets.append(line.split("=")[1]); - } - } - inputFile.close(); - info_log("Presets loaded"); - } else - info_log("Presets file not found."); + /* + * this function will load presets from file and put them into a drop down box + * How i plan for it to work: + * -> load file + * -> parse line by line + * -> split line at delimeter + * -> add [0] to dropdown (name), add [1] to an array that stores all the values + */ + QFile inputFile("presets.txt"); + if (inputFile.open(QIODevice::ReadOnly)) + { + QTextStream in(&inputFile); + while (!in.atEnd()) + { + QString line = in.readLine(); + if (line.contains("=")) + { + ui->presets_dropdown->addItem(line.split("=")[0]); + presets.append(line.split("=")[1]); + } + } + inputFile.close(); + info_log("Presets loaded"); + } else + { + show_msgbox("Unable to find the presets fle.\nThis file needs to be named 'presets.txt' and be located in the same directory as the binary."); + info_log("Presets file not found."); + } } void controllerWindow::serial_rgb_change(int r, int g, int b) { - portf.rgb_change(r, g, b); + portf.rgb_change(r, g, b); } +void controllerWindow::show_msgbox(QString message) +{ + QMessageBox msgbox; + msgbox.setText(message); + msgbox.exec(); +} /* * @@ -113,143 +122,145 @@ void controllerWindow::serial_rgb_change(int r, int g, int b) 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 - */ - port = ui->arduino_port_dropdown->currentText(); - if (portf.serial_connect(port)) - { // if true we are connected - info_log("Connection established"); - ui->arduino_status_label->setText("<font color=green>Connected</font>"); - /* now we need to disabled and enable some buttons and objects */ - ui->disconnect_button->setEnabled(true); - ui->connect_button->setEnabled(false); - ui->red_button->setEnabled(true); - ui->green_button->setEnabled(true); - ui->blue_button->setEnabled(true); - ui->off_button->setEnabled(true); - ui->reload_preset_button->setEnabled(true); - ui->set_preset_button->setEnabled(true); - ui->presets_dropdown->setEnabled(true); - ui->r_slider->setEnabled(true); - ui->g_slider->setEnabled(true); - ui->b_slider->setEnabled(true); - ui->refresh_port_button->setEnabled(false); - ui->arduino_port_dropdown->setEnabled(false); - } else - { - info_log("Unable to connect (port in use?)"); - } + /* + * 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 + */ + port = ui->arduino_port_dropdown->currentText(); + if (portf.serial_connect(port)) + { // if true we are connected + info_log("Connection established"); + ui->arduino_status_label->setText("<font color=green>Connected</font>"); + /* now we need to disabled and enable some buttons and objects */ + ui->disconnect_button->setEnabled(true); + ui->connect_button->setEnabled(false); + ui->red_button->setEnabled(true); + ui->green_button->setEnabled(true); + ui->blue_button->setEnabled(true); + ui->off_button->setEnabled(true); + ui->reload_preset_button->setEnabled(true); + ui->set_preset_button->setEnabled(true); + ui->presets_dropdown->setEnabled(true); + ui->r_slider->setEnabled(true); + ui->g_slider->setEnabled(true); + ui->b_slider->setEnabled(true); + ui->refresh_port_button->setEnabled(false); + ui->arduino_port_dropdown->setEnabled(false); + } else + { + info_log("Unable to connect (port in use?)"); + } } 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()) - { - info_log("Disconnected from serial port"); - ui->arduino_status_label->setText("<font color=red>Disconnected</font>"); - ui->disconnect_button->setEnabled(false); - ui->connect_button->setEnabled(true); - ui->red_button->setEnabled(false); - ui->green_button->setEnabled(false); - ui->blue_button->setEnabled(false); - ui->off_button->setEnabled(false); - ui->reload_preset_button->setEnabled(false); - ui->set_preset_button->setEnabled(false); - ui->presets_dropdown->setEnabled(false); - ui->refresh_port_button->setEnabled(true); - ui->arduino_port_dropdown->setEnabled(true); - ui->r_slider->setEnabled(false); - ui->g_slider->setEnabled(false); - ui->b_slider->setEnabled(false); - ui->r_slider->setValue(0); - ui->g_slider->setValue(0); - ui->b_slider->setValue(0); - - } else - { - /* I have no clue how we'd get here */ - info_log("Cannot disconnect"); - } + /* + * 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()) + { + info_log("Disconnected from serial port"); + ui->arduino_status_label->setText("<font color=red>Disconnected</font>"); + ui->disconnect_button->setEnabled(false); + ui->connect_button->setEnabled(true); + ui->red_button->setEnabled(false); + ui->green_button->setEnabled(false); + ui->blue_button->setEnabled(false); + ui->off_button->setEnabled(false); + ui->reload_preset_button->setEnabled(false); + ui->set_preset_button->setEnabled(false); + ui->presets_dropdown->setEnabled(false); + ui->refresh_port_button->setEnabled(true); + ui->arduino_port_dropdown->setEnabled(true); + ui->r_slider->setEnabled(false); + ui->g_slider->setEnabled(false); + ui->b_slider->setEnabled(false); + ui->r_slider->setValue(0); + ui->g_slider->setValue(0); + ui->b_slider->setValue(0); + } else + { + /* I have no clue how we'd get here */ + info_log("Cannot disconnect"); + } } void controllerWindow::on_refresh_port_button_clicked() { - populate_serial_list(); + populate_serial_list(); } void controllerWindow::on_reload_preset_button_clicked() { - ui->presets_dropdown->clear(); - presets.clear(); - preset_index = 0; - load_presets(); + ui->presets_dropdown->clear(); + presets.clear(); + preset_index = 0; + load_presets(); } void controllerWindow::on_r_slider_valueChanged(int value) { - r = value; - serial_rgb_change(r, g, b); + r = value; + serial_rgb_change(r, g, b); } void controllerWindow::on_g_slider_valueChanged(int value) { - g = value; - serial_rgb_change(r, g, b); + g = value; + serial_rgb_change(r, g, b); } void controllerWindow::on_b_slider_valueChanged(int value) { - b = value; - serial_rgb_change(r, g, b); + b = value; + serial_rgb_change(r, g, b); } void controllerWindow::on_red_button_clicked() { - ui->r_slider->setValue(255); - ui->g_slider->setValue(0); - ui->b_slider->setValue(0); + ui->r_slider->setValue(255); + ui->g_slider->setValue(0); + ui->b_slider->setValue(0); } void controllerWindow::on_green_button_clicked() { - ui->r_slider->setValue(0); - ui->g_slider->setValue(255); - ui->b_slider->setValue(0); + ui->r_slider->setValue(0); + ui->g_slider->setValue(255); + ui->b_slider->setValue(0); } void controllerWindow::on_blue_button_clicked() { - ui->r_slider->setValue(0); - ui->g_slider->setValue(0); - ui->b_slider->setValue(255); + ui->r_slider->setValue(0); + ui->g_slider->setValue(0); + ui->b_slider->setValue(255); } void controllerWindow::on_off_button_clicked() { - ui->r_slider->setValue(0); - ui->g_slider->setValue(0); - ui->b_slider->setValue(0); + ui->r_slider->setValue(0); + ui->g_slider->setValue(0); + ui->b_slider->setValue(0); } void controllerWindow::on_set_preset_button_clicked() { - QString tempstore = presets.at(preset_index); - QStringList temparray = tempstore.split(","); - info_log("Preset selected: " + temparray[0] + " " + temparray[1] + " " + temparray[2]); - ui->r_slider->setValue(temparray[0].toInt()); - ui->g_slider->setValue(temparray[1].toInt()); - ui->b_slider->setValue(temparray[2].toInt()); + if (!presets.empty()) + { + QString tempstore = presets.at(preset_index); + QStringList temparray = tempstore.split(","); + info_log("Preset selected: " + temparray[0] + " " + temparray[1] + " " + temparray[2]); + ui->r_slider->setValue(temparray[0].toInt()); + ui->g_slider->setValue(temparray[1].toInt()); + ui->b_slider->setValue(temparray[2].toInt()); + } } void controllerWindow::on_presets_dropdown_currentIndexChanged(int index) { - preset_index = index; + preset_index = index; } diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h index 350a599..d8c2403 100755 --- a/qt/RGBController/controllerwindow.h +++ b/qt/RGBController/controllerwindow.h @@ -8,6 +8,7 @@ #include <QFile> #include <QSerialPortInfo> #include <QTextStream> +#include <QMessageBox> #include "serial_communication.h" #include "ui_controllerwindow.h" @@ -23,53 +24,54 @@ class controllerWindow : public QMainWindow explicit controllerWindow(QWidget *parent = 0); ~controllerWindow(); - /* public functions */ - void info_log(QString text); - void populate_serial_list(); - void load_presets(); - void serial_rgb_change(int r, int g, int b); - /*public variables */ - /* these three ints will hold the current value (0 - 255) of each slider */ - int r, g, b; - /* this list will contain all the presets loaded from file */ - QStringList presets; - /* this string will hold our selected serial port */ - QString port; - /* this int will contain the current preset index selected */ - int preset_index; + /* public functions */ + void info_log(QString text); + void populate_serial_list(); + void load_presets(); + void serial_rgb_change(int r, int g, int b); + void show_msgbox(QString message); + /*public variables */ + /* these three ints will hold the current value (0 - 255) of each slider */ + int r, g, b; + /* this list will contain all the presets loaded from file */ + QStringList presets; + /* this string will hold our selected serial port */ + QString port; + /* this int will contain the current preset index selected */ + int preset_index; -private slots: - /* these slots are used to trigger button clicks and drop down items selections etc */ - void on_connect_button_clicked(); + private slots: + /* these slots are used to trigger button clicks and drop down items selections etc */ + void on_connect_button_clicked(); - void on_disconnect_button_clicked(); + void on_disconnect_button_clicked(); - void on_refresh_port_button_clicked(); + void on_refresh_port_button_clicked(); - void on_reload_preset_button_clicked(); + void on_reload_preset_button_clicked(); - void on_r_slider_valueChanged(int value); + 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); -private: + private: Ui::controllerWindow *ui; - /* serial communication object */ - serial_communication portf; + /* serial communication object */ + serial_communication portf; }; #endif // CONTROLLERWINDOW_H diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui index 1907b33..e96fcf0 100755 --- a/qt/RGBController/controllerwindow.ui +++ b/qt/RGBController/controllerwindow.ui @@ -2,6 +2,9 @@ <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> @@ -196,7 +199,14 @@ </widget> </item> <item row="10" column="0"> - <widget class="QComboBox" name="presets_dropdown"/> + <widget class="QComboBox" name="presets_dropdown"> + <property name="minimumSize"> + <size> + <width>120</width> + <height>0</height> + </size> + </property> + </widget> </item> <item row="13" column="0" colspan="2"> <widget class="QTextEdit" name="info_log_textarea"/> diff --git a/qt/RGBController/serial_communication.cpp b/qt/RGBController/serial_communication.cpp index 94e75db..ac0fd81 100644 --- a/qt/RGBController/serial_communication.cpp +++ b/qt/RGBController/serial_communication.cpp @@ -7,41 +7,41 @@ 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; + /* 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; + /* this function disconnects from the serial port if it is connected already */ + if (serial.isOpen()) + { + serial.close(); + return true; + } + return false; } void serial_communication::rgb_change(int r, int g, int b) { - /* 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("0" + QString::number(r) + "," + QString::number(g) + "," + QString::number(b) + "\n"); - if (serial.isOpen()) - serial.write(data); + /* 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("0" + 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 index d037757..ffc9b82 100644 --- a/qt/RGBController/serial_communication.h +++ b/qt/RGBController/serial_communication.h @@ -8,16 +8,16 @@ 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); - /* variables */ - QString port_name; - QSerialPort serial; - QByteArray data; + public: + /* function declares */ + serial_communication(); + bool serial_connect(QString port); + bool serial_disconnect(); + void rgb_change(int r, int g, int b); + /* variables */ + QString port_name; + QSerialPort serial; + QByteArray data; }; #endif // SERIAL_COMMUNICATION_H |