Added comments and reorganized

This commit is contained in:
NeoTheFox 2015-03-14 18:15:31 +03:00
parent a30e869e61
commit 53283605e0
2 changed files with 46 additions and 24 deletions

View File

@ -84,9 +84,15 @@ MainWindow::MainWindow(QWidget *parent) :
connect(progressSDTimer, SIGNAL(timeout()), this, SLOT(checkSDStatus())); connect(progressSDTimer, SIGNAL(timeout()), this, SLOT(checkSDStatus()));
connect(this, SIGNAL(eepromReady()), this, SLOT(openEEPROMeditor())); connect(this, SIGNAL(eepromReady()), this, SLOT(openEEPROMeditor()));
//Parser thread signal-slots and init //Register all the types
qRegisterMetaType<TemperatureReadings>("TemperatureReadings"); qRegisterMetaType<TemperatureReadings>("TemperatureReadings");
qRegisterMetaType<SDProgress>("SDProgress"); qRegisterMetaType<SDProgress>("SDProgress");
qRegisterMetaType<QSerialPortInfo>("QSerialPortInfo");
qRegisterMetaType< QVector<QString> >("QVector<QString>");
qRegisterMetaType<FileProgress>("FileProgress");
qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
//Parser thread signal-slots and init
parserWorker->moveToThread(parserThread); parserWorker->moveToThread(parserThread);
connect(parserThread, &QThread::finished, parserWorker, &QObject::deleteLater); connect(parserThread, &QThread::finished, parserWorker, &QObject::deleteLater);
connect(this, &MainWindow::recievedData, parserWorker, &Parser::parse); connect(this, &MainWindow::recievedData, parserWorker, &Parser::parse);
@ -101,10 +107,6 @@ MainWindow::MainWindow(QWidget *parent) :
parserThread->start(); parserThread->start();
//Sender thread signal-slots and init //Sender thread signal-slots and init
qRegisterMetaType<QSerialPortInfo>("QSerialPortInfo");
qRegisterMetaType< QVector<QString> >("QVector<QString>");
qRegisterMetaType<FileProgress>("FileProgress");
qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
senderWorker->moveToThread(senderThread); senderWorker->moveToThread(senderThread);
connect(senderThread, &QThread::finished, senderWorker, &QObject::deleteLater); connect(senderThread, &QThread::finished, senderWorker, &QObject::deleteLater);
connect(parserWorker, &Parser::recievedOkNum, senderWorker, &Sender::recievedOkNum); connect(parserWorker, &Parser::recievedOkNum, senderWorker, &Sender::recievedOkNum);
@ -133,6 +135,7 @@ MainWindow::MainWindow(QWidget *parent) :
sinceLastTemp->start(); sinceLastTemp->start();
sinceLastSDStatus->start(); sinceLastSDStatus->start();
//Update recent files list
updateRecent(); updateRecent();
} }
@ -144,7 +147,6 @@ MainWindow::~MainWindow()
settings.setValue("core/checktemperature", ui->checktemp->isChecked()); settings.setValue("core/checktemperature", ui->checktemp->isChecked());
settings.setValue("user/extrudertemp", ui->etmpspin->value()); settings.setValue("user/extrudertemp", ui->etmpspin->value());
settings.setValue("user/bedtemp", ui->btmpspin->value()); settings.setValue("user/bedtemp", ui->btmpspin->value());
settings.beginWriteArray("user/recentfiles"); settings.beginWriteArray("user/recentfiles");
for(int i = 0; i < recentFiles.size(); ++i) for(int i = 0; i < recentFiles.size(); ++i)
{ {
@ -155,6 +157,8 @@ MainWindow::~MainWindow()
//Cleanup what is left //Cleanup what is left
if(gfile.isOpen()) gfile.close(); if(gfile.isOpen()) gfile.close();
statusTimer->stop();
progressSDTimer->stop();
parserThread->quit(); parserThread->quit();
parserThread->wait(); parserThread->wait();
senderThread->quit(); senderThread->quit();
@ -207,18 +211,23 @@ void MainWindow::parseFile(QString filename)
void MainWindow::serialupdate() void MainWindow::serialupdate()
{ {
//Clear old serialports
ui->serialBox->clear(); ui->serialBox->clear();
//Save ports list
QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts(); QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();
//Populate the combobox
for(int i = 0; i < list.size(); i++) for(int i = 0; i < list.size(); i++)
ui->serialBox->addItem(list.at(i).portName()); ui->serialBox->addItem(list.at(i).portName());
} }
void MainWindow::serialconnect() void MainWindow::serialconnect()
{ {
//Hust to be safe - wipe all the user commands
emit flushInjectionBuffer(); emit flushInjectionBuffer();
if(!opened) if(!opened)
{ {
//Find the portinfo we need
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{ {
if(info.portName() == ui->serialBox->currentText()) if(info.portName() == ui->serialBox->currentText())
@ -228,12 +237,14 @@ void MainWindow::serialconnect()
} }
} }
//Emit signals needed
emit setBaudrate(ui->baudbox->currentText().toInt()); emit setBaudrate(ui->baudbox->currentText().toInt());
emit openPort(printerinfo); emit openPort(printerinfo);
//Set the flag right
opened=true; opened=true;
//Update UI
ui->connectBtn->setText("Disconnect"); ui->connectBtn->setText("Disconnect");
ui->sendBtn->setDisabled(false); ui->sendBtn->setDisabled(false);
//ui->pauseBtn->setDisabled(false);
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
ui->controlBox->setDisabled(false); ui->controlBox->setDisabled(false);
ui->consoleGroup->setDisabled(false); ui->consoleGroup->setDisabled(false);
@ -245,8 +256,11 @@ void MainWindow::serialconnect()
else if(opened) else if(opened)
{ {
//Emit closing signal to Sender
emit closePort(); emit closePort();
//Set the flag
opened = false;
//Update UI
ui->connectBtn->setText("Connect"); ui->connectBtn->setText("Connect");
ui->sendBtn->setDisabled(true); ui->sendBtn->setDisabled(true);
ui->pauseBtn->setDisabled(true); ui->pauseBtn->setDisabled(true);
@ -257,7 +271,6 @@ void MainWindow::serialconnect()
ui->actionSet_SD_printing_mode->setDisabled(true); ui->actionSet_SD_printing_mode->setDisabled(true);
ui->statusGroup->setDisabled(true); ui->statusGroup->setDisabled(true);
ui->actionEEPROM_editor->setDisabled(false); ui->actionEEPROM_editor->setDisabled(false);
opened = false;
} }
} }
@ -539,29 +552,26 @@ void MainWindow::readSerial(QByteArray data)
printMsg(QString(data)); //echo printMsg(QString(data)); //echo
} }
void MainWindow::printMsg(const char* text)
{
QTextCursor cursor = ui->terminal->textCursor();
cursor.movePosition(QTextCursor::End);
cursor.insertText(text);
ui->terminal->setTextCursor(cursor);
}
void MainWindow::printMsg(QString text) void MainWindow::printMsg(QString text)
{ {
//Get the cursor and set it to the end
QTextCursor cursor = ui->terminal->textCursor(); QTextCursor cursor = ui->terminal->textCursor();
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
//Paste the text
cursor.insertText(text); cursor.insertText(text);
//Apply
ui->terminal->setTextCursor(cursor); ui->terminal->setTextCursor(cursor);
} }
void MainWindow::checkStatus() void MainWindow::checkStatus()
{ {
//We want to check for few things here:
//if we are checking temperature at all and
//if the time passed from the time we last
//recieved update is more than the check
//interval
if(checkingTemperature if(checkingTemperature
&&(sinceLastTemp->elapsed() > statusTimer->interval())) emit injectCommand("M105"); &&(sinceLastTemp->elapsed() > statusTimer->interval())) emit injectCommand("M105");
} }
@ -596,13 +606,22 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
if(error == QSerialPort::NoError) return; if(error == QSerialPort::NoError) return;
if(error == QSerialPort::NotOpenError) return; //this error is internal if(error == QSerialPort::NotOpenError) return; //this error is internal
emit closePort(); emit closePort(); //If the port is still open we need to close it
//Set RepRaptor to pause if printing
//We dont want to stop the printing,
//in order to be able to continue it
//after possible connection fail
if(sending) paused = true; if(sending) paused = true;
emit pause(paused); emit pause(paused);
//Flush all the user commands
emit flushInjectionBuffer(); emit flushInjectionBuffer();
//Set the flag
opened = false;
//Update UI
ui->connectBtn->setText("Connect"); ui->connectBtn->setText("Connect");
ui->sendBtn->setDisabled(true); ui->sendBtn->setDisabled(true);
ui->pauseBtn->setDisabled(true); ui->pauseBtn->setDisabled(true);
@ -611,10 +630,11 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
ui->actionPrint_from_SD->setDisabled(true); ui->actionPrint_from_SD->setDisabled(true);
ui->actionSet_SD_printing_mode->setDisabled(true); ui->actionSet_SD_printing_mode->setDisabled(true);
ui->actionEEPROM_editor->setDisabled(true); ui->actionEEPROM_editor->setDisabled(true);
opened = false;
//Print error to qDebug to see it in terminal
qDebug() << error; qDebug() << error;
//Identify error
QString errorMsg; QString errorMsg;
switch(error) switch(error)
{ {
@ -634,6 +654,7 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
errorMsg = "Serial connection timed out"; errorMsg = "Serial connection timed out";
break; break;
//These errors are the same really
case QSerialPort::WriteError: case QSerialPort::WriteError:
case QSerialPort::ReadError: case QSerialPort::ReadError:
errorMsg = "I/O Error"; errorMsg = "I/O Error";
@ -648,6 +669,7 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
break; break;
} }
//Spawn the error message
ErrorWindow errorwindow(this, errorMsg); ErrorWindow errorwindow(this, errorMsg);
errorwindow.exec(); errorwindow.exec();
} }
@ -662,7 +684,7 @@ void MainWindow::updateTemperature(TemperatureReadings r)
void MainWindow::initSDprinting(QStringList sdFiles) void MainWindow::initSDprinting(QStringList sdFiles)
{ {
SDWindow sdwindow(sdFiles, this); //Made it to 666 lines! SDWindow sdwindow(sdFiles, this);
connect(&sdwindow, SIGNAL(fileSelected(QString)), this, SLOT(selectSDfile(QString))); connect(&sdwindow, SIGNAL(fileSelected(QString)), this, SLOT(selectSDfile(QString)));
@ -707,6 +729,7 @@ void MainWindow::updateSDStatus(SDProgress p)
void MainWindow::checkSDStatus() void MainWindow::checkSDStatus()
{ {
//Same as temperature check
if(sdprinting && chekingSDStatus && sinceLastSDStatus->elapsed() > progressSDTimer->interval()) if(sdprinting && chekingSDStatus && sinceLastSDStatus->elapsed() > progressSDTimer->interval())
emit injectCommand("M27"); emit injectCommand("M27");
} }

View File

@ -82,7 +82,6 @@ private slots:
void serialupdate(); void serialupdate();
void readSerial(QByteArray data); void readSerial(QByteArray data);
void printMsg(QString text); void printMsg(QString text);
void printMsg(const char* text);
void checkStatus(); void checkStatus();
void updateRecent(); void updateRecent();
void initSDprinting(QStringList sdFiles); void initSDprinting(QStringList sdFiles);