Replaced some parsers with regexp
This commit is contained in:
parent
dbc69f2264
commit
af4c29ecdd
@ -52,6 +52,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
readyRecieve = 0;
|
readyRecieve = 0;
|
||||||
|
|
||||||
|
temperatureRegxp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
temperatureRegxp.setPatternSyntax(QRegExp::RegExp);
|
||||||
|
temperatureRegxp.setPattern("\\d+\\.\\d+");
|
||||||
|
|
||||||
|
SDStatusRegxp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
SDStatusRegxp.setPatternSyntax(QRegExp::RegExp);
|
||||||
|
SDStatusRegxp.setPattern("\\d+");
|
||||||
|
|
||||||
serialupdate();
|
serialupdate();
|
||||||
|
|
||||||
connect(&printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError)));
|
connect(&printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(serialError(QSerialPort::SerialPortError)));
|
||||||
@ -71,7 +79,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
else sendTimer.setInterval(5);
|
else sendTimer.setInterval(5);
|
||||||
sendTimer.start();
|
sendTimer.start();
|
||||||
|
|
||||||
progressSDTimer.setInterval(1500);
|
progressSDTimer.setInterval(2000);
|
||||||
progressSDTimer.start();
|
progressSDTimer.start();
|
||||||
|
|
||||||
tempWarning.setInterval(10000);
|
tempWarning.setInterval(10000);
|
||||||
@ -228,7 +236,8 @@ void MainWindow::serialconnect()
|
|||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
ui->controlBox->setDisabled(true);
|
ui->controlBox->setDisabled(true);
|
||||||
ui->consoleGroup->setDisabled(true);
|
ui->consoleGroup->setDisabled(true);
|
||||||
|
ui->actionPrint_from_SD->setDisabled("true");
|
||||||
|
ui->actionSet_SD_printing_mode->setDisabled("true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,6 +674,7 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
|
|||||||
|
|
||||||
TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
||||||
{
|
{
|
||||||
|
/* Old parsing
|
||||||
QString tmp;
|
QString tmp;
|
||||||
TemperatureReadings t;
|
TemperatureReadings t;
|
||||||
|
|
||||||
@ -683,8 +693,25 @@ TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.b = tmp.toDouble();
|
t.b = tmp.toDouble();
|
||||||
|
*/
|
||||||
|
|
||||||
return t;
|
TemperatureReadings r;
|
||||||
|
|
||||||
|
if(temperatureRegxp.indexIn(QString(data)) != -1)
|
||||||
|
{
|
||||||
|
r.e = temperatureRegxp.cap(0).toDouble();
|
||||||
|
}
|
||||||
|
if(temperatureRegxp.indexIn(QString(data), temperatureRegxp.matchedLength()) != -1)
|
||||||
|
{
|
||||||
|
r.b = temperatureRegxp.cap(0).toDouble();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.e = -1;
|
||||||
|
r.b = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatus()
|
void MainWindow::updateStatus()
|
||||||
@ -717,24 +744,31 @@ void MainWindow::initSDprinting()
|
|||||||
|
|
||||||
double MainWindow::parseSDStatus(QByteArray data)
|
double MainWindow::parseSDStatus(QByteArray data)
|
||||||
{
|
{
|
||||||
|
/* Old parsing
|
||||||
QString tmp;
|
QString tmp;
|
||||||
QString fragment = data.split(' ').at(3);
|
QString fragment = data.split(' ').at(3);
|
||||||
for(int i = 0; fragment.at(i) != '/'; ++i)
|
for(int i = 0; fragment.at(i) != '/'; ++i)
|
||||||
{
|
{
|
||||||
tmp += fragment.at(i);
|
tmp += fragment.at(i);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return tmp.toDouble();
|
if(SDStatusRegxp.indexIn(QString(data)) != 0) return SDStatusRegxp.cap(0).toDouble();
|
||||||
|
else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::selectSDfile(QString file)
|
void MainWindow::selectSDfile(QString file)
|
||||||
{
|
{
|
||||||
ui->filename->setText(file.split(" ")[0]);
|
QStringList split = file.split(' ');
|
||||||
ui->filelines->setText(file.split(" ")[1] + QString("/0 bytes"));
|
QString bytes = split.at(split.size()-1);
|
||||||
ui->progressBar->setValue(0);
|
QString filename = file.remove(" "+bytes);
|
||||||
sdBytes = file.split(" ")[1].toDouble();
|
|
||||||
|
|
||||||
sendLine("M23 " + file.split(" ")[0]);
|
ui->filename->setText(filename);
|
||||||
|
ui->filelines->setText(bytes + QString("/0 bytes"));
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
sdBytes = bytes.toDouble();
|
||||||
|
|
||||||
|
sendLine("M23 " + filename);
|
||||||
sdprinting = true;
|
sdprinting = true;
|
||||||
ui->fileBox->setDisabled(false);
|
ui->fileBox->setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "settingswindow.h"
|
#include "settingswindow.h"
|
||||||
#include "aboutwindow.h"
|
#include "aboutwindow.h"
|
||||||
@ -48,6 +49,8 @@ public:
|
|||||||
QStringList sdFiles;
|
QStringList sdFiles;
|
||||||
QFutureWatcher<TemperatureReadings> statusWatcher;
|
QFutureWatcher<TemperatureReadings> statusWatcher;
|
||||||
QFutureWatcher<double> sdWatcher;
|
QFutureWatcher<double> sdWatcher;
|
||||||
|
QRegExp temperatureRegxp;
|
||||||
|
QRegExp SDStatusRegxp;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|||||||
@ -999,6 +999,12 @@ STOP</string>
|
|||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="tempLine">
|
<widget class="QLabel" name="tempLine">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>14</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>200</width>
|
<width>200</width>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user