SD card printing UI
This commit is contained in:
parent
8a43041ed6
commit
34c23b69e4
@ -37,6 +37,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
commandDone = false;
|
commandDone = false;
|
||||||
injectingCommand = false;
|
injectingCommand = false;
|
||||||
readingFiles = false;
|
readingFiles = false;
|
||||||
|
sdprinting = false;
|
||||||
|
sdBytes = 0;
|
||||||
userCommand = "";
|
userCommand = "";
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
|
|
||||||
@ -47,7 +49,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
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()));
|
connect(&statusWatcher, SIGNAL(finished()), this, SLOT(updateStatus()));
|
||||||
|
connect(&sdWatcher, SIGNAL(finished()), this, SLOT(updateSDStatus()));
|
||||||
connect(this, SIGNAL(sdReady()), this, SLOT(initSDprinting()));
|
connect(this, SIGNAL(sdReady()), this, SLOT(initSDprinting()));
|
||||||
|
connect(&progressSDTimer, SIGNAL(timeout()), this, SLOT(checkSDStatus()));
|
||||||
|
|
||||||
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);
|
||||||
@ -57,6 +61,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
else sendTimer.setInterval(5);
|
else sendTimer.setInterval(5);
|
||||||
sendTimer.start();
|
sendTimer.start();
|
||||||
|
|
||||||
|
progressSDTimer.setInterval(1000);
|
||||||
|
progressSDTimer.start();
|
||||||
|
|
||||||
tempWarning.setInterval(10000);
|
tempWarning.setInterval(10000);
|
||||||
|
|
||||||
sinceLastTemp.start();
|
sinceLastTemp.start();
|
||||||
@ -119,6 +126,7 @@ void MainWindow::parseFile(QFile &file)
|
|||||||
|
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
sdprinting = false;
|
||||||
ui->fileBox->setEnabled(true);
|
ui->fileBox->setEnabled(true);
|
||||||
ui->filename->setText(file.fileName().split("/").last());
|
ui->filename->setText(file.fileName().split("/").last());
|
||||||
ui->filelines->setText(QString::number(gcode.size()) + QString("/0 lines"));
|
ui->filelines->setText(QString::number(gcode.size()) + QString("/0 lines"));
|
||||||
@ -377,7 +385,12 @@ void MainWindow::readSerial()
|
|||||||
{
|
{
|
||||||
if(currentLine > 0) currentLine -= data.split(':')[1].toInt();
|
if(currentLine > 0) currentLine -= data.split(':')[1].toInt();
|
||||||
if(currentLine < 0) currentLine = 0;
|
if(currentLine < 0) currentLine = 0;
|
||||||
commandDone = true;
|
}
|
||||||
|
else if(datd.startsWith("Done")) sdprinting = false;
|
||||||
|
else if(data.startsWith("SD printing byte"))
|
||||||
|
{
|
||||||
|
QFuture<double> parseSDThread = QtConcurrent::run(this, &MainWindow::parseSDStatus, data);
|
||||||
|
sdWatcher.setFuture(parseSDThread);
|
||||||
}
|
}
|
||||||
else if(data.contains("Begin file list"))
|
else if(data.contains("Begin file list"))
|
||||||
{
|
{
|
||||||
@ -385,6 +398,7 @@ void MainWindow::readSerial()
|
|||||||
readingFiles = true; //start reading files from SD
|
readingFiles = true; //start reading files from SD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commandDone = true;
|
||||||
printMsg(QString(data)); //echo
|
printMsg(QString(data)); //echo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,7 +426,7 @@ void MainWindow::printMsg(QString text)
|
|||||||
|
|
||||||
void MainWindow::on_sendBtn_clicked()
|
void MainWindow::on_sendBtn_clicked()
|
||||||
{
|
{
|
||||||
if(sending)
|
if(sending && !sdprinting)
|
||||||
{
|
{
|
||||||
sending = false;
|
sending = false;
|
||||||
ui->sendBtn->setText("Send");
|
ui->sendBtn->setText("Send");
|
||||||
@ -421,7 +435,7 @@ void MainWindow::on_sendBtn_clicked()
|
|||||||
ui->controlBox->setChecked("true");
|
ui->controlBox->setChecked("true");
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
else if(!sending)
|
else if(!sending && !sdprinting)
|
||||||
{
|
{
|
||||||
sending=true;
|
sending=true;
|
||||||
ui->sendBtn->setText("Stop");
|
ui->sendBtn->setText("Stop");
|
||||||
@ -430,6 +444,15 @@ void MainWindow::on_sendBtn_clicked()
|
|||||||
ui->controlBox->setChecked("false");
|
ui->controlBox->setChecked("false");
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
|
else if(sdprinting)
|
||||||
|
{
|
||||||
|
sending = false;
|
||||||
|
sendLine("M24");
|
||||||
|
ui->sendBtn->setText("Send");
|
||||||
|
ui->pauseBtn->setText("Pause");
|
||||||
|
ui->controlBox->setChecked("true");
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
@ -444,7 +467,7 @@ void MainWindow::sendNext()
|
|||||||
injectingCommand=false;
|
injectingCommand=false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(sending && !paused && commandDone && printer.isWritable())
|
else if(sending && !paused && commandDone && !sdprinting && printer.isWritable())
|
||||||
{
|
{
|
||||||
if(currentLine >= gcode.size()) //check if we are at the end of array
|
if(currentLine >= gcode.size()) //check if we are at the end of array
|
||||||
{
|
{
|
||||||
@ -466,18 +489,22 @@ void MainWindow::sendNext()
|
|||||||
|
|
||||||
void MainWindow::on_pauseBtn_clicked()
|
void MainWindow::on_pauseBtn_clicked()
|
||||||
{
|
{
|
||||||
if(paused)
|
if(paused && !sdprinting)
|
||||||
{
|
{
|
||||||
paused = false;
|
paused = false;
|
||||||
ui->controlBox->setChecked(false);
|
ui->controlBox->setChecked(false);
|
||||||
ui->pauseBtn->setText("Pause");
|
ui->pauseBtn->setText("Pause");
|
||||||
}
|
}
|
||||||
else
|
else if(!paused && !sdprinting)
|
||||||
{
|
{
|
||||||
paused = true;
|
paused = true;
|
||||||
ui->controlBox->setChecked(true);
|
ui->controlBox->setChecked(true);
|
||||||
ui->pauseBtn->setText("Resume");
|
ui->pauseBtn->setText("Resume");
|
||||||
}
|
}
|
||||||
|
else if(sdprinting)
|
||||||
|
{
|
||||||
|
sendLine("M25");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkStatus()
|
void MainWindow::checkStatus()
|
||||||
@ -600,14 +627,6 @@ TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatus(TemperatureReadings r)
|
|
||||||
{
|
|
||||||
ui->extruderlcd->display(r.e);
|
|
||||||
ui->bedlcd->display(r.b);
|
|
||||||
|
|
||||||
sinceLastTemp.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateStatus()
|
void MainWindow::updateStatus()
|
||||||
{
|
{
|
||||||
TemperatureReadings r = statusWatcher.future().result();
|
TemperatureReadings r = statusWatcher.future().result();
|
||||||
@ -626,12 +645,44 @@ void MainWindow::initSDprinting()
|
|||||||
{
|
{
|
||||||
SDWindow sdwindow(sdFiles, this);
|
SDWindow sdwindow(sdFiles, this);
|
||||||
|
|
||||||
connect(&sdwindow, SIGNAL(fileSelected(QString)), this, SLOT(startSDprinting(QString)));
|
connect(&sdwindow, SIGNAL(fileSelected(QString)), this, SLOT(selectSDfile(QString)));
|
||||||
|
|
||||||
sdwindow.exec();
|
sdwindow.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::startSDprinting(QString file)
|
double MainWindow::parseSDStatus(QByteArray data)
|
||||||
{
|
{
|
||||||
sendLine("M23 " + file.split(" ")[0] + '\nM24');
|
QString tmp;
|
||||||
|
QString fragment = data.split(' ').at(3);
|
||||||
|
for(int i = 0; fragment.at(i) != '/'; ++i)
|
||||||
|
{
|
||||||
|
tmp += fragment.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp.toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::selectSDfile(QString file)
|
||||||
|
{
|
||||||
|
ui->filename->setText(file.split(" ")[0]);
|
||||||
|
ui->filelines->setText(file.split(" ")[1] + QString("/0 bytes"));
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
sdBytes = file.split(" ")[1].toDouble();
|
||||||
|
|
||||||
|
sendLine("M23 " + file.split(" ")[0]);
|
||||||
|
sdprinting = true;
|
||||||
|
ui->fileBox->setDisabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateSDStatus()
|
||||||
|
{
|
||||||
|
double currentSDbytes = sdWatcher.future().result();
|
||||||
|
ui->filelines->setText(QString::number(sdBytes) + QString("/") + QString::number(currentSDbytes) + QString(" bytes"));
|
||||||
|
ui->progressBar->setValue(currentSDbytes/sdBytes * 100);
|
||||||
|
if(currentSDbytes == sdBytes) sdprinting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::checkSDStatus()
|
||||||
|
{
|
||||||
|
if(sdWatcher.isFinished() && sdprinting) injectCommand("M27");
|
||||||
}
|
}
|
||||||
|
|||||||
10
mainwindow.h
10
mainwindow.h
@ -39,6 +39,7 @@ public:
|
|||||||
QFile gfile;
|
QFile gfile;
|
||||||
QVector<QString> gcode;
|
QVector<QString> gcode;
|
||||||
QTimer sendTimer;
|
QTimer sendTimer;
|
||||||
|
QTimer progressSDTimer;
|
||||||
QTimer statusTimer;
|
QTimer statusTimer;
|
||||||
QTimer tempWarning;
|
QTimer tempWarning;
|
||||||
QElapsedTimer sinceLastTemp;
|
QElapsedTimer sinceLastTemp;
|
||||||
@ -46,6 +47,7 @@ public:
|
|||||||
QStringList recentFiles;
|
QStringList recentFiles;
|
||||||
QStringList sdFiles;
|
QStringList sdFiles;
|
||||||
QFutureWatcher<TemperatureReadings> statusWatcher;
|
QFutureWatcher<TemperatureReadings> statusWatcher;
|
||||||
|
QFutureWatcher<double> sdWatcher;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@ -59,7 +61,9 @@ private:
|
|||||||
bool checkingTemperature;
|
bool checkingTemperature;
|
||||||
bool injectingCommand;
|
bool injectingCommand;
|
||||||
bool readingFiles;
|
bool readingFiles;
|
||||||
|
bool sdprinting;
|
||||||
int currentLine;
|
int currentLine;
|
||||||
|
double sdBytes;
|
||||||
QString userCommand;
|
QString userCommand;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -76,6 +80,7 @@ private slots:
|
|||||||
void updateRecent();
|
void updateRecent();
|
||||||
void injectCommand(QString command);
|
void injectCommand(QString command);
|
||||||
TemperatureReadings parseStatus(QByteArray data);
|
TemperatureReadings parseStatus(QByteArray data);
|
||||||
|
double parseSDStatus(QByteArray data);
|
||||||
|
|
||||||
void xplus();
|
void xplus();
|
||||||
void yplus();
|
void yplus();
|
||||||
@ -108,10 +113,11 @@ 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();
|
void updateStatus();
|
||||||
void initSDprinting();
|
void initSDprinting();
|
||||||
void startSDprinting(QString file);
|
void selectSDfile(QString file);
|
||||||
|
void checkSDStatus();
|
||||||
|
void updateSDStatus();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sdReady();
|
void sdReady();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user