Skip to content

Commit

Permalink
added auto disconnect on port error
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbug1 committed Feb 27, 2016
1 parent ff284a3 commit a22f61e
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Spherebot_UI/Spherebot_UI.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.4.2, 2016-02-27T16:13:07. -->
<!-- Written by QtCreator 3.4.2, 2016-02-27T16:42:28. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
13 changes: 12 additions & 1 deletion Spherebot_UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(Receiver, SIGNAL(lineReceived(QString)),this, SLOT(processReceivedData(QString)));
connect(Receiver, SIGNAL(lineReceived(QString)),this->bot, SLOT(processAnswer(QString)));

connect(bot->port, SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(handle_port_error(QSerialPort::SerialPortError)));

initUI();
initSateMachine();

Expand All @@ -44,7 +46,6 @@ MainWindow::MainWindow(QWidget *parent) :
setWindowTitle("Spherebot Controll");

qDebug()<<"mainwindow initialised: ";
connect(restartLayerMsgBox,SIGNAL(accepted()),this,SLOT(hey()));
}

void MainWindow::fitgraphicsView() ////function to trigger the fitIn function for the graphics view. Actually this shouldn´t be necessary!
Expand Down Expand Up @@ -266,6 +267,7 @@ void MainWindow::initSateMachine()
/////////////////////////////////////////////////// Transitions

connected->addTransition(ui->connectButton, SIGNAL(clicked()),disconnected);
connected->addTransition(this,SIGNAL(force_disconnect()),disconnected);
disconnected->addTransition(ui->connectButton, SIGNAL(clicked()),try_connect);
try_connect->addTransition(this, SIGNAL(successfully_connected()),connected);
try_connect->addTransition(this, SIGNAL(not_successfully_connected()),disconnected);
Expand Down Expand Up @@ -372,6 +374,15 @@ MainWindow::~MainWindow()
SaveSettings();
delete ui;
}

void MainWindow::handle_port_error(QSerialPort::SerialPortError err)
{
if(err != QSerialPort::NoError)
{
emit force_disconnect();
resetPortList();
}
}
///////////////////////////////////////////////////////////////////////////////

bool MainWindow::LoadSettings()
Expand Down
6 changes: 6 additions & 0 deletions Spherebot_UI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QGraphicsSvgItem>
#include <QMessageBox>
#include <QStateMachine>
#include <QSerialPort>


#define DEFAULTDIAMETER 20
Expand Down Expand Up @@ -93,6 +94,7 @@ private slots:
bool saveFile(const QString &fileName);

signals:
void force_disconnect();
void successfully_connected();
void not_successfully_connected();

Expand All @@ -102,6 +104,10 @@ private slots:
void restart_print();
void abort_restart_print();

public slots:
void handle_port_error(QSerialPort::SerialPortError err);


private:

void setCurrentFile(const QString &fileName);
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a22f61e

Please sign in to comment.