Moved sender to other thread
This commit is contained in:
parent
fea7f342c1
commit
b4ce73c959
204
mainwindow.cpp
204
mainwindow.cpp
@ -64,6 +64,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
paused = false;
|
paused = false;
|
||||||
readingFiles = false;
|
readingFiles = false;
|
||||||
sdprinting = false;
|
sdprinting = false;
|
||||||
|
opened = false;
|
||||||
sdBytes = 0;
|
sdBytes = 0;
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
readyRecieve = false;
|
readyRecieve = false;
|
||||||
@ -107,6 +108,10 @@ 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 = new Sender();
|
senderWorker = new Sender();
|
||||||
senderThread = new QThread();
|
senderThread = new QThread();
|
||||||
senderWorker->moveToThread(senderThread);
|
senderWorker->moveToThread(senderThread);
|
||||||
@ -116,12 +121,23 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(parserWorker, &Parser::recievedResend, senderWorker, &Sender::recievedResend);
|
connect(parserWorker, &Parser::recievedResend, senderWorker, &Sender::recievedResend);
|
||||||
connect(parserWorker, &Parser::recievedStart, senderWorker, &Sender::recievedStart);
|
connect(parserWorker, &Parser::recievedStart, senderWorker, &Sender::recievedStart);
|
||||||
connect(senderWorker, &Sender::errorRecieved, this, &MainWindow::serialError);
|
connect(senderWorker, &Sender::errorRecieved, this, &MainWindow::serialError);
|
||||||
connect(senderWorker, &Sender::dataRecieved, parserWorker, &Parser::parse);
|
connect(senderWorker, &Sender::dataRecieved, parserWorker, &Parser::parse, Qt::QueuedConnection);
|
||||||
|
connect(senderWorker, &Sender::dataRecieved, this, &MainWindow::readSerial, Qt::QueuedConnection);
|
||||||
|
connect(senderWorker, &Sender::reportProgress, this, &MainWindow::updateFileProgress);
|
||||||
|
connect(this, &MainWindow::setFile, senderWorker, &Sender::setFile);
|
||||||
|
connect(this, &MainWindow::startPrinting, senderWorker, &Sender::startPrinting);
|
||||||
|
connect(this, &MainWindow::stopPrinting, senderWorker, &Sender::stopPrinting);
|
||||||
|
connect(this, &MainWindow::pause, senderWorker, &Sender::pause);
|
||||||
|
connect(this, &MainWindow::setBaudrate, senderWorker, &Sender::setBaudrate);
|
||||||
|
connect(this, &MainWindow::openPort, senderWorker, &Sender::openPort);
|
||||||
|
connect(this, &MainWindow::closePort, senderWorker, &Sender::closePort);
|
||||||
|
connect(this, &MainWindow::injectCommand, senderWorker, &Sender::injectCommand);
|
||||||
|
connect(this, &MainWindow::flushInjectionBuffer, senderWorker, &Sender::flushInjectionBuffer);
|
||||||
senderThread->start();
|
senderThread->start();
|
||||||
|
|
||||||
//Timers init
|
//Timers init
|
||||||
statusTimer.start();
|
statusTimer.start();
|
||||||
sendTimer.start();
|
//sendTimer.start();
|
||||||
progressSDTimer.setInterval(2500);
|
progressSDTimer.setInterval(2500);
|
||||||
if(chekingSDStatus) progressSDTimer.start();
|
if(chekingSDStatus) progressSDTimer.start();
|
||||||
sinceLastTemp.start();
|
sinceLastTemp.start();
|
||||||
@ -185,7 +201,6 @@ void MainWindow::parseFile(QString filename)
|
|||||||
if (gfile.open(QIODevice::ReadOnly))
|
if (gfile.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
QTextStream in(&gfile);
|
QTextStream in(&gfile);
|
||||||
int n = 0;
|
|
||||||
while (!in.atEnd())
|
while (!in.atEnd())
|
||||||
{
|
{
|
||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
@ -238,9 +253,9 @@ void MainWindow::serialupdate()
|
|||||||
|
|
||||||
void MainWindow::serialconnect()
|
void MainWindow::serialconnect()
|
||||||
{
|
{
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
|
|
||||||
if(!printer.isOpen())
|
if(!opened)
|
||||||
{
|
{
|
||||||
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
||||||
{
|
{
|
||||||
@ -253,35 +268,7 @@ void MainWindow::serialconnect()
|
|||||||
|
|
||||||
emit setBaudrate(ui->baudbox->currentText().toInt());
|
emit setBaudrate(ui->baudbox->currentText().toInt());
|
||||||
emit openPort(printerinfo);
|
emit openPort(printerinfo);
|
||||||
}
|
opened=true;
|
||||||
//printer.setPort(printerinfo);
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(printer.open(QIODevice::ReadWrite))
|
|
||||||
{
|
|
||||||
|
|
||||||
//Moved here to be compatible with Qt 5.2.1
|
|
||||||
switch(ui->baudbox->currentText().toInt())
|
|
||||||
{
|
|
||||||
case 4800:
|
|
||||||
printer.setBaudRate(QSerialPort::Baud4800);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 9600:
|
|
||||||
printer.setBaudRate(QSerialPort::Baud9600);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 115200:
|
|
||||||
printer.setBaudRate(QSerialPort::Baud115200);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printer.setBaudRate(ui->baudbox->currentText().toInt());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.setFlowControl(QSerialPort::HardwareControl);
|
|
||||||
|
|
||||||
ui->connectBtn->setText("Disconnect");
|
ui->connectBtn->setText("Disconnect");
|
||||||
ui->sendBtn->setDisabled(false);
|
ui->sendBtn->setDisabled(false);
|
||||||
//ui->pauseBtn->setDisabled(false);
|
//ui->pauseBtn->setDisabled(false);
|
||||||
@ -293,11 +280,10 @@ void MainWindow::serialconnect()
|
|||||||
ui->actionSet_SD_printing_mode->setEnabled(true);
|
ui->actionSet_SD_printing_mode->setEnabled(true);
|
||||||
if(firmware == Repetier) ui->actionEEPROM_editor->setDisabled(false);
|
if(firmware == Repetier) ui->actionEEPROM_editor->setDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
else if(printer.isOpen())
|
else if(opened)
|
||||||
{
|
{
|
||||||
printer.close();
|
emit closePort();
|
||||||
|
|
||||||
ui->connectBtn->setText("Connect");
|
ui->connectBtn->setText("Connect");
|
||||||
ui->sendBtn->setDisabled(true);
|
ui->sendBtn->setDisabled(true);
|
||||||
@ -309,8 +295,9 @@ 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;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
@ -319,123 +306,123 @@ void MainWindow::serialconnect()
|
|||||||
void MainWindow::xplus()
|
void MainWindow::xplus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 X" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 X" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::xminus()
|
void MainWindow::xminus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 X-" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 X-" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::xhome()
|
void MainWindow::xhome()
|
||||||
{
|
{
|
||||||
injectCommand("G28 X0");
|
emit injectCommand("G28 X0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::yplus()
|
void MainWindow::yplus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 Y" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 Y" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::yminus()
|
void MainWindow::yminus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 Y-" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 Y-" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::yhome()
|
void MainWindow::yhome()
|
||||||
{
|
{
|
||||||
injectCommand("G28 Y0");
|
emit injectCommand("G28 Y0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::zplus()
|
void MainWindow::zplus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 Z" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 Z" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::zminus()
|
void MainWindow::zminus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 Z-" + ui->stepspin->text() + "\nG90";
|
QString command = "G91\nG1 Z-" + ui->stepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::zhome()
|
void MainWindow::zhome()
|
||||||
{
|
{
|
||||||
injectCommand("G28 Z0");
|
emit injectCommand("G28 Z0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::eplus()
|
void MainWindow::eplus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 E" + ui->estepspin->text() + "\nG90";
|
QString command = "G91\nG1 E" + ui->estepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::eminus()
|
void MainWindow::eminus()
|
||||||
{
|
{
|
||||||
QString command = "G91\nG1 E-" + ui->estepspin->text() + "\nG90";
|
QString command = "G91\nG1 E-" + ui->estepspin->text() + "\nG90";
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ezero()
|
void MainWindow::ezero()
|
||||||
{
|
{
|
||||||
injectCommand("G92 E0");
|
emit injectCommand("G92 E0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::homeall()
|
void MainWindow::homeall()
|
||||||
{
|
{
|
||||||
injectCommand("G28");
|
emit injectCommand("G28");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_sendbtn_clicked()
|
void MainWindow::on_sendbtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand(ui->sendtext->text());
|
emit injectCommand(ui->sendtext->text());
|
||||||
userHistory.append(ui->sendtext->text());
|
userHistory.append(ui->sendtext->text());
|
||||||
userHistoryPos = 0;
|
userHistoryPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_fanonbtn_clicked()
|
void MainWindow::on_fanonbtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M106");
|
emit injectCommand("M106");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_fanoffbtn_clicked()
|
void MainWindow::on_fanoffbtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M107");
|
emit injectCommand("M107");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_atxonbtn_clicked()
|
void MainWindow::on_atxonbtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M80");
|
emit injectCommand("M80");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_atxoffbtn_clicked()
|
void MainWindow::on_atxoffbtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M81");
|
emit injectCommand("M81");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_etmpset_clicked()
|
void MainWindow::on_etmpset_clicked()
|
||||||
{
|
{
|
||||||
QString command = "M80\nM104 S" + ui->etmpspin->text();
|
QString command = "M80\nM104 S" + ui->etmpspin->text();
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_etmpoff_clicked()
|
void MainWindow::on_etmpoff_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M104 S0");
|
emit injectCommand("M104 S0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_btmpset_clicked()
|
void MainWindow::on_btmpset_clicked()
|
||||||
{
|
{
|
||||||
QString command = "M80\nM140 S" + ui->btmpspin->text();
|
QString command = "M80\nM140 S" + ui->btmpspin->text();
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_btmpoff_clicked()
|
void MainWindow::on_btmpoff_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M140 S0");
|
emit injectCommand("M140 S0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::bedcenter()
|
void MainWindow::bedcenter()
|
||||||
@ -446,7 +433,7 @@ void MainWindow::bedcenter()
|
|||||||
y = settings.value("printer/bedy", 200).toInt();
|
y = settings.value("printer/bedy", 200).toInt();
|
||||||
|
|
||||||
QString command = "G1 X" + QString::number(x/2) + "Y" + QString::number(y/2);
|
QString command = "G1 X" + QString::number(x/2) + "Y" + QString::number(y/2);
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_speedslider_valueChanged(int value)
|
void MainWindow::on_speedslider_valueChanged(int value)
|
||||||
@ -463,7 +450,7 @@ void MainWindow::on_speededit_textChanged(const QString &arg1)
|
|||||||
void MainWindow::on_speedsetbtn_clicked()
|
void MainWindow::on_speedsetbtn_clicked()
|
||||||
{
|
{
|
||||||
QString command = "M220 S" + QString::number(ui->speedslider->value());
|
QString command = "M220 S" + QString::number(ui->speedslider->value());
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_flowedit_textChanged(const QString &arg1)
|
void MainWindow::on_flowedit_textChanged(const QString &arg1)
|
||||||
@ -480,25 +467,24 @@ void MainWindow::on_flowslider_valueChanged(int value)
|
|||||||
void MainWindow::on_flowbutton_clicked()
|
void MainWindow::on_flowbutton_clicked()
|
||||||
{
|
{
|
||||||
QString command = "M221 S" + QString::number(ui->flowslider->value());
|
QString command = "M221 S" + QString::number(ui->flowslider->value());
|
||||||
injectCommand(command);
|
emit injectCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_haltbtn_clicked()
|
void MainWindow::on_haltbtn_clicked()
|
||||||
{
|
{
|
||||||
if(sending && !paused)ui->pauseBtn->click();
|
if(sending && !paused)ui->pauseBtn->click();
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
injectCommand("M112");
|
emit injectCommand("M112");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionPrint_from_SD_triggered()
|
void MainWindow::on_actionPrint_from_SD_triggered()
|
||||||
{
|
{
|
||||||
injectCommand("M20");
|
emit injectCommand("M20");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_sendBtn_clicked()
|
void MainWindow::on_sendBtn_clicked()
|
||||||
{
|
{
|
||||||
/*
|
emit flushInjectionBuffer();
|
||||||
userCommands.clear();
|
|
||||||
if(sending && !sdprinting)
|
if(sending && !sdprinting)
|
||||||
{
|
{
|
||||||
sending = false;
|
sending = false;
|
||||||
@ -507,6 +493,8 @@ void MainWindow::on_sendBtn_clicked()
|
|||||||
ui->pauseBtn->setDisabled(true);
|
ui->pauseBtn->setDisabled(true);
|
||||||
if(autolock) ui->controlBox->setChecked(true);
|
if(autolock) ui->controlBox->setChecked(true);
|
||||||
paused = false;
|
paused = false;
|
||||||
|
emit pause(paused);
|
||||||
|
emit stopPrinting();
|
||||||
}
|
}
|
||||||
else if(!sending && !sdprinting)
|
else if(!sending && !sdprinting)
|
||||||
{
|
{
|
||||||
@ -516,23 +504,24 @@ void MainWindow::on_sendBtn_clicked()
|
|||||||
ui->pauseBtn->setEnabled(true);
|
ui->pauseBtn->setEnabled(true);
|
||||||
if(autolock) ui->controlBox->setChecked(false);
|
if(autolock) ui->controlBox->setChecked(false);
|
||||||
paused = false;
|
paused = false;
|
||||||
|
emit pause(paused);
|
||||||
|
emit startPrinting();
|
||||||
}
|
}
|
||||||
else if(sdprinting)
|
else if(sdprinting)
|
||||||
{
|
{
|
||||||
sending = false;
|
sending = false;
|
||||||
injectCommand("M24");
|
emit injectCommand("M24");
|
||||||
injectCommand("M27");
|
emit injectCommand("M27");
|
||||||
ui->sendBtn->setText("Start");
|
ui->sendBtn->setText("Start");
|
||||||
ui->pauseBtn->setText("Pause");
|
ui->pauseBtn->setText("Pause");
|
||||||
ui->pauseBtn->setEnabled(true);
|
ui->pauseBtn->setEnabled(true);
|
||||||
if(autolock) ui->controlBox->setChecked(true);
|
if(autolock) ui->controlBox->setChecked(true);
|
||||||
paused = false;
|
paused = false;
|
||||||
|
emit pause(paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
*/
|
|
||||||
emit startPrinting();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pauseBtn_clicked()
|
void MainWindow::on_pauseBtn_clicked()
|
||||||
@ -540,42 +529,35 @@ void MainWindow::on_pauseBtn_clicked()
|
|||||||
if(paused && !sdprinting)
|
if(paused && !sdprinting)
|
||||||
{
|
{
|
||||||
paused = false;
|
paused = false;
|
||||||
|
emit pause(paused);
|
||||||
if(autolock) ui->controlBox->setChecked(false);
|
if(autolock) ui->controlBox->setChecked(false);
|
||||||
ui->pauseBtn->setText("Pause");
|
ui->pauseBtn->setText("Pause");
|
||||||
}
|
}
|
||||||
else if(!paused && !sdprinting)
|
else if(!paused && !sdprinting)
|
||||||
{
|
{
|
||||||
paused = true;
|
paused = true;
|
||||||
|
emit pause(paused);
|
||||||
if(autolock) ui->controlBox->setChecked(true);
|
if(autolock) ui->controlBox->setChecked(true);
|
||||||
ui->pauseBtn->setText("Resume");
|
ui->pauseBtn->setText("Resume");
|
||||||
}
|
}
|
||||||
else if(sdprinting)
|
else if(sdprinting)
|
||||||
{
|
{
|
||||||
injectCommand("M25");
|
emit injectCommand("M25");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_releasebtn_clicked()
|
void MainWindow::on_releasebtn_clicked()
|
||||||
{
|
{
|
||||||
injectCommand("M84");
|
emit injectCommand("M84");
|
||||||
}
|
}
|
||||||
/////////////////
|
/////////////////
|
||||||
//Buttons end //
|
//Buttons end //
|
||||||
/////////////////
|
/////////////////
|
||||||
|
|
||||||
void MainWindow::readSerial()
|
void MainWindow::readSerial(QByteArray data)
|
||||||
{
|
{
|
||||||
if(printer.canReadLine()) //Check if full line in buffer
|
|
||||||
{
|
|
||||||
QByteArray data = printer.readLine(); //Read the line
|
|
||||||
|
|
||||||
emit recievedData(data); //Send data to parser thread
|
|
||||||
|
|
||||||
if(data.startsWith("ok") || data.startsWith("wa")) readyRecieve = true;
|
|
||||||
|
|
||||||
printMsg(QString(data)); //echo
|
printMsg(QString(data)); //echo
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::printMsg(const char* text)
|
void MainWindow::printMsg(const char* text)
|
||||||
{
|
{
|
||||||
@ -628,7 +610,7 @@ void MainWindow::sendNext()
|
|||||||
+ QString("/")
|
+ QString("/")
|
||||||
+ QString::number(currentLine)
|
+ QString::number(currentLine)
|
||||||
+ QString(" Lines"));
|
+ QString(" Lines"));
|
||||||
if(sendingChecksum) injectCommand("M110 N0");
|
if(sendingChecksum) emit injectCommand("M110 N0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendLine(gcode.at(currentLine));
|
sendLine(gcode.at(currentLine));
|
||||||
@ -647,7 +629,7 @@ void MainWindow::sendNext()
|
|||||||
void MainWindow::checkStatus()
|
void MainWindow::checkStatus()
|
||||||
{
|
{
|
||||||
if(checkingTemperature
|
if(checkingTemperature
|
||||||
&&(sinceLastTemp.elapsed() > statusTimer.interval())) injectCommand("M105");
|
&&(sinceLastTemp.elapsed() > statusTimer.interval())) emit injectCommand("M105");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_checktemp_stateChanged(int arg1)
|
void MainWindow::on_checktemp_stateChanged(int arg1)
|
||||||
@ -670,11 +652,6 @@ void MainWindow::on_actionAbout_triggered()
|
|||||||
aboutwindow.exec();
|
aboutwindow.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::injectCommand(QString command)
|
|
||||||
{
|
|
||||||
if(!userCommands.contains(command)) userCommands.enqueue(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateRecent()
|
void MainWindow::updateRecent()
|
||||||
{
|
{
|
||||||
if(!recentFiles.isEmpty()) //If array is empty we should not be bothered
|
if(!recentFiles.isEmpty()) //If array is empty we should not be bothered
|
||||||
@ -702,8 +679,9 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
|
|||||||
if(printer.isOpen()) printer.close();
|
if(printer.isOpen()) printer.close();
|
||||||
|
|
||||||
if(sending) paused = true;
|
if(sending) paused = true;
|
||||||
|
emit pause(paused);
|
||||||
|
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
|
|
||||||
ui->connectBtn->setText("Connect");
|
ui->connectBtn->setText("Connect");
|
||||||
ui->sendBtn->setDisabled(true);
|
ui->sendBtn->setDisabled(true);
|
||||||
@ -713,6 +691,7 @@ 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;
|
||||||
|
|
||||||
qDebug() << error;
|
qDebug() << error;
|
||||||
|
|
||||||
@ -793,8 +772,8 @@ void MainWindow::selectSDfile(QString file)
|
|||||||
ui->sendBtn->setText("Start");
|
ui->sendBtn->setText("Start");
|
||||||
sdBytes = bytes.toDouble();
|
sdBytes = bytes.toDouble();
|
||||||
|
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
injectCommand("M23 " + filename);
|
emit injectCommand("M23 " + filename);
|
||||||
sdprinting = true;
|
sdprinting = true;
|
||||||
ui->fileBox->setDisabled(false);
|
ui->fileBox->setDisabled(false);
|
||||||
}
|
}
|
||||||
@ -814,7 +793,7 @@ void MainWindow::updateSDStatus(SDProgress p)
|
|||||||
void MainWindow::checkSDStatus()
|
void MainWindow::checkSDStatus()
|
||||||
{
|
{
|
||||||
if(sdprinting && chekingSDStatus && sinceLastSDStatus.elapsed() > progressSDTimer.interval())
|
if(sdprinting && chekingSDStatus && sinceLastSDStatus.elapsed() > progressSDTimer.interval())
|
||||||
injectCommand("M27");
|
emit injectCommand("M27");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_stepspin_valueChanged(const QString &arg1)
|
void MainWindow::on_stepspin_valueChanged(const QString &arg1)
|
||||||
@ -839,16 +818,16 @@ void MainWindow::on_actionSet_SD_printing_mode_triggered()
|
|||||||
|
|
||||||
void MainWindow::requestEEPROMSettings()
|
void MainWindow::requestEEPROMSettings()
|
||||||
{
|
{
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
EEPROMSettings.clear();
|
EEPROMSettings.clear();
|
||||||
|
|
||||||
switch(firmware)
|
switch(firmware)
|
||||||
{
|
{
|
||||||
case Marlin:
|
case Marlin:
|
||||||
injectCommand("M503");
|
emit injectCommand("M503");
|
||||||
break;
|
break;
|
||||||
case Repetier:
|
case Repetier:
|
||||||
injectCommand("M205");
|
emit injectCommand("M205");
|
||||||
break;
|
break;
|
||||||
case OtherFirmware:
|
case OtherFirmware:
|
||||||
return;
|
return;
|
||||||
@ -874,10 +853,10 @@ void MainWindow::openEEPROMeditor()
|
|||||||
|
|
||||||
void MainWindow::sendEEPROMsettings(QStringList changes)
|
void MainWindow::sendEEPROMsettings(QStringList changes)
|
||||||
{
|
{
|
||||||
userCommands.clear();
|
emit flushInjectionBuffer();
|
||||||
foreach (QString str, changes)
|
foreach (QString str, changes)
|
||||||
{
|
{
|
||||||
injectCommand(str);
|
emit injectCommand(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -913,7 +892,7 @@ void MainWindow::recievedSDDone()
|
|||||||
|
|
||||||
void MainWindow::recievedResend(int num)
|
void MainWindow::recievedResend(int num)
|
||||||
{
|
{
|
||||||
if(!sendingChecksum) injectCommand("M110 N0");
|
if(!sendingChecksum) emit injectCommand("M110 N0");
|
||||||
else resendLineNum = num;
|
else resendLineNum = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -922,6 +901,29 @@ void MainWindow::recievedStart()
|
|||||||
readyRecieve = true;
|
readyRecieve = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateFileProgress(FileProgress p)
|
||||||
|
{
|
||||||
|
if(p.P >= p.T)
|
||||||
|
{
|
||||||
|
ui->sendBtn->setText("Send");
|
||||||
|
ui->pauseBtn->setDisabled(true);
|
||||||
|
sending = false;
|
||||||
|
paused = false;
|
||||||
|
emit pause(paused);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->sendBtn->setText("Stop");
|
||||||
|
ui->pauseBtn->setEnabled(true);
|
||||||
|
sending = true;
|
||||||
|
}
|
||||||
|
ui->filelines->setText(QString::number(p.P)
|
||||||
|
+ QString("/")
|
||||||
|
+ QString::number(p.T)
|
||||||
|
+ QString(" Lines"));
|
||||||
|
ui->progressBar->setValue(((float)p.P/p.T) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if(obj == ui->sendtext && !userHistory.isEmpty())
|
if(obj == ui->sendtext && !userHistory.isEmpty())
|
||||||
|
|||||||
@ -64,8 +64,10 @@ private:
|
|||||||
|
|
||||||
QSerialPort printer;
|
QSerialPort printer;
|
||||||
QSerialPortInfo printerinfo;
|
QSerialPortInfo printerinfo;
|
||||||
|
bool opened;
|
||||||
bool firstrun;
|
bool firstrun;
|
||||||
bool autolock;
|
bool autolock;
|
||||||
|
bool printing;
|
||||||
bool sending;
|
bool sending;
|
||||||
bool paused;
|
bool paused;
|
||||||
bool checkingTemperature;
|
bool checkingTemperature;
|
||||||
@ -88,13 +90,12 @@ private slots:
|
|||||||
void serialconnect();
|
void serialconnect();
|
||||||
void serialupdate();
|
void serialupdate();
|
||||||
bool sendLine(QString line);
|
bool sendLine(QString line);
|
||||||
void readSerial();
|
void readSerial(QByteArray data);
|
||||||
void printMsg(QString text);
|
void printMsg(QString text);
|
||||||
void printMsg(const char* text);
|
void printMsg(const char* text);
|
||||||
void sendNext();
|
void sendNext();
|
||||||
void checkStatus();
|
void checkStatus();
|
||||||
void updateRecent();
|
void updateRecent();
|
||||||
void injectCommand(QString command);
|
|
||||||
void initSDprinting(QStringList sdFiles);
|
void initSDprinting(QStringList sdFiles);
|
||||||
void selectSDfile(QString file);
|
void selectSDfile(QString file);
|
||||||
void checkSDStatus();
|
void checkSDStatus();
|
||||||
@ -112,6 +113,7 @@ private slots:
|
|||||||
void recievedStart();
|
void recievedStart();
|
||||||
void parseFile(QString filename);
|
void parseFile(QString filename);
|
||||||
void recentClicked();
|
void recentClicked();
|
||||||
|
void updateFileProgress(FileProgress);
|
||||||
|
|
||||||
void xplus();
|
void xplus();
|
||||||
void yplus();
|
void yplus();
|
||||||
@ -170,6 +172,8 @@ signals:
|
|||||||
void pause(bool p);
|
void pause(bool p);
|
||||||
void setBaudrate(int b);
|
void setBaudrate(int b);
|
||||||
void setFile(QVector <QString> f);
|
void setFile(QVector <QString> f);
|
||||||
|
void injectCommand(QString command);
|
||||||
|
void flushInjectionBuffer();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -28,6 +28,11 @@ namespace RepRaptor
|
|||||||
{
|
{
|
||||||
unsigned long int progress, total;
|
unsigned long int progress, total;
|
||||||
} SDProgress;
|
} SDProgress;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned int T, P;
|
||||||
|
} FileProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // REPRAPTOR_H
|
#endif // REPRAPTOR_H
|
||||||
|
|||||||
21
sender.cpp
21
sender.cpp
@ -17,6 +17,8 @@ Sender::Sender(QObject *parent) : QObject(parent)
|
|||||||
sendTimer.setInterval(settings.value("core/senderinterval", 2).toInt());
|
sendTimer.setInterval(settings.value("core/senderinterval", 2).toInt());
|
||||||
sendingChecksum = settings.value("core/checksums", 0).toBool();
|
sendingChecksum = settings.value("core/checksums", 0).toBool();
|
||||||
|
|
||||||
|
sendTimer.start();
|
||||||
|
|
||||||
connect(printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(recievedError(QSerialPort::SerialPortError)));
|
connect(printer, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(recievedError(QSerialPort::SerialPortError)));
|
||||||
connect(printer, &QSerialPort::readyRead, this, &Sender::recievedData);
|
connect(printer, &QSerialPort::readyRead, this, &Sender::recievedData);
|
||||||
connect(&sendTimer, &QTimer::timeout, this, &Sender::sendNext);
|
connect(&sendTimer, &QTimer::timeout, this, &Sender::sendNext);
|
||||||
@ -41,17 +43,26 @@ void Sender::sendNext()
|
|||||||
}
|
}
|
||||||
else if(sending && !paused && readyRecieve) //Send line of gcode
|
else if(sending && !paused && readyRecieve) //Send line of gcode
|
||||||
{
|
{
|
||||||
|
FileProgress p;
|
||||||
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
|
||||||
{
|
{
|
||||||
sending = false;
|
sending = false;
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
if(sendingChecksum) sendLine("M110 N0");
|
if(sendingChecksum) sendLine("M110 N0");
|
||||||
|
|
||||||
|
p.P = gcode.size();
|
||||||
|
p.T = gcode.size();
|
||||||
|
emit reportProgress(p);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendLine(gcode.at(currentLine));
|
sendLine(gcode.at(currentLine));
|
||||||
currentLine++;
|
currentLine++;
|
||||||
readyRecieve=false;
|
readyRecieve=false;
|
||||||
|
|
||||||
|
p.P = currentLine;
|
||||||
|
p.T = gcode.size();
|
||||||
|
emit reportProgress(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +93,7 @@ void Sender::openPort(QSerialPortInfo i)
|
|||||||
{
|
{
|
||||||
printer->setPort(i);
|
printer->setPort(i);
|
||||||
|
|
||||||
if(printer->open(QIODevice::ReadWrite))
|
if(!printer->isOpen() && printer->open(QIODevice::ReadWrite))
|
||||||
{
|
{
|
||||||
|
|
||||||
//Moved here to be compatible with Qt 5.2.1
|
//Moved here to be compatible with Qt 5.2.1
|
||||||
@ -106,15 +117,12 @@ void Sender::openPort(QSerialPortInfo i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printer->setFlowControl(QSerialPort::HardwareControl);
|
printer->setFlowControl(QSerialPort::HardwareControl);
|
||||||
|
|
||||||
sendTimer.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sender::closePort()
|
void Sender::closePort()
|
||||||
{
|
{
|
||||||
if(printer->isOpen()) printer->close();
|
if(printer->isOpen()) printer->close();
|
||||||
sendTimer.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sender::startPrinting()
|
void Sender::startPrinting()
|
||||||
@ -166,6 +174,11 @@ void Sender::recievedStart()
|
|||||||
readyRecieve = true;
|
readyRecieve = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sender::flushInjectionBuffer()
|
||||||
|
{
|
||||||
|
userCommands.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Sender::recievedResend(int)
|
void Sender::recievedResend(int)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
3
sender.h
3
sender.h
@ -40,7 +40,7 @@ protected:
|
|||||||
signals:
|
signals:
|
||||||
void errorRecieved(QSerialPort::SerialPortError error);
|
void errorRecieved(QSerialPort::SerialPortError error);
|
||||||
void dataRecieved(QByteArray data);
|
void dataRecieved(QByteArray data);
|
||||||
void reportPeogress(SDProgress p);
|
void reportProgress(FileProgress p);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void openPort(QSerialPortInfo i);
|
void openPort(QSerialPortInfo i);
|
||||||
@ -51,6 +51,7 @@ public slots:
|
|||||||
void setBaudrate(int b);
|
void setBaudrate(int b);
|
||||||
void setFile(QVector <QString> f);
|
void setFile(QVector <QString> f);
|
||||||
void injectCommand(QString);
|
void injectCommand(QString);
|
||||||
|
void flushInjectionBuffer();
|
||||||
|
|
||||||
void recievedOkWait();
|
void recievedOkWait();
|
||||||
void recievedOkNum(int);
|
void recievedOkNum(int);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user