Skip to content

Commit ff284a3

Browse files
committed
removing bugs
1 parent 4cf1b7a commit ff284a3

28 files changed

+7273
-244
lines changed

Spherebot_UI/Spherebot_UI.pro.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 3.4.2, 2016-02-27T11:04:57. -->
3+
<!-- Written by QtCreator 3.4.2, 2016-02-27T16:13:07. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -61,7 +61,7 @@
6161
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.5.0 MinGW 32bit</value>
6262
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.5.0 MinGW 32bit</value>
6363
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.55.win32_mingw492_kit</value>
64-
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
64+
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
6565
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
6666
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
6767
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">

Spherebot_UI/mainwindow.cpp

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void MainWindow::entry_connected()
6666
ui->portBox->setEnabled(false);
6767
ui->resetButton->setEnabled(false);
6868
ui->connectButton->setText("Disconnect");
69+
ui->sendButton->setEnabled(false);
6970
if(!ui->fileTextEdit->toPlainText().isEmpty()) ui->sendFileButton->setEnabled(true);
7071
statusBar()->showMessage(tr("Successfully connected to bot!"),4000);
7172
}
@@ -157,11 +158,13 @@ void MainWindow::entry_idle()
157158
qDebug()<< "entry_idle"<< endl;
158159
ui->fileSendProgressBar->setValue(0);
159160
ui->sendFileButton->setText("Send File");
161+
ui->saveFileButton->setText("Save File");
160162
ui->loadFileButton->setText("Load File");
161163

162164
ui->controllBox->setEnabled(true);
163165
ui->restartButton->setEnabled(false);
164166
ui->loadFileButton->setEnabled(true);
167+
ui->saveFileButton->setEnabled(false);
165168
ui->fileSendProgressBar->setEnabled(false);
166169

167170
bot->send("M 18"); //disable motors
@@ -183,14 +186,22 @@ void MainWindow::entry_ask_for_restart()
183186
qDebug()<< "entry_ask_for_restart"<< endl;
184187
statusBar()->showMessage(tr("File successfully sent"));
185188
SetBotToHomePosition();
186-
if(restartLayerMsgBox->exec() == QMessageBox::Ok) //workaround cause the signals don´t fire
187-
emit restartLayerMsgBox->accept();
189+
int result = restartLayerMsgBox->exec();
190+
if(result == QMessageBox::Ok)
191+
{
192+
emit restart_print();
193+
qDebug()<< "emit restart_print"<< endl;
194+
}
188195
else
189-
emit restartLayerMsgBox->reject();
196+
{
197+
emit abort_print();
198+
qDebug()<< "emit abort_print"<< endl;
199+
}
190200
}
191201

192202
void MainWindow::entry_ask_for_next_layer()
193203
{
204+
qDebug()<<"entry_ask_for_next_layer"<< endl;
194205
qDebug()<< "entry_ask_for_next_layer"<< endl;
195206
if(layerNames.size() > 1) layerIndex++;
196207

@@ -201,12 +212,23 @@ void MainWindow::entry_ask_for_next_layer()
201212
{
202213
nextLayerMsgBox->setText("Please change the tool for layer: " + layerNames[layerIndex]);
203214
SetBotToHomePosition();
204-
nextLayerMsgBox->exec();
215+
int result = nextLayerMsgBox->exec();
216+
if(result == QMessageBox::Ok)
217+
{
218+
emit print_next_layer();
219+
qDebug()<< "emit print_next_layer"<< endl;
220+
}
221+
else
222+
{
223+
emit abort_print();
224+
qDebug()<< "emit abort_print"<< endl;
225+
}
205226
}
206227
}
207228

208229
void MainWindow::entry_load_file_dialog()
209230
{
231+
qDebug()<<"entry_load_file_dialog"<< endl;
210232
QString fileName;
211233
if(!curDir.absolutePath().isEmpty())
212234
{
@@ -264,11 +286,20 @@ void MainWindow::initSateMachine()
264286
//
265287
start_sending->addTransition(start_sending,SIGNAL(entered()),sending);
266288

267-
ask_for_restart->addTransition(restartLayerMsgBox,SIGNAL(accepted()),restart);
268-
ask_for_restart->addTransition(restartLayerMsgBox,SIGNAL(rejected()),idle);
269-
connect(ask_for_restart,SIGNAL(exited()),this,SLOT(hey()));
289+
idle->addTransition(restartLayerMsgBox,SIGNAL(accepted()),restart);
290+
idle->addTransition(restartLayerMsgBox,SIGNAL(rejected()),idle);
291+
292+
idle->addTransition(this,SIGNAL(restart_print()),restart);
293+
ask_for_restart->addTransition(this,SIGNAL(restart_print()),restart);
294+
ask_for_restart->addTransition(this,SIGNAL(abort_restart_print()),abort);
295+
idle->addTransition(this,SIGNAL(abort_restart_print()),abort);
270296

271-
ask_for_next_layer->addTransition(nextLayerMsgBox,SIGNAL(accepted()),sending);
297+
idle->addTransition(this,SIGNAL(print_next_layer()),sending);
298+
ask_for_next_layer->addTransition(this,SIGNAL(print_next_layer()),sending);
299+
idle->addTransition(this,SIGNAL(abort_print()),abort);
300+
ask_for_next_layer->addTransition(this,SIGNAL(abort_print()),abort);
301+
//idle->addTransition(nextLayerMsgBox,SIGNAL(accepted()),sending);
302+
//idle->addTransition(nextLayerMsgBox,SIGNAL(rejected()),abort);
272303

273304
load_file_dialog->addTransition(load_file_dialog,SIGNAL(entered()),idle);
274305

@@ -308,14 +339,17 @@ void MainWindow::initUI()
308339
nextLayerMsgBox = new QMessageBox(QMessageBox::Information,
309340
"Next Layer",
310341
"The Layer has been finished!\nplease insert the tool for the layer: " + QString::number(layerIndex),
311-
QMessageBox::Ok|QMessageBox::No);
312-
nextLayerMsgBox->setButtonText(QMessageBox::Ok,"OK");
313-
nextLayerMsgBox->setButtonText(QMessageBox::No,"Abort");
342+
QMessageBox::Ok|QMessageBox::Abort);
343+
344+
//nextLayerMsgBox->addButton("OK",QMessageBox::AcceptRole);
345+
//nextLayerMsgBox->addButton("Abort",QMessageBox::RejectRole);
314346

315347
restartLayerMsgBox = new QMessageBox(QMessageBox::Information,
316348
"Restart?",
317349
"Do you want to restart the print?",
318-
QMessageBox::Ok|QMessageBox::No);
350+
QMessageBox::Ok|QMessageBox::Abort);
351+
//restartLayerMsgBox->addButton("OK",QMessageBox::RejectRole); //for some reason rejectrole and acceptrole need to be switched
352+
//restartLayerMsgBox->addButton("Abort",QMessageBox::AcceptRole);
319353

320354
connect(ui->undoButton,SIGNAL(clicked()),ui->fileTextEdit,SLOT(undo()));
321355
connect(ui->redoButton,SIGNAL(clicked()),ui->fileTextEdit,SLOT(redo()));
@@ -599,7 +633,7 @@ void MainWindow::on_sendString_editingFinished()
599633
}
600634
}
601635

602-
void MainWindow::on_sendButton_clicked()
636+
void MainWindow::on_sendButton_released()
603637
{
604638
on_sendString_editingFinished();
605639
ui->sendString->setText("");

Spherebot_UI/mainwindow.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public slots:
5252

5353
// void loadFileDialog();
5454
private slots:
55-
void hey(){qDebug()<<"hey"<<endl;}
55+
// void hey(){qDebug()<<"hey"<<endl;}
5656

5757
void resetPortList();
58-
void on_sendButton_clicked();
58+
void on_sendButton_released();
5959
void on_resetButton_clicked();
6060
void on_sendString_editingFinished();
6161
void on_servoSlider_sliderMoved(int position);
@@ -96,6 +96,12 @@ private slots:
9696
void successfully_connected();
9797
void not_successfully_connected();
9898

99+
void print_next_layer();
100+
void abort_print();
101+
102+
void restart_print();
103+
void abort_restart_print();
104+
99105
private:
100106

101107
void setCurrentFile(const QString &fileName);

Spherebot_UI/mainwindow.ui

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<rect>
5959
<x>8</x>
6060
<y>0</y>
61-
<width>541</width>
61+
<width>609</width>
6262
<height>191</height>
6363
</rect>
6464
</property>
@@ -422,13 +422,13 @@
422422
</item>
423423
</layout>
424424
</widget>
425-
<widget class="QWidget" name="">
425+
<widget class="QWidget" name="layoutWidget">
426426
<property name="geometry">
427427
<rect>
428428
<x>0</x>
429429
<y>200</y>
430430
<width>539</width>
431-
<height>31</height>
431+
<height>48</height>
432432
</rect>
433433
</property>
434434
<layout class="QHBoxLayout" name="horizontalLayout_3">
@@ -453,8 +453,8 @@
453453
<rect>
454454
<x>20</x>
455455
<y>20</y>
456-
<width>271</width>
457-
<height>30</height>
456+
<width>461</width>
457+
<height>48</height>
458458
</rect>
459459
</property>
460460
<layout class="QHBoxLayout" name="horizontalLayout">
@@ -474,7 +474,7 @@
474474
<item>
475475
<widget class="QPushButton" name="resetButton">
476476
<property name="text">
477-
<string>Reset</string>
477+
<string>Reset portlist</string>
478478
</property>
479479
</widget>
480480
</item>
@@ -558,7 +558,7 @@
558558
<rect>
559559
<x>570</x>
560560
<y>10</y>
561-
<width>461</width>
561+
<width>642</width>
562562
<height>491</height>
563563
</rect>
564564
</property>

Spherebot_UI/rxthread.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ void rxThread::receiveData()
1313
{
1414
if(bot->port->canReadLine())
1515
{
16-
line = bot->port->readLine(1024);
17-
//qDebug()<<"receiving raw: " << line << endl;/////////////////////////////
18-
while(line.endsWith('\n')) line.chop(1);
19-
qDebug()<<"receiving: " << line << endl;/////////////////////////////
20-
emit lineReceived(line);
16+
while(bot->port->canReadLine())
17+
{
18+
line = bot->port->readLine(1024);
19+
//qDebug()<<"receiving raw: " << line << endl;/////////////////////////////
20+
while(line.endsWith('\n')) line.chop(1);
21+
if( line != "")
22+
{
23+
qDebug()<<"receiving: " << line << endl;/////////////////////////////
24+
emit lineReceived(line);
25+
}
26+
}
2127
}
2228
}
2329

Spherebot_UI/spherebot.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool spherebot::disconnectWithBot()
5454
if(port->isOpen())
5555
port->close();
5656
bot_connected = false;
57-
timeout_timer->stop();
57+
this->resetState();
5858
return 1;
5959
}
6060

@@ -99,7 +99,8 @@ void spherebot::processAnswer(QString answer)
9999
}
100100
else
101101
{
102-
//qDebug() << "answer did not contain rs or ok" << endl;
102+
qDebug() << "answer did not contain rs or ok or Spherebot" << endl;
103+
qDebug() << "answer was:" << answer << endl;
103104
}
104105
}
105106

@@ -122,19 +123,21 @@ bool spherebot::send(QString cmd)
122123
{
123124
if(port->isOpen())
124125
{
125-
while( lastLine.endsWith('\n')) lastLine.chop(1);
126+
while( lastLine.endsWith('\n') || lastLine.endsWith('\r')) lastLine.chop(1);
126127

127128
cmd.append(" ");
128129
cmd.append(generateChecksumString(cmd));
129-
cmd.append("\n");
130+
cmd.append('\n');
130131

131132
if(bot_connected)
132133
{
133134
if(lastLineTransmitted)
134135
{
135136
qDebug()<<"Sending: " + cmd;
136-
port->write((const char*)cmd.toUtf8(),cmd.length());
137-
137+
int er = port->write((const char*)cmd.toUtf8(),cmd.length());
138+
if (er == -1)
139+
qDebug() << "an error occured while writing to the port!!" << endl;
140+
//qDebug() << "flush result: " << port->flush();
138141
lastLine = cmd;
139142
lastLineTransmitted = false;
140143
timeout_timer->start();
@@ -168,7 +171,7 @@ void spherebot::resendLine()
168171
else if( bot_connected)
169172
{
170173
port->write((const char*)lastLine.toUtf8(),lastLine.length());
171-
while( lastLine.endsWith('\n')) lastLine.chop(1);
174+
//while( lastLine.endsWith('\n')) lastLine.chop(1);
172175
qDebug()<<"Resending: " << lastLine << endl;
173176
}
174177
}
@@ -203,6 +206,11 @@ void spherebot::resetState()
203206
lineCounter = 0;
204207
ignoreFirstM01 = true;
205208
sendingFile = false;
209+
toSendBuffer.clear();
210+
lastLine = "";
211+
lineCounter = 0;
212+
retry_timer->stop();
213+
timeout_timer->stop();
206214
}
207215

208216
QString removeComments(QString intext)
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)