Optimizations and bugfixes
This commit is contained in:
parent
e57406ee6b
commit
d62be051dd
@ -129,7 +129,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
//Timers init
|
//Timers init
|
||||||
statusTimer.start();
|
statusTimer.start();
|
||||||
//sendTimer.start();
|
|
||||||
progressSDTimer.setInterval(2500);
|
progressSDTimer.setInterval(2500);
|
||||||
if(chekingSDStatus) progressSDTimer.start();
|
if(chekingSDStatus) progressSDTimer.start();
|
||||||
sinceLastTemp.start();
|
sinceLastTemp.start();
|
||||||
|
|||||||
45
sender.cpp
45
sender.cpp
@ -6,6 +6,8 @@ Sender::Sender(QObject *parent) : QObject(parent)
|
|||||||
currentLine=0;
|
currentLine=0;
|
||||||
totalLineNum=0;
|
totalLineNum=0;
|
||||||
baudrate=115200;
|
baudrate=115200;
|
||||||
|
resendNum = 0;
|
||||||
|
resending = false;
|
||||||
sendingChecksum=false;
|
sendingChecksum=false;
|
||||||
paused=false;
|
paused=false;
|
||||||
sending=false;
|
sending=false;
|
||||||
@ -34,15 +36,36 @@ Sender::~Sender()
|
|||||||
//Mainloop of sending
|
//Mainloop of sending
|
||||||
void Sender::sendNext()
|
void Sender::sendNext()
|
||||||
{
|
{
|
||||||
if(printer->isWritable())
|
if(printer->isWritable() && readyRecieve)
|
||||||
{
|
{
|
||||||
if(!userCommands.isEmpty() && readyRecieve) //Inject user command
|
if(sendingChecksum && resending)
|
||||||
|
{
|
||||||
|
if(resendNum < sentCommands.size())
|
||||||
|
{
|
||||||
|
sendLine(sentCommands.at(resendNum));
|
||||||
|
resendNum++;
|
||||||
|
}
|
||||||
|
else if(resendNum == sentCommands.size())
|
||||||
|
{
|
||||||
|
resending = false;
|
||||||
|
resendNum = 0;
|
||||||
|
}
|
||||||
|
else if(resendNum > sentCommands.size())
|
||||||
|
{
|
||||||
|
sendLine("M110 N0");
|
||||||
|
totalLineNum = 0;
|
||||||
|
resendNum = 0;
|
||||||
|
sentCommands.clear();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!userCommands.isEmpty()) //Inject user command
|
||||||
{
|
{
|
||||||
sendLine(userCommands.dequeue());
|
sendLine(userCommands.dequeue());
|
||||||
readyRecieve = false;
|
readyRecieve = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(sending && !paused && readyRecieve) //Send line of gcode
|
else if(sending && !paused) //Send line of gcode
|
||||||
{
|
{
|
||||||
FileProgress p;
|
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
|
||||||
@ -70,9 +93,10 @@ void Sender::sendNext()
|
|||||||
|
|
||||||
bool Sender::sendLine(QString line)
|
bool Sender::sendLine(QString line)
|
||||||
{
|
{
|
||||||
|
sentCommands.clear();
|
||||||
if(printer->isOpen())
|
if(printer->isOpen())
|
||||||
{
|
{
|
||||||
if(sendingChecksum)
|
if(sendingChecksum && !resending)
|
||||||
{
|
{
|
||||||
if(line.contains("M110")) totalLineNum = 0;
|
if(line.contains("M110")) totalLineNum = 0;
|
||||||
|
|
||||||
@ -83,6 +107,7 @@ bool Sender::sendLine(QString line)
|
|||||||
cs &= 0xff;
|
cs &= 0xff;
|
||||||
line += QString::number(cs);
|
line += QString::number(cs);
|
||||||
totalLineNum++;
|
totalLineNum++;
|
||||||
|
sentCommands.append(line);
|
||||||
}
|
}
|
||||||
if(printer->write(line.toUtf8()+'\n')) return true;
|
if(printer->write(line.toUtf8()+'\n')) return true;
|
||||||
else return false;
|
else return false;
|
||||||
@ -157,7 +182,7 @@ void Sender::setFile(QVector <QString> f)
|
|||||||
|
|
||||||
void Sender::injectCommand(QString command)
|
void Sender::injectCommand(QString command)
|
||||||
{
|
{
|
||||||
if(userCommands.contains(command)) userCommands.enqueue(command);
|
if(!userCommands.contains(command)) userCommands.enqueue(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sender::recievedOkWait()
|
void Sender::recievedOkWait()
|
||||||
@ -180,9 +205,14 @@ void Sender::flushInjectionBuffer()
|
|||||||
userCommands.clear();
|
userCommands.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sender::recievedResend(int)
|
void Sender::recievedResend(int r)
|
||||||
{
|
{
|
||||||
|
if(sendingChecksum)
|
||||||
|
{
|
||||||
|
resending = true;
|
||||||
|
resendNum = r;
|
||||||
|
}
|
||||||
|
else currentLine--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sender::recievedData()
|
void Sender::recievedData()
|
||||||
@ -192,6 +222,7 @@ void Sender::recievedData()
|
|||||||
QByteArray data = printer->readLine();
|
QByteArray data = printer->readLine();
|
||||||
if(data == "") return;
|
if(data == "") return;
|
||||||
emit dataRecieved(data);
|
emit dataRecieved(data);
|
||||||
|
//Yeah, yeah, I know. This class is called "Sender", but checking this here is faster.
|
||||||
if(data.startsWith("ok") || data.startsWith("wa")) readyRecieve=true;
|
if(data.startsWith("ok") || data.startsWith("wa")) readyRecieve=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
sender.h
10
sender.h
@ -23,13 +23,15 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
QSerialPort *printer;
|
QSerialPort *printer;
|
||||||
QTimer *sendTimer;
|
QTimer *sendTimer;
|
||||||
int currentLine;
|
unsigned int currentLine;
|
||||||
int totalLineNum;
|
unsigned int totalLineNum;
|
||||||
int baudrate;
|
unsigned int resendNum;
|
||||||
|
unsigned int baudrate;
|
||||||
bool paused;
|
bool paused;
|
||||||
bool sending;
|
bool sending;
|
||||||
bool readyRecieve;
|
bool readyRecieve;
|
||||||
bool sendingChecksum;
|
bool sendingChecksum;
|
||||||
|
bool resending;
|
||||||
QQueue <QString> userCommands;
|
QQueue <QString> userCommands;
|
||||||
QStringList sentCommands;
|
QStringList sentCommands;
|
||||||
QVector <QString> gcode;
|
QVector <QString> gcode;
|
||||||
@ -55,7 +57,7 @@ public slots:
|
|||||||
void recievedOkWait();
|
void recievedOkWait();
|
||||||
void recievedOkNum(int);
|
void recievedOkNum(int);
|
||||||
void recievedStart();
|
void recievedStart();
|
||||||
void recievedResend(int);
|
void recievedResend(int r);
|
||||||
|
|
||||||
void sendNext();
|
void sendNext();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user