diff --git a/README.txt b/README.txt index ad2d7c4..06ad208 100644 --- a/README.txt +++ b/README.txt @@ -6,7 +6,7 @@ installation, you must certify that your system is Debian based (or at least uses apt-get) and that you have an active Internet connection. It is important to note that you should also have the control commands for the function generator already installed, but you can always install them later (please -refer to the package "gf2-1.0.tar.gz" to do so). +refer to the packages "gf2-1.1.tar.gz" or "gf2-1.0.tar.gz" to do so). A list of the included scripts follows: – install.sh; diff --git a/src/about.cpp b/src/about.cpp index c33895a..f1a44b6 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free diff --git a/src/about.h b/src/about.h index f40c128..8b4da0d 100644 --- a/src/about.h +++ b/src/about.h @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free diff --git a/src/about.ui b/src/about.ui index f1d29bb..fb00eea 100644 --- a/src/about.ui +++ b/src/about.ui @@ -49,7 +49,7 @@ - <html><head/><body><p>GF2 Graphical User Interface - Version 1.0<br/>Copyright &copy; 2018 Samuel Lourenço</p><p>This program is distributed under the terms of the <a href="http://www.gnu.org/licenses/gpl-3.0-standalone.html"><span style=" text-decoration: underline; color:#2980b9;">GNU GPL v3</span></a>.</p></body></html> + <html><head/><body><p>GF2 Graphical User Interface - Version 2.0<br/>Copyright © 2018-2019 Samuel Lourenço</p><p>This program is distributed under the terms of the <a href="http://www.gnu.org/licenses/gpl-3.0-standalone.html"><span style=" text-decoration: underline; color:#2980b9;">GNU GPL v3</span></a>.</p></body></html> Qt::AlignJustify|Qt::AlignTop diff --git a/src/gf2-gui.pro b/src/gf2-gui.pro index 5b32888..0ca0782 100644 --- a/src/gf2-gui.pro +++ b/src/gf2-gui.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui xml greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -14,12 +14,12 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ - about.cpp \ - serial.cpp + serial.cpp \ + about.cpp HEADERS += mainwindow.h \ - about.h \ - serial.h + serial.h \ + about.h FORMS += mainwindow.ui \ about.ui \ diff --git a/src/main.cpp b/src/main.cpp index bb59382..dc2606b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ca6d590..3d4f440 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -19,6 +19,8 @@ // Includes +#include +#include #include #include "about.h" #include "mainwindow.h" @@ -30,6 +32,8 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + ui->pushButtonClear->setFocus(); + filepath_ = QDir::homePath(); } MainWindow::~MainWindow() @@ -43,13 +47,115 @@ void MainWindow::on_actionAbout_triggered() about.exec(); } +void MainWindow::on_actionLoad_triggered() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Load Settings from File"), filepath_, tr("XML files (*.xml);;All files (*)")); + if (!filename.isEmpty()) // Note that the previous dialog will return an empty string if the user cancels it + { + QFile file(filename); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QMessageBox errorRead; + errorRead.critical(this, tr("Error"), tr("Could not read from %1.\n\nPlease verify that you have read access to this file.").arg(QDir::toNativeSeparators(filename))); + } + else + { + QDomDocument document; + bool error = !document.setContent(&file); + file.close(); + if (error) + { + QMessageBox errorInvalid; + errorInvalid.critical(this, tr("Error"), tr("Invalid XML. The file might be corrupted or incomplete.")); + } + else + { + QDomElement root = document.firstChildElement(); + if (root.tagName() != "settings" || root.attribute("target") != "GF2") + { + QMessageBox errorNoSettings; + errorNoSettings.critical(this, tr("Error"), tr("The selected file is not a GF2 settings file.")); + } + else + { + int errorcount = implementSettings(root); + if (errorcount > 0) + { + QMessageBox warningDebug; + warningDebug.warning(this, tr("Warning"), tr("Found %1 setting(s) with invalid attribute values.\n\nPlease check your settings file for out-of-bounds or unsupported attribute values.").arg(errorcount)); + } + filepath_ = filename; + } + } + } + } +} + +void MainWindow::on_actionSave_triggered() +{ + QString filename = QFileDialog::getSaveFileName(this, tr("Save Settings to File"), filepath_, tr("XML files (*.xml);;All files (*)")); + if (!filename.isEmpty()) // Note that the previous dialog will return an empty string if the user cancels it + { + QDomDocument document; + QDomProcessingInstruction instruction = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\""); + document.appendChild(instruction); + QDomElement root = document.createElement("settings"); + root.setAttribute("target", "GF2"); + document.appendChild(root); + if (ui->comboBoxWave->currentIndex() == 0) + appendSetting(document, root, "waveform", "sinusoidal"); + else if (ui->comboBoxWave->currentIndex() == 1) + appendSetting(document, root, "waveform", "triangular"); + appendSetting(document, root, "frequency_0", QString::number(ui->doubleSpinBoxFreq0->value())); + appendSetting(document, root, "frequency_1", QString::number(ui->doubleSpinBoxFreq1->value())); + if (ui->radioButtonSelFreq0->isChecked()) + appendSetting(document, root, "active_frequency", "frequency_0"); + else if (ui->radioButtonSelFreq1->isChecked()) + appendSetting(document, root, "active_frequency", "frequency_1"); + appendSetting(document, root, "phase_0", QString::number(ui->doubleSpinBoxPhase0->value())); + appendSetting(document, root, "phase_1", QString::number(ui->doubleSpinBoxPhase1->value())); + if (ui->radioButtonSelPhase0->isChecked()) + appendSetting(document, root, "active_phase", "phase_0"); + else if (ui->radioButtonSelPhase1->isChecked()) + appendSetting(document, root, "active_phase", "phase_1"); + appendSetting(document, root, "amplitude", QString::number(ui->doubleSpinBoxAmp->value())); + if (ui->checkBoxZload->isChecked()) + appendSetting(document, root, "50r_load", "on"); + else + appendSetting(document, root, "50r_load", "off"); + if (ui->radioButtonDACOn->isChecked()) + appendSetting(document, root, "dac_state", "on"); + else if (ui->radioButtonDACOff->isChecked()) + appendSetting(document, root, "dac_state", "off"); + if (ui->radioButtonClkOn->isChecked()) + appendSetting(document, root, "clock_state", "on"); + else if (ui->radioButtonClkOff->isChecked()) + appendSetting(document, root, "clock_state", "off"); + QFile file(filename); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QMessageBox errorWrite; + errorWrite.critical(this, tr("Error"), tr("Could not write to %1.\n\nPlease verify that you have write access to this file.").arg(QDir::toNativeSeparators(filename))); + } + else + { + QTextStream out(&file); + out.setCodec("UTF-8"); + out << document.toString(); + file.close(); + filepath_ = filename; + } + } +} + void MainWindow::on_actionSerial_triggered() { Serial serial; + serial.setSerialLineEditText(serialstr_); if (serial.exec() == QDialog::Accepted) { - serialstr_ = serial.getSerial(); - if (serialstr_ == "") + serialstr_ = serial.serialLineEditText(); + if (serialstr_.isEmpty()) this->setWindowTitle("GF2 Function Generator"); else this->setWindowTitle("GF2 Function Generator (S/N: " + serialstr_ + ")"); @@ -74,110 +180,53 @@ void MainWindow::on_checkBoxZload_stateChanged() void MainWindow::on_comboBoxWave_currentIndexChanged(int index) { - QProcess sh; - QString command; if (ui->actionAutoApply->isChecked()) { if(index == 0) - command = ("gf2-sine " + serialstr_).simplified(); + execute(("gf2-sine " + serialstr_).simplified()); else if (index == 1) - command = ("gf2-tri " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-tri " + serialstr_).simplified()); } } void MainWindow::on_doubleSpinBoxAmp_valueChanged(const QString &arg) { - QProcess sh; - QString command, zload; if (ui->actionAutoApply->isChecked()) { + QString zload; if (ui->checkBoxZload->isChecked()) zload = "50"; - command = ("gf2-amp" + zload + " " + arg + " " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-amp" + zload + " " + arg + " " + serialstr_).simplified()); } } void MainWindow::on_doubleSpinBoxFreq0_valueChanged(const QString &arg) { - QProcess sh; - QString command; if (ui->actionAutoApply->isChecked()) - { - command = ("gf2-freq0 " + arg + " " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); - } + execute(("gf2-freq0 " + arg + " " + serialstr_).simplified()); } void MainWindow::on_doubleSpinBoxFreq1_valueChanged(const QString &arg) { - QProcess sh; - QString command; if (ui->actionAutoApply->isChecked()) - { - command = ("gf2-freq1 " + arg + " " + serialstr_).simplified(); - command.simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); - } + execute(("gf2-freq1 " + arg + " " + serialstr_).simplified()); } void MainWindow::on_doubleSpinBoxPhase0_valueChanged(const QString &arg) { - QProcess sh; - QString command; if (ui->actionAutoApply->isChecked()) - { - command = ("gf2-phase0 " + arg + " " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); - } + execute(("gf2-phase0 " + arg + " " + serialstr_).simplified()); } void MainWindow::on_doubleSpinBoxPhase1_valueChanged(const QString &arg) { - QProcess sh; - QString command; if (ui->actionAutoApply->isChecked()) - { - command = ("gf2-phase1 " + arg + " " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); - } + execute(("gf2-phase1 " + arg + " " + serialstr_).simplified()); } void MainWindow::on_pushButtonApply_clicked() { - QProcess sh; - QString amp, clkstate, command, dacstate, freq0, freq1, fsel, phase0, phase1, psel, wave, zload; + QString amp, clkstate, dacstate, freq0, freq1, fsel, phase0, phase1, psel, wave, zload; amp = QString::number(ui->doubleSpinBoxAmp->value()); if (ui->radioButtonClkOn->isChecked()) clkstate = "on"; @@ -205,159 +254,219 @@ void MainWindow::on_pushButtonApply_clicked() wave = "tri"; if (ui->checkBoxZload->isChecked()) zload = "50"; - command = ("gf2-" + wave + " " + serialstr_ + " && gf2-freq0 " + freq0 + " " + serialstr_ + " && gf2-freq1 " + freq1 + " " + serialstr_ + " && gf2-selfreq" + fsel + " " + serialstr_ + " && gf2-phase0 " + phase0 + " " + serialstr_ + " && gf2-phase1 " + phase1 + " " + serialstr_ + " && gf2-selphase" + psel + " " + serialstr_ + " && gf2-amp" + zload + " " + amp + " " + serialstr_ + " && gf2-dac" + dacstate + " " + serialstr_ + " && gf2-clk" + clkstate + " " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-" + wave + " " + serialstr_ + " && gf2-freq0 " + freq0 + " " + serialstr_ + " && gf2-freq1 " + freq1 + " " + serialstr_ + " && gf2-selfreq" + fsel + " " + serialstr_ + " && gf2-phase0 " + phase0 + " " + serialstr_ + " && gf2-phase1 " + phase1 + " " + serialstr_ + " && gf2-selphase" + psel + " " + serialstr_ + " && gf2-amp" + zload + " " + amp + " " + serialstr_ + " && gf2-dac" + dacstate + " " + serialstr_ + " && gf2-clk" + clkstate + " " + serialstr_).simplified()); } void MainWindow::on_pushButtonClear_clicked() { - QProcess sh; - QString command = ("gf2-clear " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-clear " + serialstr_).simplified()); } void MainWindow::on_pushButtonReset_clicked() { - QProcess sh; - QString command; if (ui->actionResetClear->isChecked()) - command = ("gf2-reset " + serialstr_ + " && sleep 2 && gf2-clear " + serialstr_).simplified(); + execute(("gf2-reset " + serialstr_ + " && sleep 2 && gf2-clear " + serialstr_).simplified()); else - command = ("gf2-reset " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-reset " + serialstr_).simplified()); } void MainWindow::on_pushButtonStart_clicked() { - QProcess sh; - QString command = ("gf2-start " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-start " + serialstr_).simplified()); } void MainWindow::on_pushButtonStop_clicked() { - QProcess sh; - QString command = ("gf2-stop " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-stop " + serialstr_).simplified()); } void MainWindow::on_radioButtonClkOff_clicked() { - QProcess sh; - QString command = ("gf2-clkoff " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-clkoff " + serialstr_).simplified()); } void MainWindow::on_radioButtonClkOn_clicked() { - QProcess sh; - QString command = ("gf2-clkon " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-clkon " + serialstr_).simplified()); } void MainWindow::on_radioButtonDACOff_clicked() { - QProcess sh; - QString command = ("gf2-dacoff " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-dacoff " + serialstr_).simplified()); } void MainWindow::on_radioButtonDACOn_clicked() { - QProcess sh; - QString command = ("gf2-dacon " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-dacon " + serialstr_).simplified()); } void MainWindow::on_radioButtonSelFreq0_clicked() { - QProcess sh; - QString command = ("gf2-selfreq0 " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-selfreq0 " + serialstr_).simplified()); } void MainWindow::on_radioButtonSelFreq1_clicked() { - QProcess sh; - QString command = ("gf2-selfreq1 " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-selfreq1 " + serialstr_).simplified()); } void MainWindow::on_radioButtonSelPhase0_clicked() { - QProcess sh; - QString command = ("gf2-selphase0 " + serialstr_).simplified(); - ui->textBrowserCommand->append("$ " + command); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << command); - sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); - sh.close(); + execute(("gf2-selphase0 " + serialstr_).simplified()); } void MainWindow::on_radioButtonSelPhase1_clicked() +{ + execute(("gf2-selphase1 " + serialstr_).simplified()); +} + +void MainWindow::appendSetting(QDomDocument &document, QDomElement &parent, const QString &name, const QString &value) +{ + QDomElement element = document.createElement("setting"); + element.setAttribute("value", value); + element.setAttribute("name", name); + parent.appendChild(element); +} + +int MainWindow::implementSettings(const QDomElement &parent) +{ + int errcnt = 0; + QDomNodeList settings = parent.elementsByTagName("setting"); + int cnt = settings.count(); + for (int i = 0; i < cnt; ++i) // Modifier settings + { + QDomNode node = settings.item(i); + if (node.isElement()) + { + QDomElement element = node.toElement(); + if(element.attribute("name").toLower() == "50r_load") + { + QString value = element.attribute("value").toLower(); + if (value == "on") + ui->checkBoxZload->setChecked(true); + else if (value == "off") + ui->checkBoxZload->setChecked(false); + else + ++errcnt; + } + } + } + for (int i = 0; i < cnt; ++i) // Normal settings + { + QDomNode node = settings.item(i); + if (node.isElement()) + { + QDomElement element = node.toElement(); + QString name = element.attribute("name").toLower(); + if(name == "active_frequency") + { + QString value = element.attribute("value").toLower(); + if (value == "frequency_0") + ui->radioButtonSelFreq0->click(); + else if (value == "frequency_1") + ui->radioButtonSelFreq1->click(); + else + ++errcnt; + } + else if(name == "active_phase") + { + QString value = element.attribute("value").toLower(); + if (value == "phase_0") + ui->radioButtonSelPhase0->click(); + else if (value == "phase_1") + ui->radioButtonSelPhase1->click(); + else + ++errcnt; + } + else if(name == "amplitude") + { + bool ok; + double value = element.attribute("value").toDouble(&ok); + if (ok && value >= ui->doubleSpinBoxAmp->minimum() && value <= ui->doubleSpinBoxAmp->maximum()) + ui->doubleSpinBoxAmp->setValue(value); + else + ++errcnt; + } + else if(name == "clock_state") + { + QString value = element.attribute("value").toLower(); + if (value == "on") + ui->radioButtonClkOn->click(); + else if (value == "off") + ui->radioButtonClkOff->click(); + else + ++errcnt; + } + else if(name == "dac_state") + { + QString value = element.attribute("value").toLower(); + if (value == "on") + ui->radioButtonDACOn->click(); + else if (value == "off") + ui->radioButtonDACOff->click(); + else + ++errcnt; + } + else if(name == "frequency_0") + { + bool ok; + double value = element.attribute("value").toDouble(&ok); + if (ok && value >= ui->doubleSpinBoxFreq0->minimum() && value <= ui->doubleSpinBoxFreq0->maximum()) + ui->doubleSpinBoxFreq0->setValue(value); + else + ++errcnt; + } + else if(name == "frequency_1") + { + bool ok; + double value = element.attribute("value").toDouble(&ok); + if (ok && value >= ui->doubleSpinBoxFreq1->minimum() && value <= ui->doubleSpinBoxFreq1->maximum()) + ui->doubleSpinBoxFreq1->setValue(value); + else + ++errcnt; + } + else if(name == "phase_0") + { + bool ok; + double value = element.attribute("value").toDouble(&ok); + if (ok && value >= ui->doubleSpinBoxPhase0->minimum() && value <= ui->doubleSpinBoxPhase0->maximum()) + ui->doubleSpinBoxPhase0->setValue(value); + else + ++errcnt; + } + else if(name == "phase_1") + { + bool ok; + double value = element.attribute("value").toDouble(&ok); + if (ok && value >= ui->doubleSpinBoxPhase1->minimum() && value <= ui->doubleSpinBoxPhase1->maximum()) + ui->doubleSpinBoxPhase1->setValue(value); + else + ++errcnt; + } + else if(name == "waveform") + { + QString value = element.attribute("value").toLower(); + if (value == "sinusoidal") + ui->comboBoxWave->setCurrentIndex(0); + else if (value == "triangular") + ui->comboBoxWave->setCurrentIndex(1); + else + ++errcnt; + } + } + } + return errcnt; +} + +void MainWindow::execute(const QString &command) { QProcess sh; - QString command = ("gf2-selphase1 " + serialstr_).simplified(); ui->textBrowserCommand->append("$ " + command); sh.setProcessChannelMode(QProcess::MergedChannels); sh.start("sh", QStringList() << "-c" << command); sh.waitForFinished(); - ui->textBrowserCommand->append(sh.readAll()); + QString result = sh.readAll(); + result.chop(1); + ui->textBrowserCommand->append(result); sh.close(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 4975d73..c078ba5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -23,6 +23,7 @@ // Includes #include +#include namespace Ui { class MainWindow; @@ -38,6 +39,8 @@ class MainWindow : public QMainWindow private slots: void on_actionAbout_triggered(); + void on_actionLoad_triggered(); + void on_actionSave_triggered(); void on_actionSerial_triggered(); void on_checkBoxZload_stateChanged(); void on_comboBoxWave_currentIndexChanged(int index); @@ -62,7 +65,10 @@ private slots: private: Ui::MainWindow *ui; - QString serialstr_; + QString filepath_, serialstr_; + void appendSetting(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &value); + int implementSettings(const QDomElement &parent); + void execute(const QString &command); }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 6976511..244f885 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -142,20 +142,17 @@ 10 - 309 + 315 115 - 33 + 21 - Amplitude (Vpp): + Amplitude (V<sub>pp</sub>): Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - true - @@ -374,7 +371,7 @@ - Clear Settings + Clear @@ -420,7 +417,7 @@ 10 - 130 + 350 81 31 @@ -433,7 +430,7 @@ 10 - 170 + 130 81 101 @@ -475,7 +472,7 @@ 10 - 280 + 240 81 101 @@ -523,6 +520,12 @@ 161 + + + Monospace + 9 + + @@ -538,11 +541,14 @@ &File + + + - + - &Settings + &Options @@ -556,7 +562,7 @@ - + @@ -583,7 +589,7 @@ true - &Clear Settings after Reset + &Clear after Reset @@ -596,6 +602,22 @@ &About GF2 GUI + + + &Load Settings + + + Ctrl+O + + + + + &Save Settings + + + Ctrl+S + + diff --git a/src/serial.cpp b/src/serial.cpp index 29267eb..e1513d7 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -1,4 +1,4 @@ -/* GF2 GUI - Version 1.0 for Debian Linux +/* GF2 GUI - Version 2.0 for Debian Linux Copyright (c) 2018 Samuel Lourenço This program is free software: you can redistribute it and/or modify it @@ -27,13 +27,9 @@ Serial::Serial(QWidget *parent) : QDialog(parent), ui(new Ui::Serial) { - QProcess sh; ui->setupUi(this); - sh.setProcessChannelMode(QProcess::MergedChannels); - sh.start("sh", QStringList() << "-c" << "gf2-list"); - sh.waitForFinished(); - ui->textBrowserList->append(sh.readAll()); - sh.close(); + list(); + ui->lineEditSerial->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d-]{1,12}"), this)); } Serial::~Serial() @@ -41,24 +37,30 @@ Serial::~Serial() delete ui; } -QString Serial::getSerial() +QString Serial::serialLineEditText() const { - QString serialstr = ui->lineEditSerial->text().simplified(); - serialstr.remove(" "); - serialstr.remove("&"); - serialstr.remove("|"); - serialstr.remove("("); - serialstr.remove(")"); - return serialstr; + return ui->lineEditSerial->text(); +} + +void Serial::setSerialLineEditText(const QString &serialstr) +{ + ui->lineEditSerial->setText(serialstr); } void Serial::on_pushButtonRefresh_clicked() { - QProcess sh; ui->textBrowserList->clear(); + list(); +} + +void Serial::list() +{ + QProcess sh; sh.setProcessChannelMode(QProcess::MergedChannels); sh.start("sh", QStringList() << "-c" << "gf2-list"); sh.waitForFinished(); - ui->textBrowserList->append(sh.readAll()); + QString result = sh.readAll(); + result.chop(1); + ui->textBrowserList->append(result); sh.close(); } diff --git a/src/serial.h b/src/serial.h index 4d036e5..26974a6 100644 --- a/src/serial.h +++ b/src/serial.h @@ -1,5 +1,5 @@ -/* GF2 GUI - Version 1.0 for Debian Linux - Copyright (c) 2018 Samuel Lourenço +/* GF2 GUI - Version 2.0 for Debian Linux + Copyright (c) 2018-2019 Samuel Lourenço This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -35,13 +35,15 @@ class Serial : public QDialog public: explicit Serial(QWidget *parent = 0); ~Serial(); - QString getSerial(); + QString serialLineEditText() const; + void setSerialLineEditText(const QString &serialstr); private slots: void on_pushButtonRefresh_clicked(); private: Ui::Serial *ui; + void list(); }; #endif // SERIAL_H diff --git a/src/serial.ui b/src/serial.ui index 0d4c603..411c8cb 100644 --- a/src/serial.ui +++ b/src/serial.ui @@ -103,6 +103,9 @@ 31 + + true +