-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2482 lines (2369 loc) · 120 KB
/
mainwindow.cpp
File metadata and controls
2482 lines (2369 loc) · 120 KB
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
** This file is part of Yet Another Serial Plotter **
** **
** Serial Port Plotter is a program for plotting 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: Cricri042 **
** Contact: cricri042@devlabnet.eu **
** Date: 25/02/2019 **
****************************************************************************/
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <QSplitter>
#include <QtGui>
#include <QPen>
#include <QNetworkReply>
//static const QString DEFS_URL = "https://www.devlabnet.eu/softdev/yasp/updates.json";
//static const QString DEFS_URL = "https://raw.githubusercontent.com/devlabnet/YASP/master/installer/updates.json";
static const QString YASP_VERSION = "v1.3.0";
static const QString DEFS_URL = "https://api.github.com/repos/devlabnet/YASP/releases/latest";
static const QString DOC_URL = "https://gdoc.pub/doc/e/2PACX-1vQmyyZDie11-NvYd0V3Ry10cUGisbMw1lMT7EOq4qnecPBSdgyicpQix47Plv0QDT93KMiAFPEK7MNc";
/******************************************************************************************************************/
/* Constructor */
/******************************************************************************************************************/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
connected(false), plotting(false), dataPointNumber(0), numberOfAxes(1),
STATE(WAIT_START), plotTimeInMilliSeconds(PLOT_TIME_DEF) {
ui->setupUi(this);
QLocale::setDefault(QLocale::C);
createUI(); // Create the UI
// resize(minimumSize());
// ui->terminalWidget->setVisible(false);
// ----------------------------------------
// Hide dynamicFrame and autoScrollCheckBox
ui->dynamicFrame->setVisible(false);
ui->autoScrollCheckBox->setVisible(false);
ui->checkBoxDynamicMeasures->setVisible(false);
// ----------------------------------------
ui->dynamicFrame->setVisible(true);
ui->autoScrollCheckBox->setVisible(true);
QColor gridColor = QColor(170,170,170);
ui->bgColorButton->setAutoFillBackground(true);
ui->bgColorButton->setStyleSheet("background-color:" + bgColor.name() + "; color: rgb(0, 0, 0)");
QColor subGridColor = QColor(80,80,80);
ui->plot->setBackground(QBrush(bgColor)); // Background for the plot area
ui->plot->hide();
#ifdef YASP_PLOTS_WIDTH
ui->plot->setOpenGl(true);
#endif
ui->stopPlotButton->setEnabled(false); // Plot button is disabled initially
ui->logPlotButton->setVisible(false);
// Legend
ui->plot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
ui->plot->setNotAntialiasedElements(QCP::aeAll); // used for higher performance (see QCustomPlot real time example)
// Y Axes
ui->plot->yAxis->setTickLabelColor(gridColor); // See QCustomPlot examples / styled demo
ui->plot->yAxis->setSelectedParts(QCPAxis::spNone);
ui->plot->xAxis->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
ui->plot->xAxis->setSelectedParts(QCPAxis::spNone);
ui->plot->yAxis->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
ui->plot->xAxis->grid()->setSubGridPen(QPen(subGridColor, 1, Qt::DotLine));
ui->plot->yAxis->grid()->setSubGridPen(QPen(subGridColor, 1, Qt::DotLine));
ui->plot->xAxis->grid()->setSubGridVisible(true);
ui->plot->yAxis->grid()->setSubGridVisible(true);
ui->plot->yAxis->setBasePen(QPen(gridColor));
ui->plot->yAxis->setTickPen(QPen(gridColor));
ui->plot->yAxis->setSubTickPen(QPen(gridColor));
ui->plot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
// X Axes
ui->plot->xAxis->setBasePen(QPen(gridColor));
ui->plot->xAxis->setSubTickPen(QPen(gridColor));
ui->plot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
ui->plot->xAxis->setTickLabelColor(gridColor);
fixedTicker = QSharedPointer<QCPAxisTickerFixed>(new QCPAxisTickerFixed);
// plotTimeInMilliSeconds = 30;
ui->plot->xAxis->setTicker(fixedTicker);
// tick step shall be 0.001 second -> 1 milisecond
// tick step shall be 0.0001 second -> 0.1 milisecond -> 100 microdeconds
// tick step shall be 0.00001 second -> 0.01 milisecond -> 10 microdeconds
fixedTicker->setTickStep(0.00001);
fixedTicker->setTickCount(10);
fixedTicker->setTickStepStrategy(QCPAxisTicker::tssMeetTickCount);
fixedTicker->setScaleStrategy(QCPAxisTickerFixed::ssMultiples );
ui->plot->xAxis->setTickPen(QPen(Qt::red, 2));
ui->plot->xAxis->setTickLength(15);
// Slot for printing coordinates
connect(ui->plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(onMousePressInPlot(QMouseEvent*)));
connect(ui->plot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(onMouseMoveInPlot(QMouseEvent*)));
connect(ui->plot, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(onMouseReleaseInPlot(QMouseEvent*)));
connect(ui->plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(onMouseWheelInPlot(QWheelEvent*)));
connect(ui->plot->xAxis, SIGNAL(rangeChanged(const QCPRange&)), this, SLOT(xAxisRangeChanged(const QCPRange&)));
connect(ui->plot->yAxis, SIGNAL(rangeChanged(const QCPRange&)), this, SLOT(yAxisRangeChanged(const QCPRange&)));
// setup policy and connect slot for context menu popup:
ui->plot->setContextMenuPolicy(Qt::PreventContextMenu);
connect(ui->plot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(plotContextMenuRequest(QPoint)));
ui->plot->setInteraction(QCP::iSelectAxes, false);
ui->plot->setInteraction(QCP::iSelectPlottables, false);
ui->plot->setInteraction(QCP::iSelectOther, false);
connect(ui->checkBoxDynamicMeasures, SIGNAL(stateChanged(int)), this, SLOT(checkBoxDynamicMeasuresChanged(int)));
serialPort = nullptr;
// Connect update timer to replot slot
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(replot()));
ui->menuWidgets->menuAction()->setVisible(false);
updateTimer.setInterval(20);
QPalette p;
p.setColor(QPalette::Background, QColor(144, 238, 144));
ui->splitter->setPalette(p);
ui->splitter->setMinimumHeight(100);
// ui->splitter->setSizes({2, 1});
ui->splitter->setSizes(QList<int>({INT_MAX, INT_MAX}));
ui->tabWidget->setCurrentIndex(0);
ui->spinDisplayTime->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
ui->spinDisplayTime->setMinimum(PLOT_TIME_MIN_DEF);
ui->spinDisplayTime->setMaximum(PLOT_TIME_MAX_DEF);
ui->spinDisplayTime->setValue(PLOT_TIME_DEF);
ui->spinDisplayTime->setDecimals(0);
ui->spinDisplayTime->setSuffix(" Millis");
ui->spinDisplayTime->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
ui->spinDisplayRange->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
ui->spinDisplayRange->setMinimum(1);
ui->spinDisplayRange->setMaximum(YAXIS_MAX_RANGE);
ui->spinDisplayRange->setValue(DEF_YAXIS_RANGE);
ui->spinDisplayRange->setDecimals(0);
ui->spinDisplayRange->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
ui->autoScrollLabel->setStyleSheet("QLabel { color : DodgerBlue; }");
ui->autoScrollLabel->setText("Auto Scroll OFF, To allow move cursor to the end or SELECT Button ---> ");
ui->tabWidget->removeTab(1);
contextMenu = new QMenu(this);
// connect(contextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuTriggered(QAction*)));
// connect(contextMenu, SIGNAL(aboutToHide()), this, SLOT(menuAboutToHide()));
ui->plot->setContextMenuPolicy(Qt::PreventContextMenu);
mouseWheelTimer.stop();
ui->aboutNevVersionButton->setVisible(false);
checkForUpdate();
// loadHelpFile();
// green rgb(153, 255, 153)
// pink rgb(255, 179, 209)
// yellow rgb(255, 255, 102)
// blue rgb(102, 255, 255)
ui->buttonsFrame->setStyleSheet("QFrame{color:black; background-color:rgb(153, 255, 153);border-radius:10px;border:2px solid grey} QLabel{border:none;}");
ui->rangeFrame->setStyleSheet("QFrame{color:black; background-color:rgb(255, 179, 209);border-radius:10px;border:2px solid grey} QLabel{border:none;}");
ui->dynamicFrame->setStyleSheet("QFrame{color:black; background-color:rgb(255, 255, 102);border-radius:10px;border:2px solid grey} QLabel{border:none;}");
ui->pointsCountFrame->setStyleSheet("QFrame{color:black; background-color:rgb(102, 255, 255);border-radius:10px;border:2px solid grey} QLabel{border:none;}");
measureMode = measureType::None;
// Clear the terminal
on_clearTermButton_clicked();
}
/******************************************************************************************************************/
/* Destructor */
/******************************************************************************************************************/
MainWindow::~MainWindow() {
if(serialPort != nullptr) delete serialPort;
delete ui;
}
/******************************************************************************************************************/
void MainWindow::closeEvent(QCloseEvent *event) {
if (logFile != nullptr) {
if(logFile->isOpen()) {
logFile->close();
delete logFile;
logFile = nullptr;
}
}
// or event->accept(); but fine 'moments' are there
if (widgetsW != nullptr) widgetsW->deleteLater();
QMainWindow::closeEvent(event);
}
/******************************************************************************************************************/
void MainWindow::checkForUpdate() {
QNetworkRequest request;
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkForUpdateFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl(DEFS_URL)));
}
/******************************************************************************************************************/
/**
* Compares the two version strings (\a x and \a y).
* - If \a x is greater than \y, this function returns \c true.
* - If \a y is greater than \x, this function returns \c false.
* - If both versions are the same, this function returns \c false.
*/
bool MainWindow::compareVersions(const QString& x, const QString& y) {
QStringList versionsX = x.split (".");
QStringList versionsY = y.split (".");
int count = qMin (versionsX.count(), versionsY.count());
// qDebug() << "count: " << count;
for (int i = 0; i < count; i++) {
int a = versionsX.at(i).toInt();
int b = versionsY.at(i).toInt();
if (a > b) {
return true;
}
if (b > a) {
return false;
}
}
return versionsY.count() < versionsX.count();
}
///******************************************************************************************************************/
//void MainWindow::loadHelpFile() {
// ui->helpWebWidget->setUrl(QUrl(QStringLiteral("https://docs.google.com/document/d/e/2PACX-1vQmyyZDie11-NvYd0V3Ry10cUGisbMw1lMT7EOq4qnecPBSdgyicpQix47Plv0QDT93KMiAFPEK7MNc/pub")));
// QFont ft = ui->helpWebWidget->font();
// ui->helpWebWidget->setZoomFactor(1.5);
//}
/******************************************************************************************************************/
void MainWindow::setUpdateAvailable(bool available, QString latestVersion, QString changelog) {
QString text;
text += "<hr/>";
text += "<div style=\"text-align:center;\">";
text += "<img src=\":/Icons/Icons/logo_devlabnet_small.png\" alt=\"Smiley face\">";
text += "</div>";
text += "<hr/>";
text += "<div style=\"text-align:center;color:black;font-size:20px;background-color:#ffffb3;\">";
text += "<br>";
text += tr ("%1 Version: %2").arg(qApp->applicationName()).arg(YASP_VERSION);
text += "<br>";
text += "</div>";
if (available) {
text += "<div style=\"text-align:center;color:black;font-size:20px;background-color:#ffb3b3;\">";
text += "<br>";
text += tr("Version %1 of %2 has been released!").arg (latestVersion).arg(qApp->applicationName());
text += "<br><br>" + tr("If you like to download the update now");
text += ",<br>";
text += tr("Click on the \"Download New Version\" button above.");
text += "<br>";
text += "</div>";
text += "<br>";
text += "<hr/><b>New in version " + latestVersion + "</b>";
text += changelog;
text += "<hr/><br>";
ui->AboutTextEdit->setHtml(text);
ui->aboutNevVersionButton->setStyleSheet("color: Black; background-color: Tomato; font-weight:bold;");
ui->aboutNevVersionButton->setVisible(true);
} else {
text += "<hr/>";
text += "<div style=\"text-align:center;color:black;font-size:20px;background-color:#d9ffb3;\">";
text += "<br>";
text += tr ("Congratulations!<br>You are running the latest version of %1").arg(qApp->applicationName());
text += "<br>";
text += tr("No updates are available for the moment");
text += "<br>";
text += "</div>";
text += "<hr/><br>";
ui->AboutTextEdit->setText(text);
ui->aboutNevVersionButton->setVisible(false);
}
}
/******************************************************************************************************************/
void MainWindow::checkForUpdateFinished(QNetworkReply* reply) {
if(reply->error()) {
qDebug() << "checkForUpdateFinished ERROR --> " << reply->errorString();
}
else
{
QJsonDocument document = QJsonDocument::fromJson (reply->readAll());
/* JSON is invalid */
if (document.isNull()) {
qDebug() << "JSON is invalid !!!";
downloadUrl = "";
return;
}
QJsonValue tag = document.object().value("tag_name");
QString latestVersion = tag.toString();;
QJsonValue body = document.object().value("body");
QString bodyStr = body.toString();;
QJsonArray assets = document.object().value("assets").toArray();
QJsonObject obj = assets[0].toObject();
// QVariantList v = assets.toVariantList();
downloadUrl = obj.value("browser_download_url").toString();
// qDebug() << "downloadUrl: " << downloadUrl;
// QString platformKey = "windows";
// /* Get the platform information */
// QJsonObject updates = document.object().value ("updates").toObject();
// QJsonObject platform = updates.value (platformKey).toObject();
// /* Get update information */
// QString changelog = platform.value ("changelog").toString();
// downloadUrl = platform.value ("download-url").toString();
// QString latestVersion = platform.value ("latest-version").toString();
// qDebug() << "changelog: " << changelog;
// qDebug() << "downloadUrl: " << downloadUrl;
// qDebug() << "latestVersion: " << latestVersion;
setUpdateAvailable(compareVersions(latestVersion, YASP_VERSION), latestVersion, bodyStr);
}
reply->deleteLater();
}
/******************************************************************************************************************/
/**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->setStyleSheet("color: Black; background-color: Tomato; font-weight:bold;");
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->addItem("230400");
ui->comboBaud->addItem("500000");
ui->comboBaud->addItem("1000000");
ui->comboBaud->addItem("2000000");
// ui->comboBaud->addItem("2400000");
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->comboBaud->setCurrentIndex(7); // Select 9600 bits by default
}
/******************************************************************************************************************/
/* 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);
}
/******************************************************************************************************************/
void MainWindow::cleanGraphs() {
ui->plot->clearItems();
ui->plot->clearGraphs();
ui->plot->clearPlottables();
// ui->plot->hide();
foreach (yaspGraph* yGraph, graphs) {
Q_ASSERT(yGraph);
delete yGraph;
}
graphs.clear();
workingGraph = nullptr;
measureMode = measureType::None;
}
/******************************************************************************************************************/
void MainWindow::cleanDataGraphsBefore(double d) {
// d -= PLOT_TIME_MAX_DEF/2;
if (d < PLOT_TIME_MAX_CLEAN_DEF) return;
d -= PLOT_TIME_MAX_CLEAN_DEF;
foreach (yaspGraph* yGraph, graphs) {
Q_ASSERT(yGraph);
yGraph->plot()->data()->removeBefore(d);
}
}
/******************************************************************************************************************/
void MainWindow::cleanDataGraphs() {
foreach (yaspGraph* yGraph, graphs) {
Q_ASSERT(yGraph);
yGraph->plot()->data()->clear();
}
dataPointNumber = 0;
}
/******************************************************************************************************************/
yaspGraph* MainWindow::addGraph(int id) {
ui->plot->yAxis->setRange(-DEF_YAXIS_RANGE/2, DEF_YAXIS_RANGE/2); // Set lower and upper plot range
QString plotStr = "Plot " + QString::number(id);
QCPGraph* graph = ui->plot->addGraph();
graph->setSelectable(QCP::stNone);
QCPItemText* textLabel = new QCPItemText(ui->plot);
textLabel->setSelectable(true);
textLabel->setRoundCorners(5);
textLabel->setPadding(QMargins(8, 4, 8, 4));
textLabel->setProperty("id", id);
connect(textLabel, SIGNAL(selectionChanged (bool)), this, SLOT(plotLabelSelectionChanged(bool)));
QCPItemStraightLine* axisLine = new QCPItemStraightLine(ui->plot);
axisLine->setSelectable(false);
yaspGraph* g = new yaspGraph(id, graph, textLabel, axisLine, plotStr, colours[id], plotTimeInMilliSeconds);
graphs.insert(id, g);
return g;
}
/******************************************************************************************************************/
void MainWindow::updateLabel(int id, QString plotInfoStr) {
yaspGraph* yGraph = graphs[id];
Q_ASSERT(yGraph);
yGraph->updateLabel(plotInfoStr, ui->plot->yAxis->axisRect()->left());
if (selectedPlotId == id) {
infoModeLabel->setColor(yGraph->plot()->pen().color());
}
}
/******************************************************************************************************************/
/* Open the inside serial port; connect its signals */
/******************************************************************************************************************/
void MainWindow::openPort() {
// Clear the terminal
on_clearTermButton_clicked();
// 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); // Use local instance of QSerialPort; does not crash
serialPort->setBaudRate(baudRate, QSerialPort::AllDirections);
serialPort->setParity(parity);
serialPort->setDataBits(dataBits);
serialPort->setStopBits(stopBits);
if (serialPort->open(QIODevice::ReadWrite) ) {
ui->plot->show();
receivedData.clear();
noMsgReceivedData.clear();
portOpenedSuccess();
} else {
ui->statusBar->setStyleSheet("background-color: Tomato; font-weight:bold;");
ui->statusBar->showMessage("Cannot open port " + ui->comboPort->currentText() + " --> " + serialPort->errorString());
qDebug() << "Cannot open port " << ui->comboPort->currentText();
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->setStyleSheet("background-color: SkyBlue ; font-weight:bold;");
ui->statusBar->showMessage(selectedPort.description());
// loadHelpFile();
}
/******************************************************************************************************************/
/* Connect Button clicked slot; handles connect and disconnect */
/******************************************************************************************************************/
void MainWindow::on_connectButton_clicked() {
if (connected) {
closePort();
} else {
openPort();
}
}
/******************************************************************************************************************/
void MainWindow::initTracer() {
// Plot points
measureMode = measureType::None;
points = new QCPGraph(ui->plot->xAxis, ui->plot->yAxis);
// ui->plot->addPlottable(points);
points->setSelectable(QCP::stNone);
points->setAdaptiveSampling(false);
points->removeFromLegend();
points->setLineStyle(QCPGraph::lsNone);
points->setScatterStyle(QCPScatterStyle::ssCircle);
points->setPen(QPen(QBrush(Qt::red), 4));
infoModeLabel = new QCPItemText(ui->plot);
connect(infoModeLabel, SIGNAL(selectionChanged (bool)), this, SLOT(infoModeLabelSelectionChanged(bool)));
infoModeLabel->setVisible(false);
infoModeLabel->setSelectable(true);
infoModeLabel->setRoundCorners(15);
infoModeLabel->setBrush(QBrush(QColor(105,105,105)));
infoModeLabel->setPadding(QMargins(8, 8, 8, 8));
infoModeLabel->setSelectedColor(Qt::white);
infoModeLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
infoModeLabel->position->setType(QCPItemPosition::ptAbsolute );
QFont font;
font.setPointSize(12);
font.setStyleHint(QFont::Monospace);
font.setWeight(QFont::Bold);
font.setStyle(QFont::StyleItalic);
infoModeLabel->setFont(font);
infoModeLabel->position->setCoords(ui->plot->geometry().width() - 32, 16);
tracer = new QCPItemTracer(ui->plot);
tracer->setVisible(false);
tracer->blockSignals(true);
tracer->setSize(2);
QColor linesColor;
if (bgColor.lightness() > 128) {
linesColor = Qt::black;
} else {
linesColor = Qt::white;
}
QPen pen = QPen(linesColor, 2);
tracer->setPen(pen);
tracer->setSelectable(false);
tracerRect = new QCPItemRect(ui->plot);
tracerRect->setRoundCorners(25);
tracerRect->setVisible(false);
tracerRect->setSelectable(false);
tracerRect->setPen(pen);
tracerRect->setBrush(QBrush(QColor(200, 200, 200, 25)));
pen.setStyle(Qt::DotLine);
traceLineBottom = new QCPItemStraightLine(ui->plot);
traceLineBottom->setSelectable(false);
pen.setColor(Qt::green);
traceLineBottom->setPen(pen);
traceLineTop = new QCPItemStraightLine(ui->plot);
traceLineTop->setSelectable(false);
pen.setColor(Qt::red);
traceLineTop->setPen(pen);
traceLineLeft = new QCPItemStraightLine(ui->plot);
traceLineLeft->setSelectable(false);
pen.setColor(Qt::green);
traceLineLeft->setPen(pen);
traceLineRight = new QCPItemStraightLine(ui->plot);
traceLineRight->setSelectable(false);
pen.setColor(Qt::yellow);
traceLineRight->setPen(pen);
font.setPixelSize(12);
tracerArrowAmplitude = new QCPItemLine(ui->plot);
tracerArrowAmplitude->setSelectable(false);
tracerArrowAmplitude->setHead(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitude->setTail(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitude->setPen(QPen(QColor(150, 255, 255), 4));
tracerArrowAmplitudeTxt = new QCPItemText(ui->plot);
tracerArrowAmplitudeTxt->setSelectable(false);
tracerArrowAmplitudeTxt->setRoundCorners(5);
tracerArrowAmplitudeTxt->setPositionAlignment(Qt::AlignRight|Qt::AlignVCenter);
tracerArrowAmplitudeTxt->setTextAlignment(Qt::AlignLeft);
tracerArrowAmplitudeTxt->brush().setStyle(Qt::SolidPattern);
tracerArrowAmplitudeTxt->setFont(font);
tracerArrowAmplitudeTxt->setPen(QPen(bgColor));
tracerArrowAmplitudeTxt->setColor(bgColor);
tracerArrowAmplitudeTxt->setBrush(QBrush(QColor(200, 255, 255)));
tracerArrowAmplitudeTxt->setPadding(QMargins(8, 4, 8, 4));
tracerArrowAmplitudeTop = new QCPItemLine(ui->plot);
tracerArrowAmplitudeTop->setSelectable(false);
tracerArrowAmplitudeTop->setHead(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitudeTop->setTail(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitudeTop->setPen(QPen(QColor(255, 150, 150), 4));
tracerArrowAmplitudeTopTxt = new QCPItemText(ui->plot);
tracerArrowAmplitudeTopTxt->setSelectable(false);
tracerArrowAmplitudeTopTxt->setRoundCorners(5);
tracerArrowAmplitudeTopTxt->setPositionAlignment(Qt::AlignLeft|Qt::AlignVCenter);
tracerArrowAmplitudeTopTxt->setTextAlignment(Qt::AlignRight);
tracerArrowAmplitudeTopTxt->brush().setStyle(Qt::SolidPattern);
tracerArrowAmplitudeTopTxt->setFont(font);
tracerArrowAmplitudeTopTxt->setPen(QPen(bgColor));
tracerArrowAmplitudeTopTxt->setColor(bgColor);
tracerArrowAmplitudeTopTxt->setBrush(QBrush(QColor(255, 150, 150)));
tracerArrowAmplitudeTopTxt->setPadding(QMargins(8, 4, 8, 4));
tracerArrowAmplitudeBottom = new QCPItemLine(ui->plot);
tracerArrowAmplitudeBottom->setSelectable(false);
tracerArrowAmplitudeBottom->setHead(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitudeBottom->setTail(QCPLineEnding::esSpikeArrow);
tracerArrowAmplitudeBottom->setPen(QPen(QColor(150, 255, 150), 4));
tracerArrowAmplitudeBottomTxt = new QCPItemText(ui->plot);
tracerArrowAmplitudeBottomTxt->setSelectable(false);
tracerArrowAmplitudeBottomTxt->setRoundCorners(5);
tracerArrowAmplitudeBottomTxt->setPositionAlignment(Qt::AlignLeft|Qt::AlignVCenter);
tracerArrowAmplitudeBottomTxt->setTextAlignment(Qt::AlignRight);
tracerArrowAmplitudeBottomTxt->brush().setStyle(Qt::SolidPattern);
tracerArrowAmplitudeBottomTxt->setFont(font);
tracerArrowAmplitudeBottomTxt->setPen(QPen(bgColor));
tracerArrowAmplitudeBottomTxt->setColor(bgColor);
tracerArrowAmplitudeBottomTxt->setBrush(QBrush(QColor(150, 255, 150)));
tracerArrowAmplitudeBottomTxt->setPadding(QMargins(8, 4, 8, 4));
tracerArrowFromRef = new QCPItemLine(ui->plot);
tracerArrowFromRef->setSelectable(false);
tracerArrowFromRef->setHead(QCPLineEnding::esSpikeArrow);
tracerArrowFromRef->setTail(QCPLineEnding::esSpikeArrow);
tracerArrowFromRef->setPen(QPen(QColor(255, 255, 150), 4));
tracerArrowFromRefTxt = new QCPItemText(ui->plot);
tracerArrowFromRefTxt->setSelectable(false);
tracerArrowFromRefTxt->setRoundCorners(5);
tracerArrowFromRefTxt->setPositionAlignment(Qt::AlignRight|Qt::AlignVCenter);
tracerArrowFromRefTxt->setTextAlignment(Qt::AlignLeft);
tracerArrowFromRefTxt->brush().setStyle(Qt::SolidPattern);
tracerArrowFromRefTxt->setFont(font);
tracerArrowFromRefTxt->setPen(QPen(bgColor));
tracerArrowFromRefTxt->setColor(bgColor);
tracerArrowFromRefTxt->setBrush(QBrush(QColor(255, 255, 150)));
tracerArrowFromRefTxt->setPadding(QMargins(8, 4, 8, 4));
resetTracer();
}
/******************************************************************************************************************/
/* Slot for port opened successfully */
/******************************************************************************************************************/
void MainWindow::portOpenedSuccess() {
connect(serialPort, SIGNAL(dataTerminalReadyChanged(bool)), this, SLOT(dataTerminalReadyChanged(bool)));
serialPort->setDataTerminalReady(false);
ui->menuWidgets->menuAction()->setVisible(true);
if ((widgetsW != nullptr)) {
widgetsW->setSerialPort(serialPort);
}
ui->connectButton->setText("Disconnect"); // Change buttons
ui->statusBar->setStyleSheet("background-color: SpringGreen ; font-weight:bold;");
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
// Slot is refreshed 20 times per second
connected = true; // Set flags
plotting = true;
minValue = DBL_MAX;
maxValue = -DBL_MAX;
ui->tabWidget->setCurrentIndex(1);
// Reset the Device via DTR
serialPort->setDataTerminalReady(true);
// connect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
// connect(this, SIGNAL(newPlotData(QStringList)), this, SLOT(onNewPlotDataArrived(QStringList)));
QWidget* tabW = ui->tabWidget->findChild<QWidget *>("tabPlots");
ui->tabWidget->insertTab(1, tabW, "Plots");
ui->tabWidget->setCurrentIndex(1);
updateTimer.start();
ui->plot->xAxis->setRange(lastDataTtime - plotTimeInMilliSeconds, lastDataTtime);
ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems );
lastDataTtime = 0;
connect(&mouseWheelTimer, SIGNAL(timeout()), this, SLOT(mouseWheelTimerShoot()));
initTracer();
on_resetPlotButton_clicked();
}
/******************************************************************************************************************/
void MainWindow::keyPressEvent(QKeyEvent *event) {
if(event->key() == Qt::Key_Escape ) {
if (workingGraph) {
if (measureMode != measureType::None) {
measureMode = measureType::None;
resetTracer();
plotLabelSelectionChanged(true);
return;
}
unselectGraphs();
}
}
if( event->modifiers() == Qt::ShiftModifier ) {
if (measureMode == measureType::Arrow) {
tracerArrowFromRef->setVisible(false);
tracerArrowFromRefTxt->setVisible(false);
tracerArrowAmplitudeTopTxt->setVisible(false);
tracerArrowAmplitudeBottomTxt->setVisible(false);
} else if (measureMode == measureType::Freq) {
traceLineTop->setVisible(false);
traceLineLeft->setVisible(false);
traceLineRight->setVisible(false);
tracerStep = 0;
points->data()->clear();
traceLineRight->setVisible(false);
traceLineLeft->setVisible(false);
traceLineTop->setVisible(false);
tracerArrowAmplitudeTxt->setVisible(false);
}
}
if( event->modifiers() == Qt::ControlModifier ) {
if (measureMode == measureType::Arrow) {
tracerArrowFromRef->setVisible(true);
tracerArrowFromRefTxt->setVisible(true);
tracerArrowAmplitudeTopTxt->setVisible(true);
tracerArrowAmplitudeBottomTxt->setVisible(true);
tracerArrowFromRef->start->setCoords(tracer->position->coords());
tracerArrowFromRef->end->setCoords(tracer->position->coords());
}
else if (measureMode == measureType::Freq) {
if (tracerStep == 0) {
traceLineLeft->setVisible(true);
traceLineTop->setVisible(false);
traceLineRight->setVisible(true);
double posX = ui->plot->xAxis->pixelToCoord(mousePos.x());
traceLineLeft->point1->setCoords(posX, ui->plot->yAxis->range().lower);
traceLineLeft->point2->setCoords(posX, ui->plot->yAxis->range().upper);
traceLineRight->point1->setCoords(posX, -ui->plot->yAxis->range().lower);
traceLineRight->point2->setCoords(posX, ui->plot->yAxis->range().upper);
tracerStep = 1;
} else if (tracerStep == 1) {
tracerStep = 2;
double lineY = (tracerRect->topLeft->coords().y() + tracerRect->bottomRight->coords().y()) / 2;
traceLineTop->setVisible(true);
traceLineTop->point1->setCoords(traceLineLeft->point1->coords().x(), lineY);
traceLineTop->point2->setCoords(traceLineLeft->point1->coords().x(), lineY);
}
}
}
}
/******************************************************************************************************************/
void MainWindow::resizeEvent(QResizeEvent* event) {
QMainWindow::resizeEvent(event);
if (workingGraph) {
if (infoModeLabel && infoModeLabel->visible()) {
infoModeLabel->position->setCoords(ui->plot->geometry().width() - 32, 16);
}
}
}
/******************************************************************************************************************/
void MainWindow::dataTerminalReadyChanged(bool dtr) {
if (dtr) {
serialPort->clear(QSerialPort::AllDirections);
connect(serialPort, SIGNAL(readyRead()), this, SLOT(readData()));
}
}
/******************************************************************************************************************/
void MainWindow:: closePort() {
cleanGraphs();
ui->plot->hide();
ui->tabWidget->removeTab(1);
ui->tabWidget->setCurrentIndex(0);
if (logFile != nullptr) {
if(logFile->isOpen()) {
logFile->close();
delete logFile;
logFile = nullptr;
}
}
// Clear the terminal
on_clearTermButton_clicked();
ui->menuWidgets->menuAction()->setVisible(false);
if ((widgetsW != nullptr) && widgetsW->isVisible()) {
widgetsW->hide();
}
updateTimer.stop();
connected = false;
disconnect(serialPort, SIGNAL(readyRead()), this, SLOT(readData()));
// disconnect(this, SIGNAL(newData(QStringList)), this, SLOT(onNewDataArrived(QStringList)));
// disconnect(this, SIGNAL(newPlotData(QStringList)), this, SLOT(onNewPlotDataArrived(QStringList)));
serialPort->close(); // Close serial port
delete serialPort; // Delete the pointer
serialPort = nullptr; // Assign NULL to dangling pointer
ui->connectButton->setText("Connect"); // Change Connect button text, to indicate disconnected
ui->statusBar->setStyleSheet("background-color: SkyBlue; font-weight:bold;");
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
noMsgReceivedData.clear();
ui->stopPlotButton->setEnabled(false); // Take care of controls
ui->saveJPGButton->setEnabled(false);
enableControls(true);
}
/******************************************************************************************************************/
/* Replot */
/******************************************************************************************************************/
void MainWindow::replot() {
if(connected) {
if (plotting) {
if (ui->autoScrollCheckBox->isChecked()) {
lastDataTtime += (ui->plot->xAxis->range().size() / 2000);
}
ui->plot->xAxis->setRange(lastDataTtime - plotTimeInMilliSeconds, lastDataTtime);
// double rVal = 2 * qMax(abs(minValue), abs(maxValue));
// ui->plot->yAxis->setRange(-rVal, rVal);
ui->plot->replot();
} else {
ui->plot->xAxis->setRange(ui->plot->xAxis->range());
}
}
}
/******************************************************************************************************************/
void MainWindow::mouseWheelTimerShoot() {
mouseWheelTimer.stop();
if (workingGraph) {
if (measureMode == measureType::Box) {
infoModeLabel->setText(workingGraph->plot()->name() + " -> MEASURE BOX MODE");
} else if (measureMode == measureType::Arrow) {
infoModeLabel->setText(workingGraph->plot()->name() + " -> MEASURE ARROW MODE");
} else if (measureMode == measureType::Freq) {
infoModeLabel->setText(workingGraph->plot()->name() + " -> MEASURE FREQ MODE");
} else {
infoModeLabel->setText(workingGraph->plot()->name() + " -> SHOW MODE");
}
infoModeLabel->setColor(workingGraph->plot()->pen().color());
infoModeLabel->position->setCoords(ui->plot->geometry().width() - 32, 16);
}
}
/******************************************************************************************************************/
void MainWindow::unselectGraphs() {
// qDebug() << "<<<<<<<<<<<<< unselectGraphs >>>>>>>>>>>>>>";
resetMouseWheelState();
foreach (yaspGraph* yGraph, graphs) {
Q_ASSERT(yGraph);
yGraph->setSelected(false);
}
selectedPlotId = -1;
measureMode = measureType::None;
resetTracer();
workingGraph = nullptr;
ui->plot->setContextMenuPolicy(Qt::PreventContextMenu);
ui->plot->deselectAll();
ui->plot->replot();
}
/******************************************************************************************************************/
/* Stop Plot Button */
/******************************************************************************************************************/
void MainWindow::on_stopPlotButton_clicked() {
if (plotting) {
// Stop plotting
ui->plot->axisRect()->setRangeZoom(Qt::Vertical);
// Stop updating plot timer
plotting = false;
ui->stopPlotButton->setText("Start Plot");
} else {
// Start plotting
plotting = true;
ui->stopPlotButton->setText("Stop Plot");
}
unselectGraphs();
}
/******************************************************************************************************************/
bool MainWindow::isColor(QString str) {
if (!str.isEmpty()) {
// check if start with #, if yes --> color
if (str.at(0) == "#") {
str = str.remove(0, 1);
QRegularExpression hexMatcher("^[0-9A-F]{6}$", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = hexMatcher.match(str);
if (match.hasMatch()) {
// Found hex string of length 6.
return true;
}
}
}
return false;
}
/******************************************************************************************************************/
yaspGraph* MainWindow::getGraph(int id) {
if (graphs.contains(id)) {
return graphs[id];
}
// Create new Graph
yaspGraph* graph = addGraph(id);
return graph;
}
/******************************************************************************************************************/
void MainWindow::onNewPlotDataArrived(const QString& str) {
QStringList newData = str.split(SPACE_MSG); // Split string received from port and put it into list
if (newData.size() > 1) {
int plotId = newData.at(0).toInt();
if ((plotId < 0) || (plotId > YASP_MAXPLOT_IND)) {
qDebug() << " BAD PLOT ID : " << plotId << " --> " << newData;
addMessageText(" BAD PLOT ID : " + QString::number(plotId) + " --> " + newData.join(" / "), "tomato");
return;
}
yaspGraph* yGraph = getGraph(plotId);
QString param1 = "";
QString param2 = "";
QString id = newData.at(0);
if (newData.size() > 1) {
if (newData.size() > 2) {
param2 = newData.at(2);
}
param1 = newData.at(1);
}
if (isColor(param1)) {
QPen pen = yGraph->plot()->pen();
pen.setColor(QColor(param1));
yGraph->plot()->setPen(pen);
} else {
if ((!param1.isEmpty()) && ( yGraph->plot()->name() != param1)) {
yGraph->plot()->setName(param1);
}
}
if (isColor(param2)) {
yGraph->plot()->setPen(QPen(QColor(param2)));
} else {
if ((!param2.isEmpty()) && ( yGraph->plot()->name() != param2)) {
QPen pen = yGraph->plot()->pen();
pen.setColor(QColor(param2));
yGraph->plot()->setPen(pen);
}
}
// qDebug() << "param1 : " << param1;
// qDebug() << "param2 : " << param2;
updateLabel(plotId, yGraph->infoStr());
ui->plot->replot();
}
}
/******************************************************************************************************************/
/* Slot for new data from serial port . Data is comming in QStringList and needs to be parsed */
/******************************************************************************************************************/
void MainWindow::onNewDataArrived(const QString &str) {
QStringList newData = str.split(SPACE_MSG); // Split string received from port and put it into list
Q_ASSERT(newData.size() > 0);
int plotId = newData.at(0).toInt();
if ((plotId < 0) || (plotId > YASP_MAXPLOT_IND)) {
addMessageText(" BAD DATA ID : " + QString::number(plotId) + " --> " + newData.join(" / "), "tomato");
return;
}
yaspGraph* yGraph = getGraph(plotId);
if (yGraph) {
int dataListSize = newData.size(); // Get size of received list
// qDebug() << "NEW DATA : " << plotId << " / " << dataListSize << " --> " << newData;
dataPointNumber++;
if (dataListSize == 3) {
double currentTime = newData[1].toDouble()/1000.0;
if (currentTime < (lastDataTtime - YASP_OVERFLOW_TIME)) {
// Will normally rarely append
// Means that current millis() returned is more than YASP_OVERFLOW_TIME (1 Hour) in the past !!
// --> millis() overflow !! or Device Reset after more than 1 Hour logging (which lead to millis() / micros() reset to 0) !!
// So just clean everything in graph
qDebug() << currentTime << " ============================ CLEAN OVERFLOW ============================ " << lastDataTtime;
cleanDataGraphs();
}
bool canReplot = ((currentTime - lastDataTtime) > 25);
lastDataTtime = currentTime;
cleanDataGraphsBefore(lastDataTtime);
double val = newData[2].toDouble();
// Add data to graphs according plot Id
QCPGraph* plot = yGraph->plot();
val *= yGraph->mult();
val += yGraph->offset();
yGraph->updateMinMax(val);
plot->addData(lastDataTtime, val);
if (val < minValue) {
minValue = val;
}
if (val > maxValue) {
maxValue = val;
}
ui->dataInfoLabel->setNum(dataPointNumber);
QString plotInfoStr = " val: ";
plotInfoStr += QString::number(val, 'f', 3);
plotInfoStr += + " offset: ";
plotInfoStr += QString::number(yGraph->offset(), 'f', 3);
plotInfoStr += + " mult: ";
plotInfoStr += QString::number(yGraph->mult(), 'f', 3);
if (yGraph->getMin() < DBL_MAX) {
plotInfoStr += + " min: ";
plotInfoStr += QString::number(yGraph->getMin(), 'f', 3);
}
if (yGraph->getMax() > -DBL_MAX) {
plotInfoStr += + " max: ";