Getting ready for checksum support
This commit is contained in:
parent
3bb5133ea9
commit
763bc62b26
@ -25,13 +25,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->baudbox->addItem(QString::number(250000));
|
||||
ui->baudbox->addItem(QString::number(460800));
|
||||
ui->baudbox->addItem(QString::number(500000));
|
||||
if(settings.value("printer/baudrateindex").toInt()) ui->baudbox->setCurrentIndex(settings.value("printer/baudrateindex").toInt());
|
||||
if(settings.value("printer/baudrateindex").toInt())
|
||||
ui->baudbox->setCurrentIndex(settings.value("printer/baudrateindex").toInt());
|
||||
else ui->baudbox->setCurrentIndex(2);
|
||||
|
||||
ui->extruderlcd->setPalette(Qt::red);
|
||||
ui->bedlcd->setPalette(Qt::red);
|
||||
|
||||
if(!settings.value("core/firstrun").toBool()) firstrun = true;
|
||||
firstrun = !settings.value("core/firstrun").toBool(); //firstrun is inverted!
|
||||
|
||||
checkingTemperature = settings.value("core/checktemperature").toBool();
|
||||
ui->checktemp->setChecked(checkingTemperature);
|
||||
@ -43,10 +44,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
else echo = false;
|
||||
|
||||
autolock = settings.value("core/lockcontrols").toBool();
|
||||
sendingChecksum = settings.value("core/checksums").toBool();
|
||||
|
||||
sending = false;
|
||||
paused = false;
|
||||
injectingCommand = false;
|
||||
readingFiles = false;
|
||||
sdprinting = false;
|
||||
sdBytes = 0;
|
||||
@ -56,11 +57,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
temperatureRegxp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
temperatureRegxp.setPatternSyntax(QRegExp::RegExp);
|
||||
temperatureRegxp.setPattern("\\d+\\.\\d+");
|
||||
temperatureRegxp.setPattern("\\d+\\.\\d+"); // Find float in string
|
||||
|
||||
SDStatusRegxp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
SDStatusRegxp.setPatternSyntax(QRegExp::RegExp);
|
||||
SDStatusRegxp.setPattern("\\d+");
|
||||
SDStatusRegxp.setPattern("\\d+"); //First number
|
||||
|
||||
serialupdate();
|
||||
|
||||
@ -94,11 +95,12 @@ MainWindow::~MainWindow()
|
||||
if(gfile.isOpen()) gfile.close();
|
||||
if(printer.isOpen()) printer.close();
|
||||
|
||||
if(firstrun) settings.setValue("core/firstrun", true); //firstrun is inverted!
|
||||
|
||||
settings.setValue("printer/baudrateindex", ui->baudbox->currentIndex());
|
||||
settings.setValue("core/checktemperature", ui->checktemp->isChecked());
|
||||
settings.setValue("user/extrudertemp", ui->etmpspin->value());
|
||||
settings.setValue("user/bedtemp", ui->btmpspin->value());
|
||||
if(firstrun) settings.setValue("core/firstrun", true);
|
||||
|
||||
settings.beginWriteArray("user/recentfiles");
|
||||
for(int i = 0; i < recentFiles.size(); i++)
|
||||
@ -136,11 +138,21 @@ void MainWindow::parseFile(QFile &file)
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QTextStream in(&file);
|
||||
int n = 0;
|
||||
while (!in.atEnd())
|
||||
{
|
||||
QString line = in.readLine();
|
||||
if(!line.startsWith(";"))
|
||||
{
|
||||
if(sendingChecksum)
|
||||
{
|
||||
line = "N"+QString::number(n)+line+"*";
|
||||
int cs = 0;
|
||||
for(int i = 0; line.at(i) != '*'; i++) cs = cs ^ line.at(i).toLatin1();
|
||||
cs &= 0xff;
|
||||
line += QString::number(cs);
|
||||
n++;
|
||||
}
|
||||
gcode.append(line);
|
||||
}
|
||||
|
||||
@ -174,13 +186,13 @@ void MainWindow::serialupdate()
|
||||
ui->serialBox->clear();
|
||||
QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
{
|
||||
ui->serialBox->addItem(list.at(i).portName());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::serialconnect()
|
||||
{
|
||||
userCommands.clear();
|
||||
|
||||
if(!printer.isOpen())
|
||||
{
|
||||
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
|
||||
@ -224,7 +236,7 @@ void MainWindow::serialconnect()
|
||||
ui->consoleGroup->setDisabled(false);
|
||||
ui->actionPrint_from_SD->setEnabled("true");
|
||||
ui->actionSet_SD_printing_mode->setEnabled("true");
|
||||
if(checkingTemperature) injectCommand("M105");
|
||||
//if(checkingTemperature) injectCommand("M105");
|
||||
}
|
||||
}
|
||||
|
||||
@ -415,6 +427,7 @@ void MainWindow::on_flowbutton_clicked()
|
||||
void MainWindow::on_haltbtn_clicked()
|
||||
{
|
||||
if(sending && !paused)ui->pauseBtn->click();
|
||||
userCommands.clear();
|
||||
injectCommand("M112");
|
||||
}
|
||||
//Buttons end
|
||||
@ -445,10 +458,21 @@ void MainWindow::readSerial()
|
||||
else if(data.startsWith("wait")) readyRecieve = 1;
|
||||
else if(data.startsWith("Resend")) //Handle resend if requested
|
||||
{
|
||||
if(currentLine > 0) currentLine -= data.split(':')[1].toInt();
|
||||
if(currentLine < 0) currentLine = 0;
|
||||
if(gcode.isEmpty())
|
||||
{
|
||||
injectCommand("M110"); //This means we rebooted, file is gone, so we need to reset counter
|
||||
return;
|
||||
}
|
||||
int err = data.split(':')[1].toInt();
|
||||
if(!sendingChecksum)
|
||||
{
|
||||
if(currentLine > 0) currentLine -= err;
|
||||
if(currentLine < 0) currentLine = 0;
|
||||
}
|
||||
else injectCommand(gcode.at(err));
|
||||
}
|
||||
else if(data.startsWith("Done")) sdprinting = false;
|
||||
else if(data.startsWith("start") && checkingTemperature) injectCommand("M105");
|
||||
else if(data.startsWith("SD printing byte") && sdWatcher.isFinished())
|
||||
{
|
||||
QFuture<double> parseSDThread = QtConcurrent::run(this, &MainWindow::parseSDStatus, data);
|
||||
@ -488,6 +512,7 @@ void MainWindow::printMsg(QString text)
|
||||
|
||||
void MainWindow::on_sendBtn_clicked()
|
||||
{
|
||||
userCommands.clear();
|
||||
if(sending && !sdprinting)
|
||||
{
|
||||
sending = false;
|
||||
@ -522,11 +547,10 @@ void MainWindow::on_sendBtn_clicked()
|
||||
|
||||
void MainWindow::sendNext()
|
||||
{
|
||||
if(injectingCommand && printer.isWritable() && readyRecieve > 0)
|
||||
if(!userCommands.isEmpty() && printer.isWritable() && readyRecieve > 0)
|
||||
{
|
||||
sendLine(userCommand);
|
||||
sendLine(userCommands.dequeue());
|
||||
readyRecieve--;
|
||||
injectingCommand=false;
|
||||
return;
|
||||
}
|
||||
else if(sending && !paused && readyRecieve > 0 && !sdprinting && printer.isWritable())
|
||||
@ -609,8 +633,7 @@ void MainWindow::on_actionAbout_triggered()
|
||||
|
||||
void MainWindow::injectCommand(QString command)
|
||||
{
|
||||
injectingCommand = true;
|
||||
userCommand = command;
|
||||
userCommands.enqueue(command);
|
||||
}
|
||||
|
||||
void MainWindow::updateRecent()
|
||||
@ -627,6 +650,8 @@ void MainWindow::serialError(QSerialPort::SerialPortError error)
|
||||
|
||||
if(sending) paused = true;
|
||||
|
||||
userCommands.clear();
|
||||
|
||||
ui->connectBtn->setText("Connect");
|
||||
ui->sendBtn->setDisabled(true);
|
||||
ui->pauseBtn->setDisabled(true);
|
||||
@ -700,13 +725,9 @@ TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
||||
TemperatureReadings r;
|
||||
|
||||
if(temperatureRegxp.indexIn(QString(data)) != -1)
|
||||
{
|
||||
r.e = temperatureRegxp.cap(0).toDouble();
|
||||
}
|
||||
if(temperatureRegxp.indexIn(QString(data), temperatureRegxp.matchedLength()) != -1)
|
||||
{
|
||||
r.b = temperatureRegxp.cap(0).toDouble();
|
||||
}
|
||||
else
|
||||
{
|
||||
r.e = -1;
|
||||
@ -755,7 +776,8 @@ double MainWindow::parseSDStatus(QByteArray data)
|
||||
}
|
||||
*/
|
||||
|
||||
if(SDStatusRegxp.indexIn(QString(data)) != 0) return SDStatusRegxp.cap(0).toDouble();
|
||||
if(SDStatusRegxp.indexIn(QString(data)) != 0)
|
||||
return SDStatusRegxp.cap(0).toDouble();
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ public:
|
||||
|
||||
QFile gfile;
|
||||
QVector<QString> gcode;
|
||||
QQueue <QString> userCommands;
|
||||
QTimer sendTimer;
|
||||
QTimer progressSDTimer;
|
||||
QTimer statusTimer;
|
||||
@ -63,11 +64,11 @@ private:
|
||||
bool sending;
|
||||
bool paused;
|
||||
bool checkingTemperature;
|
||||
bool injectingCommand;
|
||||
bool readingFiles;
|
||||
bool sdprinting;
|
||||
bool echo;
|
||||
int currentLine;
|
||||
bool sendingChecksum;
|
||||
long int currentLine;
|
||||
int readyRecieve;
|
||||
double sdBytes;
|
||||
QString userCommand;
|
||||
|
||||
@ -7,10 +7,12 @@ SettingsWindow::SettingsWindow(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if(!settings.value("core/firstrun").toBool()) ui->senderbox->setValue(4);
|
||||
bool firstrun = !settings.value("core/firstrun").toBool(); //firstrun is inverted!
|
||||
|
||||
if(firstrun) ui->senderbox->setValue(4);
|
||||
else ui->senderbox->setValue(settings.value("core/senderinterval").toFloat());
|
||||
|
||||
if(!settings.value("core/firstrun").toBool()) ui->echobox->setChecked(false);
|
||||
if(firstrun) ui->echobox->setChecked(false);
|
||||
else ui->echobox->setChecked(settings.value("core/echo").toBool());
|
||||
|
||||
if(settings.value("core/statusinterval").toInt()) ui->statusbox->setValue(settings.value("core/statusinterval").toInt());
|
||||
@ -23,6 +25,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) :
|
||||
else ui->bedybox->setValue(200);
|
||||
|
||||
ui->lockbox->setChecked(settings.value("core/lockcontrols").toBool());
|
||||
ui->checksumbox->setChecked(settings.value("core/checksums").toBool());
|
||||
|
||||
}
|
||||
|
||||
@ -39,4 +42,5 @@ void SettingsWindow::on_buttonBox_accepted()
|
||||
settings.setValue("printer/bedx", ui->bedxbox->value());
|
||||
settings.setValue("core/echo", ui->echobox->isChecked());
|
||||
settings.setValue("core/lockcontrols", ui->lockbox->isChecked());
|
||||
settings.setValue("core/checksums", ui->checksumbox->isChecked());
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>253</width>
|
||||
<height>242</height>
|
||||
<height>330</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -24,14 +24,17 @@
|
||||
<string>Internal</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="echobox">
|
||||
<property name="toolTip">
|
||||
<string>Show every sent command in console</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sender</string>
|
||||
<string>Echo commands</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="senderbox">
|
||||
<property name="toolTip">
|
||||
<string>A good default is 2, lower = fater, higher = less CPU load. 0 would execute as soon as possible.</string>
|
||||
@ -51,23 +54,26 @@
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>2.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="statusbox">
|
||||
<property name="toolTip">
|
||||
<string>A good default is 5000. More = less interruptions, less = better temperature monitoring</string>
|
||||
@ -84,19 +90,55 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>ms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="echobox">
|
||||
<property name="toolTip">
|
||||
<string>Show every sent command in console</string>
|
||||
<item row="4" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="lockbox">
|
||||
<property name="text">
|
||||
<string>Lock controls when printing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Sender</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="checksumbox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Echo commands</string>
|
||||
<string>Checksums</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>This settings are applied after restart</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -105,14 +147,20 @@
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Printer</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
<string>Bed size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -126,10 +174,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Bed size</string>
|
||||
<string>X</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user