Error handling
This commit is contained in:
parent
ded139334d
commit
47aa59860e
@ -2,7 +2,7 @@
|
||||
# RepRaptor
|
||||
A Qt RepRap gcode sender/host controller aimed to be fast and minimalistic.
|
||||
|
||||
Right now the project is in early stage, nigtly builds are available.
|
||||
Right now the project is in early stage.
|
||||
|
||||
## Screenshots
|
||||

|
||||
|
||||
@ -16,15 +16,20 @@ CONFIG += static
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
settingswindow.cpp \
|
||||
aboutwindow.cpp
|
||||
aboutwindow.cpp \
|
||||
errorwindow.cpp \
|
||||
erroricon.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
settingswindow.h \
|
||||
aboutwindow.h
|
||||
aboutwindow.h \
|
||||
errorwindow.h \
|
||||
erroricon.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
settingswindow.ui \
|
||||
aboutwindow.ui
|
||||
aboutwindow.ui \
|
||||
errorwindow.ui
|
||||
|
||||
RESOURCES += \
|
||||
graphics.qrc
|
||||
|
||||
38
erroricon.cpp
Normal file
38
erroricon.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "erroricon.h"
|
||||
|
||||
ErrorIcon::ErrorIcon(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
framenum = 0;
|
||||
frame = ":icons/error_a.png";
|
||||
animation.setInterval(300);
|
||||
animation.start();
|
||||
|
||||
connect(&animation, SIGNAL(timeout()), this, SLOT(changeFrame()));
|
||||
}
|
||||
|
||||
void ErrorIcon::paintEvent(QPaintEvent *pe)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(0,0,128,87,QPixmap(frame));
|
||||
}
|
||||
|
||||
void ErrorIcon::changeFrame()
|
||||
{
|
||||
if(framenum == 0)
|
||||
{
|
||||
frame = ":icons/error_a.png";
|
||||
framenum = 1;
|
||||
}
|
||||
else if(framenum == 1)
|
||||
{
|
||||
frame = ":icons/error_b.png";
|
||||
framenum = 0;
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
|
||||
ErrorIcon::~ErrorIcon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
27
erroricon.h
Normal file
27
erroricon.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef ERRORICON_H
|
||||
#define ERRORICON_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QPainter>
|
||||
|
||||
class ErrorIcon : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ErrorIcon(QWidget *parent = 0);
|
||||
~ErrorIcon();
|
||||
QTimer animation;
|
||||
QString frame;
|
||||
int framenum;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *pe);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void changeFrame();
|
||||
};
|
||||
|
||||
#endif // ERRORICON_H
|
||||
15
errorwindow.cpp
Normal file
15
errorwindow.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "errorwindow.h"
|
||||
#include "ui_errorwindow.h"
|
||||
|
||||
ErrorWindow::ErrorWindow(QWidget *parent, QString errorText) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ErrorWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->errorlabel->setText(errorText);
|
||||
}
|
||||
|
||||
ErrorWindow::~ErrorWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
24
errorwindow.h
Normal file
24
errorwindow.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef ERRORWINDOW_H
|
||||
#define ERRORWINDOW_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "erroricon.h"
|
||||
|
||||
namespace Ui {
|
||||
class ErrorWindow;
|
||||
}
|
||||
|
||||
class ErrorWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ErrorWindow(QWidget *parent = 0, QString errorText = "Unknown error");
|
||||
~ErrorWindow();
|
||||
|
||||
private:
|
||||
Ui::ErrorWindow *ui;
|
||||
};
|
||||
|
||||
#endif // ERRORWINDOW_H
|
||||
130
errorwindow.ui
Normal file
130
errorwindow.ui
Normal file
@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ErrorWindow</class>
|
||||
<widget class="QDialog" name="ErrorWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>350</width>
|
||||
<height>139</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>100</y>
|
||||
<width>171</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="ErrorIcon" name="widget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>128</width>
|
||||
<height>87</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>128</width>
|
||||
<height>87</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>10</y>
|
||||
<width>121</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Serial port error:</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="errorlabel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>40</y>
|
||||
<width>151</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NaN</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ErrorIcon</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">erroricon.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ErrorWindow</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ErrorWindow</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@ -2,5 +2,7 @@
|
||||
<qresource prefix="/">
|
||||
<file>icons/icon.png</file>
|
||||
<file>icons/logo.png</file>
|
||||
<file>icons/error_a.png</file>
|
||||
<file>icons/error_b.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
icons/error_a.png
Normal file
BIN
icons/error_a.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
BIN
icons/error_b.png
Normal file
BIN
icons/error_b.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@ -39,6 +39,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
serialupdate();
|
||||
|
||||
connect(&printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError)));
|
||||
connect(&printer, SIGNAL(readyRead()), this, SLOT(readSerial()));
|
||||
connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus()));
|
||||
connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
||||
@ -199,6 +200,7 @@ void MainWindow::serialconnect()
|
||||
ui->progressBar->setValue(0);
|
||||
ui->controlBox->setDisabled(true);
|
||||
ui->consoleGroup->setDisabled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -440,6 +442,7 @@ void MainWindow::sendNext()
|
||||
currentLine = 0;
|
||||
ui->sendBtn->setText("Send");
|
||||
ui->pauseBtn->setDisabled("true");
|
||||
ui->filelines->setText(QString::number(gcode.size()) + QString("/") + QString::number(currentLine) + QString(" Lines"));
|
||||
return;
|
||||
}
|
||||
sendLine(gcode.at(currentLine));
|
||||
@ -505,5 +508,59 @@ void MainWindow::injectCommand(QString command)
|
||||
|
||||
void MainWindow::updateRecent()
|
||||
{
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
void MainWindow::serialError(QSerialPort::SerialPortError error)
|
||||
{
|
||||
if(error == QSerialPort::NoError) return;
|
||||
|
||||
if(printer.isOpen()) printer.close();
|
||||
|
||||
if(sending) paused = true;
|
||||
|
||||
ui->connectBtn->setText("Connect");
|
||||
ui->sendBtn->setDisabled(true);
|
||||
ui->pauseBtn->setDisabled(true);
|
||||
ui->progressBar->setValue(0);
|
||||
ui->controlBox->setDisabled(true);
|
||||
ui->consoleGroup->setDisabled(true);
|
||||
|
||||
qDebug() << error;
|
||||
|
||||
QString errorMsg;
|
||||
switch(error)
|
||||
{
|
||||
case QSerialPort::DeviceNotFoundError:
|
||||
errorMsg = "Device not found";
|
||||
break;
|
||||
|
||||
case QSerialPort::PermissionError:
|
||||
errorMsg = "Insufficient permissions\nAlready opened?";
|
||||
break;
|
||||
|
||||
case QSerialPort::OpenError:
|
||||
errorMsg = "Cant open port\nAlready opened?";
|
||||
break;
|
||||
|
||||
case QSerialPort::TimeoutError:
|
||||
errorMsg = "Serial connection timed out";
|
||||
break;
|
||||
|
||||
case QSerialPort::WriteError:
|
||||
case QSerialPort::ReadError:
|
||||
errorMsg = "I/O Error";
|
||||
break;
|
||||
|
||||
case QSerialPort::ResourceError:
|
||||
errorMsg = "Disconnected";
|
||||
break;
|
||||
|
||||
default:
|
||||
errorMsg = "Unknown error\nSomething went wrong";
|
||||
break;
|
||||
}
|
||||
|
||||
ErrorWindow errorwindow(this, errorMsg);
|
||||
errorwindow.exec();
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
#include "settingswindow.h"
|
||||
#include "aboutwindow.h"
|
||||
#include "errorwindow.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
@ -95,6 +96,7 @@ private slots:
|
||||
void on_actionSettings_triggered();
|
||||
void on_releasebtn_clicked();
|
||||
void on_actionAbout_triggered();
|
||||
void serialError(QSerialPort::SerialPortError error);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user