From 8a43041ed6b0934bb9328587e48d0a5b68923b0b Mon Sep 17 00:00:00 2001 From: NeoTheFox Date: Tue, 3 Mar 2015 14:51:38 +0300 Subject: [PATCH] Initial SD printing support --- RepRaptor.pro | 9 ++++-- mainwindow.cpp | 34 +++++++++++++++++++++- mainwindow.h | 8 ++++++ mainwindow.ui | 4 +-- sdwindow.cpp | 27 ++++++++++++++++++ sdwindow.h | 30 ++++++++++++++++++++ sdwindow.ui | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 sdwindow.cpp create mode 100644 sdwindow.h create mode 100644 sdwindow.ui diff --git a/RepRaptor.pro b/RepRaptor.pro index d3c0a0b..50e7e87 100644 --- a/RepRaptor.pro +++ b/RepRaptor.pro @@ -18,18 +18,21 @@ SOURCES += main.cpp\ settingswindow.cpp \ aboutwindow.cpp \ errorwindow.cpp \ - erroricon.cpp + erroricon.cpp \ + sdwindow.cpp HEADERS += mainwindow.h \ settingswindow.h \ aboutwindow.h \ errorwindow.h \ - erroricon.h + erroricon.h \ + sdwindow.h FORMS += mainwindow.ui \ settingswindow.ui \ aboutwindow.ui \ - errorwindow.ui + errorwindow.ui \ + sdwindow.ui RESOURCES += \ graphics.qrc diff --git a/mainwindow.cpp b/mainwindow.cpp index 600ce5f..8db382e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent) : paused = false; commandDone = false; injectingCommand = false; + readingFiles = false; userCommand = ""; currentLine = 0; @@ -46,6 +47,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus())); connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext())); connect(&statusWatcher, SIGNAL(finished()), this, SLOT(updateStatus())); + connect(this, SIGNAL(sdReady()), this, SLOT(initSDprinting())); if(settings.value("core/statusinterval").toInt()) statusTimer.setInterval(settings.value("core/statusinterval").toInt()); else statusTimer.setInterval(3000); @@ -354,6 +356,17 @@ void MainWindow::readSerial() if(printer.canReadLine()) { QByteArray data = printer.readLine(); + + if(readingFiles) + { + if(!data.contains("End file list")) sdFiles.append(data); + else + { + readingFiles = false; + emit sdReady(); + } + } + if(data.startsWith("ok") || data.startsWith("wait")) commandDone = true; //Can send next command else if(checkingTemperature && data.startsWith("T:")) { @@ -366,6 +379,11 @@ void MainWindow::readSerial() if(currentLine < 0) currentLine = 0; commandDone = true; } + else if(data.contains("Begin file list")) + { + sdFiles.clear(); + readingFiles = true; //start reading files from SD + } printMsg(QString(data)); //echo } @@ -601,5 +619,19 @@ void MainWindow::updateStatus() void MainWindow::on_actionPrint_from_SD_triggered() { - //TODO + sendLine("M20"); +} + +void MainWindow::initSDprinting() +{ + SDWindow sdwindow(sdFiles, this); + + connect(&sdwindow, SIGNAL(fileSelected(QString)), this, SLOT(startSDprinting(QString))); + + sdwindow.exec(); +} + +void MainWindow::startSDprinting(QString file) +{ + sendLine("M23 " + file.split(" ")[0] + '\nM24'); } diff --git a/mainwindow.h b/mainwindow.h index 963b398..703a43e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -16,6 +16,7 @@ #include "settingswindow.h" #include "aboutwindow.h" #include "errorwindow.h" +#include "sdwindow.h" namespace Ui { @@ -43,6 +44,7 @@ public: QElapsedTimer sinceLastTemp; QSettings settings; QStringList recentFiles; + QStringList sdFiles; QFutureWatcher statusWatcher; private: @@ -56,6 +58,7 @@ private: bool commandDone; bool checkingTemperature; bool injectingCommand; + bool readingFiles; int currentLine; QString userCommand; @@ -107,6 +110,11 @@ private slots: void on_actionPrint_from_SD_triggered(); void updateStatus(TemperatureReadings r); void updateStatus(); + void initSDprinting(); + void startSDprinting(QString file); + +signals: + void sdReady(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 25f7e59..e2427c7 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -541,7 +541,7 @@ - false + true Tools @@ -592,7 +592,7 @@ - false + true Print from SD... diff --git a/sdwindow.cpp b/sdwindow.cpp new file mode 100644 index 0000000..5b231d9 --- /dev/null +++ b/sdwindow.cpp @@ -0,0 +1,27 @@ +#include "sdwindow.h" +#include "ui_sdwindow.h" + +SDWindow::SDWindow(QStringList files, QWidget *parent) : + QDialog(parent), + ui(new Ui::SDWindow) +{ + ui->setupUi(this); + + ui->fileslist->addItems(files); +} + +SDWindow::~SDWindow() +{ + delete ui; +} + +void SDWindow::on_buttonBox_accepted() +{ + emit fileSelected(ui->fileslist->currentItem()->text()); +} + +void SDWindow::on_fileslist_doubleClicked(const QModelIndex &index) +{ + emit fileSelected(ui->fileslist->currentItem()->text()); + this->close(); +} diff --git a/sdwindow.h b/sdwindow.h new file mode 100644 index 0000000..7302738 --- /dev/null +++ b/sdwindow.h @@ -0,0 +1,30 @@ +#ifndef SDWINDOW_H +#define SDWINDOW_H + +#include + +namespace Ui { +class SDWindow; +} + +class SDWindow : public QDialog +{ + Q_OBJECT + +public: + explicit SDWindow(QStringList files, QWidget *parent = 0); + ~SDWindow(); + +signals: + void fileSelected(QString filename); + +private slots: + void on_buttonBox_accepted(); + + void on_fileslist_doubleClicked(const QModelIndex &index); + +private: + Ui::SDWindow *ui; +}; + +#endif // SDWINDOW_H diff --git a/sdwindow.ui b/sdwindow.ui new file mode 100644 index 0000000..7686cb0 --- /dev/null +++ b/sdwindow.ui @@ -0,0 +1,77 @@ + + + SDWindow + + + + 0 + 0 + 199 + 246 + + + + Dialog + + + + + + Print file: + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + + + + + buttonBox + accepted() + SDWindow + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SDWindow + reject() + + + 316 + 260 + + + 286 + 274 + + + + +