-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.cpp
602 lines (527 loc) · 34.1 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/***************************************************************************
** This file is part of Serial Port Plotter **
** **
** **
** Serial Port Plotter is a program for plotting integer data from **
** serial port using Qt and QCustomPlot **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author: Borislav **
** Contact: [email protected] **
** Date: 29.12.14 **
****************************************************************************/
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
/******************************************************************************************************************/
/* Constructor */
/******************************************************************************************************************/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
connected(false), plotting(false), dataPointNumber(0), numberOfAxes(1), STATE(WAIT_START), NUMBER_OF_POINTS(500)
{
ui->setupUi(this);
createUI(); // Create the UI
ui->plot->setBackground(QBrush(QColor(48,47,47))); // Background for the plot area
setupPlot(); // Setup plot area
ui->stopPlotButton->setEnabled(false); // Plot button is disabled initially
ui->plot->setNotAntialiasedElements(QCP::aeAll); // used for higher performance (see QCustomPlot real time example)
QFont font;
font.setStyleStrategy(QFont::NoAntialias);
ui->plot->xAxis->setTickLabelFont(font);
ui->plot->yAxis->setTickLabelFont(font);
ui->plot->legend->setFont(font);
ui->plot->yAxis->setAutoTickStep(false); // User can change tick step with a spin box
ui->plot->yAxis->setTickStep(ui->spinYStep->value()); // Set initial tick step
ui->plot->xAxis->setTickLabelColor(QColor(170,170,170)); // Tick labels color
ui->plot->yAxis->setTickLabelColor(QColor(170,170,170)); // See QCustomPlot examples / styled demo
ui->plot->xAxis->grid()->setPen(QPen(QColor(170,170,170), 1, Qt::DotLine));
ui->plot->yAxis->grid()->setPen(QPen(QColor(170,170,170), 1, Qt::DotLine));
ui->plot->xAxis->grid()->setSubGridPen(QPen(QColor(80,80,80), 1, Qt::DotLine));
ui->plot->yAxis->grid()->setSubGridPen(QPen(QColor(80,80,80), 1, Qt::DotLine));
ui->plot->xAxis->grid()->setSubGridVisible(true);
ui->plot->yAxis->grid()->setSubGridVisible(true);
ui->plot->xAxis->setBasePen(QPen(QColor(170,170,170)));
ui->plot->yAxis->setBasePen(QPen(QColor(170,170,170)));
ui->plot->xAxis->setTickPen(QPen(QColor(170,170,170)));
ui->plot->yAxis->setTickPen(QPen(QColor(170,170,170)));
ui->plot->xAxis->setSubTickPen(QPen(QColor(170,170,170)));
ui->plot->yAxis->setSubTickPen(QPen(QColor(170,170,170)));
ui->plot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
ui->plot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
ui->plot->setInteraction(QCP::iRangeDrag, true);
ui->plot->setInteraction(QCP::iRangeZoom, true);
// Slot for printing coordinates
connect(ui->plot, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(onMouseMoveInPlot(QMouseEvent*)));
serialPort = NULL; // Set serial port pointer to NULL initially
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(replot())); // Connect update timer to replot slot
updateTimer.start(50);
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Destructor */
/******************************************************************************************************************/
MainWindow::~MainWindow()
{
if(serialPort != NULL) delete serialPort;
delete ui;
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/**Create the GUI */
/******************************************************************************************************************/
void MainWindow::createUI()
{
if(QSerialPortInfo::availablePorts().size() == 0) { // Check if there are any ports at all; if not, disable controls and return
enableControls(false);
ui->connectButton->setEnabled(false);
ui->statusBar->showMessage("No ports detected.");
ui->saveJPGButton->setEnabled(false);
return;
}
for(QSerialPortInfo port : QSerialPortInfo::availablePorts()) { // List all available serial ports and populate ports combo box
ui->comboPort->addItem(port.portName());
}
ui->comboBaud->addItem("1200"); // Populate baud rate combo box
ui->comboBaud->addItem("2400");
ui->comboBaud->addItem("4800");
ui->comboBaud->addItem("9600");
ui->comboBaud->addItem("19200");
ui->comboBaud->addItem("38400");
ui->comboBaud->addItem("57600");
ui->comboBaud->addItem("115200");
ui->comboBaud->setCurrentIndex(7); // Select 9600 bits by default
ui->comboData->addItem("8 bits"); // Populate data bits combo box
ui->comboData->addItem("7 bits");
ui->comboParity->addItem("none"); // Populate parity combo box
ui->comboParity->addItem("odd");
ui->comboParity->addItem("even");
ui->comboStop->addItem("1 bit"); // Populate stop bits combo box
ui->comboStop->addItem("2 bits");
ui->comboAxes->addItem("1"); // Populate axes combo box; 3 axes maximum allowed
ui->comboAxes->addItem("2");
ui->comboAxes->addItem("3");
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Enable/disable controls */
/******************************************************************************************************************/
void MainWindow::enableControls(bool enable)
{
ui->comboBaud->setEnabled(enable); // Disable controls in the GUI
ui->comboData->setEnabled(enable);
ui->comboParity->setEnabled(enable);
ui->comboPort->setEnabled(enable);
ui->comboStop->setEnabled(enable);
ui->comboAxes->setEnabled(enable);
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Setup the plot area */
/******************************************************************************************************************/
void MainWindow::setupPlot()
{
ui->plot->clearItems(); // Remove everything from the plot
numberOfAxes = ui->comboAxes->currentText().toInt(); // Get number of axes from the user combo
ui->plot->yAxis->setRange(ui->spinAxesMin->value(), ui->spinAxesMax->value()); // Set lower and upper plot range
ui->plot->yAxis->setTickStep(ui->spinYStep->value()); // Set tick step according to user spin box
ui->plot->xAxis->setRange(0, NUMBER_OF_POINTS); // Set x axis range for specified number of points
if(numberOfAxes == 1) { // If 1 axis selected
ui->plot->addGraph(); // add Graph 0
ui->plot->graph(0)->setPen(QPen(Qt::red));
} else if(numberOfAxes == 2) { // If 2 axes selected
ui->plot->addGraph(); // add Graph 0
ui->plot->graph(0)->setPen(QPen(Qt::red));
ui->plot->addGraph(); // add Graph 1
ui->plot->graph(1)->setPen(QPen(Qt::yellow));
} else if(numberOfAxes == 3) { // If 3 axis selected
ui->plot->addGraph(); // add Graph 0
ui->plot->graph(0)->setPen(QPen(Qt::red));
ui->plot->addGraph(); // add Graph 1
ui->plot->graph(1)->setPen(QPen(Qt::yellow));
ui->plot->addGraph(); // add Graph 2
ui->plot->graph(2)->setPen(QPen(Qt::green));
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Open the inside serial port; connect its signals */
/******************************************************************************************************************/
void MainWindow::openPort(QSerialPortInfo portInfo, int baudRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits)
{
serialPort = new QSerialPort(portInfo, 0); // Create a new serial port
connect(this, SIGNAL(portOpenOK()), this, SLOT(portOpenedSuccess())); // Connect port signals to GUI slots
connect(this, SIGNAL(portOpenFail()), this, SLOT(portOpenedFail()));
connect(this, SIGNAL(portClosed()), this, SLOT(onPortClosed()));
connect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
connect(serialPort, SIGNAL(readyRead()), this, SLOT(readData()));
if(serialPort->open(QIODevice::ReadWrite) ) {
serialPort->setBaudRate(baudRate);
serialPort->setParity(parity);
serialPort->setDataBits(dataBits);
serialPort->setStopBits(stopBits);
emit portOpenOK();
} else {
emit portOpenedFail();
qDebug() << serialPort->errorString();
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Port Combo Box index changed slot; displays info for selected port when combo box is changed */
/******************************************************************************************************************/
void MainWindow::on_comboPort_currentIndexChanged(const QString &arg1)
{
QSerialPortInfo selectedPort(arg1); // Dislplay info for selected port
ui->statusBar->showMessage(selectedPort.description());
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Connect Button clicked slot; handles connect and disconnect */
/******************************************************************************************************************/
void MainWindow::on_connectButton_clicked()
{
if(!ui->checkBox->isChecked()){
if(connected) { // If application is connected, disconnect
serialPort->close(); // Close serial port
emit portClosed(); // Notify application
delete serialPort; // Delete the pointer
serialPort = NULL; // Assign NULL to dangling pointer
ui->connectButton->setText("Connect"); // Change Connect button text, to indicate disconnected
ui->statusBar->showMessage("Disconnected!"); // Show message in status bar
connected = false; // Set connected status flag to false
plotting = false; // Not plotting anymore
receivedData.clear(); // Clear received string
ui->stopPlotButton->setEnabled(false); // Take care of controls
ui->saveJPGButton->setEnabled(false);
enableControls(true);
} else { // If application is not connected, connect
// Get parameters from controls first
QSerialPortInfo portInfo(ui->comboPort->currentText()); // Temporary object, needed to create QSerialPort
int baudRate = ui->comboBaud->currentText().toInt(); // Get baud rate from combo box
int dataBitsIndex = ui->comboData->currentIndex(); // Get index of data bits combo box
int parityIndex = ui->comboParity->currentIndex(); // Get index of parity combo box
int stopBitsIndex = ui->comboStop->currentIndex(); // Get index of stop bits combo box
QSerialPort::DataBits dataBits;
QSerialPort::Parity parity;
QSerialPort::StopBits stopBits;
if(dataBitsIndex == 0) { // Set data bits according to the selected index
dataBits = QSerialPort::Data8;
} else {
dataBits = QSerialPort::Data7;
}
if(parityIndex == 0) { // Set parity according to the selected index
parity = QSerialPort::NoParity;
} else if(parityIndex == 1) {
parity = QSerialPort::OddParity;
} else {
parity = QSerialPort::EvenParity;
}
if(stopBitsIndex == 0) { // Set stop bits according to the selected index
stopBits = QSerialPort::OneStop;
} else {
stopBits = QSerialPort::TwoStop;
}
serialPort = new QSerialPort(portInfo, 0); // Use local instance of QSerialPort; does not crash
openPort(portInfo, baudRate, dataBits, parity, stopBits); // Open serial port and connect its signals
}
} else {
if(connected){
simulate.stop();
connected=false;
ui->connectButton->setText("Connect"); // Change Connect button text, to indicate disconnected
ui->statusBar->showMessage("Disconnected!"); // Show message in status bar
disconnect(&simulate, SIGNAL(timeout()), this, SLOT(simulatedData()));
disconnect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
plotting = false;
updateTimer.stop();
} else {
simulate.setInterval(20);
simulate.setSingleShot(false);
connect(&simulate, SIGNAL(timeout()), this, SLOT(simulatedData()));
connect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
simulate.start();
connected=true;
plotting = true;
updateTimer.start(50);
ui->connectButton->setText("DisConnect"); // Change Connect button text, to indicate disconnected
ui->statusBar->showMessage("Connected!"); // Show message in status bar
}
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for port opened successfully */
/******************************************************************************************************************/
void MainWindow::portOpenedSuccess()
{
//qDebug() << "Port opened signal received!";
ui->connectButton->setText("Disconnect"); // Change buttons
ui->statusBar->showMessage("Connected!");
enableControls(false); // Disable controls if port is open
ui->stopPlotButton->setText("Stop Plot"); // Enable button for stopping plot
ui->stopPlotButton->setEnabled(true);
ui->saveJPGButton->setEnabled(true); // Enable button for saving plot
setupPlot(); // Create the QCustomPlot area
updateTimer.start(50); // Slot is refreshed 20 times per second
connected = true; // Set flags
plotting = true;
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for fail to open the port */
/******************************************************************************************************************/
void MainWindow::portOpenedFail()
{
//qDebug() << "Port cannot be open signal received!";
ui->statusBar->showMessage("Cannot open port!");
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for closing the port */
/******************************************************************************************************************/
void MainWindow::onPortClosed()
{
//qDebug() << "Port closed signal received!";
updateTimer.stop();
connected = false;
disconnect(serialPort, SIGNAL(readyRead()), this, SLOT(readData()));
disconnect(this, SIGNAL(portOpenOK()), this, SLOT(portOpenedSuccess())); // Disconnect port signals to GUI slots
disconnect(this, SIGNAL(portOpenFail()), this, SLOT(portOpenedFail()));
disconnect(this, SIGNAL(portClosed()), this, SLOT(onPortClosed()));
disconnect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
}
/******************************************************************************************************************/
/* Replot */
/******************************************************************************************************************/
void MainWindow::replot()
{
if(connected) {
ui->plot->xAxis->setRange(dataPointNumber - NUMBER_OF_POINTS, dataPointNumber);
ui->plot->replot();
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Stop Plot Button */
/******************************************************************************************************************/
void MainWindow::on_stopPlotButton_clicked()
{
if(plotting) { // Stop plotting
updateTimer.stop(); // Stop updating plot timer
plotting = false;
ui->stopPlotButton->setText("Start Plot");
} else { // Start plotting
updateTimer.start(); // Start updating plot timer
plotting = true;
ui->stopPlotButton->setText("Stop Plot");
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for new data from serial port . Data is comming in QStringList and needs to be parsed */
/******************************************************************************************************************/
void MainWindow::onNewDataArrived(QStringList newData)
{
if(plotting) {
int dataListSize = newData.size(); // Get size of received list
dataPointNumber++; // Increment data number
if(numberOfAxes == 1 && dataListSize > 0) { // Add data to graphs according to number of axes
ui->plot->graph(0)->addData(dataPointNumber, newData[0].toInt()); // Add data to Graph 0
ui->plot->graph(0)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS); // Remove data from graph 0
} else if(numberOfAxes == 2) {
ui->plot->graph(0)->addData(dataPointNumber, newData[0].toInt());
ui->plot->graph(0)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS);
if(dataListSize > 1){
ui->plot->graph(1)->addData(dataPointNumber, newData[1].toInt());
ui->plot->graph(1)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS);
}
} else if(numberOfAxes == 3) {
ui->plot->graph(0)->addData(dataPointNumber,newData[0].toInt());
ui->plot->graph(0)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS);
if(dataListSize > 1) {
ui->plot->graph(1)->addData(dataPointNumber, newData[1].toInt());
ui->plot->graph(1)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS);
}
if(dataListSize > 2) {
ui->plot->graph(2)->addData(dataPointNumber, newData[2].toInt());
ui->plot->graph(2)->removeDataBefore(dataPointNumber - NUMBER_OF_POINTS);
}
} else return;
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for spin box for plot minimum value on y axis */
/******************************************************************************************************************/
void MainWindow::on_spinAxesMin_valueChanged(int arg1)
{
ui->plot->yAxis->setRangeLower(arg1);
ui->plot->replot();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for spin box for plot maximum value on y axis */
/******************************************************************************************************************/
void MainWindow::on_spinAxesMax_valueChanged(int arg1)
{
ui->plot->yAxis->setRangeUpper(arg1);
ui->plot->replot();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Read data for inside serial port */
/******************************************************************************************************************/
void MainWindow::readData()
{
if(serialPort->bytesAvailable()) { // If any bytes are available
QByteArray data = serialPort->readAll(); // Read all data in QByteArray
if(!data.isEmpty()) { // If the byte array is not empty
char *temp = data.data(); // Get a '\0'-terminated char* to the data
for(int i = 0; temp[i] != '\0'; i++) { // Iterate over the char*
switch(STATE) { // Switch the current state of the message
case WAIT_START: // If waiting for start [$], examine each char
if(temp[i] == START_MSG) { // If the char is $, change STATE to IN_MESSAGE
STATE = IN_MESSAGE;
receivedData.clear(); // Clear temporary QString that holds the message
break; // Break out of the switch
}
break;
case IN_MESSAGE: // If state is IN_MESSAGE
if(temp[i] == END_MSG) { // If char examined is ;, switch state to END_MSG
STATE = WAIT_START;
QStringList incomingData = receivedData.split(' '); // Split string received from port and put it into list
emit newData(incomingData); // Emit signal for data received with the list
break;
}
else if(isdigit(temp[i]) || isspace(temp[i]) ) { // If examined char is a digit, and not '$' or ';', append it to temporary string
receivedData.append(temp[i]);
}
else if( temp[i]=='-' || temp[i]=='+' ) { // If examined char is a digit, and not '$' or ';', append it to temporary string
receivedData.append(temp[i]);
}
break;
default: break;
}
}
}
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Number of axes combo; when changed, display axes colors in status bar */
/******************************************************************************************************************/
void MainWindow::on_comboAxes_currentIndexChanged(int index)
{
if(index == 0) {
ui->statusBar->showMessage("Axis 1: Red");
} else if(index == 1) {
ui->statusBar->showMessage("Axis 1: Red; Axis 2: Yellow");
} else {
ui->statusBar->showMessage("Axis 1: Red; Axis 2: Yellow; Axis 3: Green");
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Spin box for changing the Y Tick step */
/******************************************************************************************************************/
void MainWindow::on_spinYStep_valueChanged(int arg1)
{
ui->plot->yAxis->setTickStep(arg1);
ui->plot->replot();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Save a JPG image of the plot to current EXE directory */
/******************************************************************************************************************/
void MainWindow::on_saveJPGButton_clicked()
{
ui->plot->saveJpg(QString::number(dataPointNumber) + ".jpg");
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Reset the zoom of the plot to the initial values */
/******************************************************************************************************************/
void MainWindow::on_resetPlotButton_clicked()
{
ui->plot->yAxis->setRange(0, 4095);
ui->plot->xAxis->setRange(dataPointNumber - NUMBER_OF_POINTS, dataPointNumber);
ui->plot->yAxis->setTickStep(ui->spinYStep->value());
ui->plot->replot();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Prints coordinates of mouse pointer in status bar on mouse release */
/******************************************************************************************************************/
void MainWindow::onMouseMoveInPlot(QMouseEvent *event)
{
int xx = ui->plot->xAxis->pixelToCoord(event->x());
int yy = ui->plot->yAxis->pixelToCoord(event->y());
QString coordinates("X: %1 Y: %2");
coordinates = coordinates.arg(xx).arg(yy);
ui->statusBar->showMessage(coordinates);
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Spin box controls how many data points are collected and displayed */
/******************************************************************************************************************/
void MainWindow::on_spinPoints_valueChanged(int arg1)
{
NUMBER_OF_POINTS = arg1;
ui->plot->replot();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Shows a window with instructions */
/******************************************************************************************************************/
void MainWindow::on_actionHow_to_use_triggered()
{
helpWindow = new HelpWindow(this);
helpWindow->setWindowTitle("How to use this application");
helpWindow->show();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Emulate data emission */
/******************************************************************************************************************/
void MainWindow::on_checkBox_clicked()
{
if(connected){
QMessageBox msgBox;
msgBox.setText("Please Disconnect first");
msgBox.exec();
} else {
if(!ui->checkBox->isChecked()){
ui->checkBox->setChecked(false);
} else {
ui->checkBox->setChecked(true);
}
}
}
/******************************************************************************************************************/
/* fake data emission */
/******************************************************************************************************************/
void MainWindow::simulatedData()
{
int i1 = rand();
int i2 = rand();
if (i1>RAND_MAX/2) receivedData="+"; else receivedData="-";
char buf[20];
sprintf(buf,"%d",i2);
receivedData.append(buf);
QStringList incomingData = receivedData.split(' ');
emit newData(incomingData);
}