Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e28c11
Showing
5 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "ypspur_gui.h" | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication app(argc, argv); | ||
YPSpur_gui gui; | ||
gui.show(); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#include "ypspur_gui.h" | ||
#include "ui_ypspur_gui.h" | ||
|
||
#include <iostream> | ||
#include <QRegExp> | ||
#include <QFileDialog> | ||
#include <QScrollBar> | ||
|
||
|
||
YPSpur_gui::YPSpur_gui(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::YPSpur_gui), | ||
settings(QString("ypspur")) | ||
{ | ||
ui->setupUi(this); | ||
|
||
port = settings.value("coordinator/port", "/dev/ttyACM0").toString(); | ||
if(!port.isEmpty()) ui->portList->addItem(port); | ||
|
||
paramFile = settings.value("coordinator/param", "").toString(); | ||
QString paramName = paramFile; | ||
paramName.replace(QRegExp("^.*([^/\\\\]*)$"),"\\1"); | ||
if(!paramFile.isEmpty()) ui->parameterName->setText(paramName); | ||
} | ||
|
||
YPSpur_gui::~YPSpur_gui() | ||
{ | ||
settings.sync(); | ||
delete ui; | ||
} | ||
|
||
|
||
void YPSpur_gui::on_coordinatorStart_toggled(bool checked) | ||
{ | ||
if(checked) | ||
{ | ||
ui->parameterBrowse->setDisabled(true); | ||
ui->portList->setDisabled(true); | ||
connect(&coordinator, SIGNAL(readyReadStandardError()), this, SLOT(updateCoordinatorError())); | ||
connect(&coordinator, SIGNAL(readyReadStandardOutput()), this, SLOT(updateCoordinatorText())); | ||
connect(&interpreter, SIGNAL(readyReadStandardError()), this, SLOT(updateInterpreterError())); | ||
connect(&interpreter, SIGNAL(readyReadStandardOutput()), this, SLOT(updateInterpreterText())); | ||
|
||
QStringList args; | ||
args.append("--device"); | ||
args.append(port); | ||
args.append("--param"); | ||
args.append(paramFile); | ||
args.append("--update-param"); | ||
coordinator.start("/usr/local/bin/ypspur-coordinator", args); | ||
} | ||
else | ||
{ | ||
interpreter.close(); | ||
coordinator.close(); | ||
ui->parameterBrowse->setDisabled(false); | ||
ui->portList->setDisabled(false); | ||
|
||
mutexCoordinatorOutput.lock(); | ||
ui->coordinatorOut->textCursor().movePosition(QTextCursor::End); | ||
ui->coordinatorOut->insertHtml("<hr style=\"width:100%;background-color:#CCCCCC;height:1pt;\"><br>"); | ||
ui->coordinatorOut->verticalScrollBar()->setValue( | ||
ui->coordinatorOut->verticalScrollBar()->maximum()); | ||
mutexCoordinatorOutput.unlock(); | ||
} | ||
} | ||
|
||
void YPSpur_gui::updateCoordinatorError() | ||
{ | ||
mutexCoordinatorOutput.lock(); | ||
QString data(coordinator.readAllStandardError() ); | ||
|
||
data.replace(QRegExp(" ")," "); | ||
data.replace(QRegExp("\n"),"<br>"); | ||
ui->coordinatorOut->textCursor().movePosition(QTextCursor::End); | ||
ui->coordinatorOut->insertHtml("<b>" + data + "</b>"); | ||
ui->coordinatorOut->verticalScrollBar()->setValue( | ||
ui->coordinatorOut->verticalScrollBar()->maximum()); | ||
mutexCoordinatorOutput.unlock(); | ||
if(data.contains("Command analyser started.")) | ||
{ | ||
interpreter.start("/usr/local/bin/ypspur-interpreter"); | ||
} | ||
} | ||
|
||
void YPSpur_gui::updateCoordinatorText() | ||
{ | ||
mutexCoordinatorOutput.lock(); | ||
QString data(coordinator.readAllStandardOutput()); | ||
|
||
data.replace(QRegExp(" ")," "); | ||
data.replace(QRegExp("\n"),"<br>"); | ||
ui->coordinatorOut->textCursor().movePosition(QTextCursor::End); | ||
ui->coordinatorOut->insertHtml(data); | ||
ui->coordinatorOut->verticalScrollBar()->setValue( | ||
ui->coordinatorOut->verticalScrollBar()->maximum()); | ||
mutexCoordinatorOutput.unlock(); | ||
} | ||
|
||
void YPSpur_gui::updateInterpreterError() | ||
{ | ||
mutexInterpreterOutput.lock(); | ||
QString data(interpreter.readAllStandardError() ); | ||
|
||
data.replace(QRegExp(" ")," "); | ||
data.replace(QRegExp("\n"),"<br>"); | ||
ui->interpreterOut->textCursor().movePosition(QTextCursor::End); | ||
ui->interpreterOut->insertHtml("<b>" + data + "</b>"); | ||
ui->interpreterOut->verticalScrollBar()->setValue( | ||
ui->interpreterOut->verticalScrollBar()->maximum()); | ||
mutexInterpreterOutput.unlock(); | ||
} | ||
|
||
void YPSpur_gui::updateInterpreterText() | ||
{ | ||
mutexInterpreterOutput.lock(); | ||
QString data(interpreter.readAllStandardOutput()); | ||
|
||
data.replace(QRegExp(" ")," "); | ||
data.replace(QRegExp("\n"),"<br>"); | ||
ui->interpreterOut->textCursor().movePosition(QTextCursor::End); | ||
ui->interpreterOut->insertHtml(data); | ||
ui->interpreterOut->verticalScrollBar()->setValue( | ||
ui->interpreterOut->verticalScrollBar()->maximum()); | ||
mutexInterpreterOutput.unlock(); | ||
} | ||
|
||
void YPSpur_gui::on_parameterBrowse_clicked() | ||
{ | ||
QString defaultPath("./"); | ||
if(!paramFile.isEmpty()) | ||
{ | ||
defaultPath = paramFile; | ||
} | ||
QString fileName = QFileDialog::getOpenFileName( | ||
this, | ||
QString("Open Image"), | ||
defaultPath, | ||
QString("Parameter files (*.param)")); | ||
if(!fileName.isEmpty()) | ||
{ | ||
paramFile = fileName; | ||
|
||
QString paramName = fileName; | ||
paramName.replace(QRegExp("^.*([^/\\\\]*)$"),"\\1"); | ||
ui->parameterName->setText(paramName); | ||
|
||
settings.setValue("coordinator/param", paramFile); | ||
} | ||
} | ||
|
||
void YPSpur_gui::on_portList_textChanged(const QString &arg1) | ||
{ | ||
if(!arg1.isNull()) | ||
{ | ||
port = arg1; | ||
settings.setValue("coordinator/port", port); | ||
} | ||
} | ||
|
||
void YPSpur_gui::on_interpreterCommand_returnPressed() | ||
{ | ||
QString str = ui->interpreterCommand->text(); | ||
str.append("\n"); | ||
interpreter.write(str.toLocal8Bit()); | ||
ui->interpreterCommand->setText(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef YPSPUR_GUI_H | ||
#define YPSPUR_GUI_H | ||
|
||
#include <stdio.h> | ||
#include <sys/fcntl.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
|
||
#include <QMainWindow> | ||
#include <QFile> | ||
#include <QProcess> | ||
#include <QTextEdit> | ||
#include <QMetaObject> | ||
#include <QMutex> | ||
#include <QSettings> | ||
|
||
namespace Ui { | ||
class YPSpur_gui; | ||
} | ||
|
||
|
||
class YPSpur_gui : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit YPSpur_gui(QWidget *parent = 0); | ||
~YPSpur_gui(); | ||
|
||
private slots: | ||
void on_coordinatorStart_toggled(bool checked); | ||
void updateCoordinatorError(); | ||
void updateCoordinatorText(); | ||
void updateInterpreterError(); | ||
void updateInterpreterText(); | ||
|
||
void on_parameterBrowse_clicked(); | ||
|
||
void on_portList_textChanged(const QString &arg1); | ||
|
||
void on_interpreterCommand_returnPressed(); | ||
|
||
private: | ||
Ui::YPSpur_gui *ui; | ||
|
||
QProcess interpreter; | ||
QProcess coordinator; | ||
QMutex mutexInterpreterOutput; | ||
QMutex mutexCoordinatorOutput; | ||
|
||
QString paramFile; | ||
QString port; | ||
|
||
QSettings settings; | ||
}; | ||
|
||
#endif // YPSPUR_GUI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2014-06-08T15:22:02 | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
TARGET = ypspur_gui | ||
TEMPLATE = app | ||
|
||
|
||
SOURCES += main.cpp \ | ||
ypspur_gui.cpp | ||
|
||
HEADERS += \ | ||
ypspur_gui.h | ||
|
||
FORMS += \ | ||
ypspur_gui.ui |
Oops, something went wrong.