Moved temperature parsing to QFuture
This commit is contained in:
parent
8423eda54a
commit
aed98997a0
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui serialport
|
QT += core gui serialport concurrent
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(&printer, SIGNAL(readyRead()), this, SLOT(readSerial()));
|
connect(&printer, SIGNAL(readyRead()), this, SLOT(readSerial()));
|
||||||
connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus()));
|
connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus()));
|
||||||
connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
||||||
|
connect(&statusWatcher, SIGNAL(finished()), this, SLOT(updateStatus()));
|
||||||
|
|
||||||
if(settings.value("core/statusinterval").toInt()) statusTimer.setInterval(settings.value("core/statusinterval").toInt());
|
if(settings.value("core/statusinterval").toInt()) statusTimer.setInterval(settings.value("core/statusinterval").toInt());
|
||||||
else statusTimer.setInterval(3000);
|
else statusTimer.setInterval(3000);
|
||||||
@ -354,7 +355,11 @@ void MainWindow::readSerial()
|
|||||||
{
|
{
|
||||||
QByteArray data = printer.readLine();
|
QByteArray data = printer.readLine();
|
||||||
if(data.startsWith("ok") || data.startsWith("wait")) commandDone = true; //Can send next command
|
if(data.startsWith("ok") || data.startsWith("wait")) commandDone = true; //Can send next command
|
||||||
else if(checkingTemperature && data.startsWith("T:")) parseStatus(data); //Parse temperature readings if any
|
else if(checkingTemperature && data.startsWith("T:"))
|
||||||
|
{
|
||||||
|
QFuture<TemperatureReadings> parseThread = QtConcurrent::run(this, &MainWindow::parseStatus, data);
|
||||||
|
statusWatcher.setFuture(parseThread);
|
||||||
|
}
|
||||||
else if(data.startsWith("Resend")) //Handle resend if requested
|
else if(data.startsWith("Resend")) //Handle resend if requested
|
||||||
{
|
{
|
||||||
if(currentLine > 0) currentLine -= data.split(':')[1].toInt();
|
if(currentLine > 0) currentLine -= data.split(':')[1].toInt();
|
||||||
@ -552,7 +557,7 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
|
|||||||
errorwindow.exec();
|
errorwindow.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::parseStatus(QByteArray data)
|
TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
||||||
{
|
{
|
||||||
QString extmp = "";
|
QString extmp = "";
|
||||||
QString btmp = "";
|
QString btmp = "";
|
||||||
@ -566,11 +571,33 @@ void MainWindow::parseStatus(QByteArray data)
|
|||||||
btmp+=data.at(i);
|
btmp+=data.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->extruderlcd->display(extmp.toDouble());
|
//ui->extruderlcd->display(extmp.toDouble());
|
||||||
ui->bedlcd->display(btmp.toDouble());
|
//ui->bedlcd->display(btmp.toDouble());
|
||||||
|
//sinceLastTemp.restart();
|
||||||
|
|
||||||
|
TemperatureReadings t;
|
||||||
|
t.e = extmp.toDouble();
|
||||||
|
t.b = btmp.toDouble();
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateStatus(TemperatureReadings r)
|
||||||
|
{
|
||||||
|
ui->extruderlcd->display(r.e);
|
||||||
|
ui->bedlcd->display(r.b);
|
||||||
|
|
||||||
sinceLastTemp.restart();
|
sinceLastTemp.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateStatus()
|
||||||
|
{
|
||||||
|
TemperatureReadings r = statusWatcher.future().result();
|
||||||
|
ui->extruderlcd->display(r.e);
|
||||||
|
ui->bedlcd->display(r.b);
|
||||||
|
|
||||||
|
sinceLastTemp.restart();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionPrint_from_SD_triggered()
|
void MainWindow::on_actionPrint_from_SD_triggered()
|
||||||
{
|
{
|
||||||
|
|||||||
12
mainwindow.h
12
mainwindow.h
@ -8,7 +8,7 @@
|
|||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QTimer>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -22,6 +22,11 @@ namespace Ui {
|
|||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double e, b;
|
||||||
|
} TemperatureReadings;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -38,6 +43,7 @@ public:
|
|||||||
QElapsedTimer sinceLastTemp;
|
QElapsedTimer sinceLastTemp;
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QStringList recentFiles;
|
QStringList recentFiles;
|
||||||
|
QFutureWatcher<TemperatureReadings> statusWatcher;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@ -66,7 +72,7 @@ private slots:
|
|||||||
void checkStatus();
|
void checkStatus();
|
||||||
void updateRecent();
|
void updateRecent();
|
||||||
void injectCommand(QString command);
|
void injectCommand(QString command);
|
||||||
void parseStatus(QByteArray data);
|
TemperatureReadings parseStatus(QByteArray data);
|
||||||
|
|
||||||
void xplus();
|
void xplus();
|
||||||
void yplus();
|
void yplus();
|
||||||
@ -99,6 +105,8 @@ private slots:
|
|||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
void serialError(QSerialPort::SerialPortError error);
|
void serialError(QSerialPort::SerialPortError error);
|
||||||
void on_actionPrint_from_SD_triggered();
|
void on_actionPrint_from_SD_triggered();
|
||||||
|
void updateStatus(TemperatureReadings r);
|
||||||
|
void updateStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user