Skip to content

Commit 6746768

Browse files
committed
Just tested it, does work. Kinda.
1 parent d176eca commit 6746768

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

mainwindow.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent) :
1111
connect(ui->pushButton_serialConnect, SIGNAL(clicked()), this, SLOT(handle_serialConnectBtn()));
1212
connect(ui->pushButton_fileSelect, SIGNAL(clicked()), this, SLOT(handle_selectFileBtn()));
1313
connect(ui->pushButton_fileLoad, SIGNAL(clicked()), this, SLOT(do_loadFile()));
14+
connect(ui->pushButton_doPlot, SIGNAL(clicked()), this, SLOT(do_plot()));
1415

1516
// Initialize interface
1617
ui->comboBox_baud->insertItems(0, QStringList() << "2400" << "4800" << "9600" << "19200" << "38400" << "57600" << "115200");
@@ -242,13 +243,16 @@ void MainWindow::do_loadFile()
242243
{
243244
QString buffer = "";
244245
char tmp = 0;
245-
while (tmp != ';')
246+
while (tmp != ';' && !inputFile.atEnd())
246247
{
247248
inputFile.read(&tmp, 1);
248249
buffer += tmp;
249250
}
250-
cmdList.append(buffer);
251-
ui->textBrowser_read->append(buffer);
251+
if (buffer.endsWith(";"))
252+
{
253+
cmdList.append(buffer);
254+
ui->textBrowser_read->append(buffer);
255+
}
252256
}
253257

254258
plotScene.clear();
@@ -259,13 +263,15 @@ void MainWindow::do_loadFile()
259263
if (cmdList.at(i)[0] == 'P' && cmdList.at(i)[1] == 'D')
260264
{
261265
ui->textBrowser_console->append("Found PD: " + cmdList.at(i));
262-
int charIndex = 2;
266+
int charIndex = 1;
263267
int nextX, nextY;
264268
while (cmdList.at(i)[charIndex] != ';')
265269
{
270+
charIndex++;
266271
nextX = get_nextInt(cmdList.at(i), &charIndex);
267272
charIndex++;
268273
nextY = get_nextInt(cmdList.at(i), &charIndex);
274+
269275
plotScene.addLine(curX, -curY, nextX, -nextY);
270276
ui->textBrowser_console->append(timeStamp() + "Adding line [" +
271277
QString::number(curX) + "," + QString::number(curY) +
@@ -278,9 +284,10 @@ void MainWindow::do_loadFile()
278284
else if (cmdList.at(i)[0] == 'P' && cmdList.at(i)[1] == 'U')
279285
{
280286
ui->textBrowser_console->append("Found PU: " + cmdList.at(i));
281-
int charIndex = 2;
287+
int charIndex = 1;
282288
while (cmdList.at(i)[charIndex] != ';')
283289
{
290+
charIndex++;
284291
curX = get_nextInt(cmdList.at(i), &charIndex);
285292
charIndex++;
286293
curY = get_nextInt(cmdList.at(i), &charIndex);
@@ -294,7 +301,16 @@ void MainWindow::do_loadFile()
294301

295302
void MainWindow::do_plot()
296303
{
297-
//serialBuffer->write();
304+
if (!serialBuffer->isOpen() || cmdList.isEmpty())
305+
{
306+
ui->textBrowser_console->append(timeStamp() + "Can't plot!");
307+
return;
308+
}
309+
for (int i = 0; i < cmdList.count(); i++)
310+
{
311+
int size = cmdList.at(i).length();
312+
serialBuffer->write(cmdList.at(i).toStdString().c_str(), size);
313+
}
298314
}
299315

300316

mainwindow.ui

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<item>
1919
<widget class="QTabWidget" name="tabWidget">
2020
<property name="currentIndex">
21-
<number>1</number>
21+
<number>0</number>
2222
</property>
2323
<widget class="QWidget" name="tab_settings">
2424
<attribute name="title">
@@ -151,7 +151,7 @@
151151
<item>
152152
<widget class="QPushButton" name="pushButton_doPlot">
153153
<property name="enabled">
154-
<bool>false</bool>
154+
<bool>true</bool>
155155
</property>
156156
<property name="text">
157157
<string>Plot!</string>
@@ -224,12 +224,6 @@
224224
</layout>
225225
</item>
226226
</layout>
227-
<zorder>lineEdit_filePath</zorder>
228-
<zorder>pushButton_fileLoad</zorder>
229-
<zorder>groupBox_serial</zorder>
230-
<zorder>groupBox_serial</zorder>
231-
<zorder>groupBox_serial</zorder>
232-
<zorder>label_5</zorder>
233227
</widget>
234228
</item>
235229
<item>

0 commit comments

Comments
 (0)