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