-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
268 lines (222 loc) · 6.09 KB
/
mainwindow.cpp
File metadata and controls
268 lines (222 loc) · 6.09 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
#include <QTimer>
#include <QDebug>
#include <QScrollBar>
#include <QPen>
#include <QPainterPath>
#include <QFuture>
#include <QtConcurrent>
#include <QtSerialPort/QSerialPort>
#include "serialengine.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QThread* thread = new QThread;
serial = new serialengine();
serial->moveToThread(thread);
QObject::connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater()));
thread->start();
serial->start();
m_dep_x = DEP_X;
m_nbvalmoy = ui->sB_nbMoyenne->value();
ui->gridLayout_4->setGeometry(ui->centralWidget->rect());
this->setWindowTitle("HeatMonitor");
this->setWindowIcon(QIcon(":/icon/heatcon.png"));
// QMainWindow::centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
moytab = (int*) malloc(sizeof(int) * NBVALMOY);
int i = m_nbvalmoy;
while (i--)
{
moytab[i] = 0;
}
m_stop = 0;
g_axis_x = NULL;
m_consigne = 0;
m_olx = 0;
m_moyennepath = NULL;
moyenne = 0;
m_timereset = 100;
// future = new QFuture<int>;
g_moyennepath = NULL;
g_datagraph = NULL;
yqpath = NULL;
ypath = NULL;
m_datapath= NULL;
yline= NULL;
yqline= NULL;
scene = new QGraphicsScene(this);
updateTimer = new QTimer(this);
view = new QGraphicsView(scene);
// ui->gridLayout_4->
// g_axis_x = new QGraphicsLineItem(ui->gridLayout->geometry().x(), ui->gridLayout->geometry().height()/2, ui->gridLayout->geometry().width(), ui->gridLayout->geometry().height()/2);
init_graph();
connect(updateTimer, SIGNAL(timeout()), this, SLOT(myupdate()), Qt::QueuedConnection);
// connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(update_graph(int)));
updateTimer->start(m_timereset);
}
void MainWindow::init_graph()
{
if (g_moyennepath)
delete g_moyennepath;
if (scene)
delete scene;
scene = new QGraphicsScene(this);
if (view)
delete view;
view = new QGraphicsView(scene);
g_axis_x = NULL;
g_moyennepath = NULL;
g_datagraph = NULL;
m_oldy = scene->height()/2;
view->setGeometry(ui->gridLayout->geometry());
ui->gridLayout->addWidget(view);
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
qDebug() << " width :" << this->geometry().width() << " height :" << this->geometry().height();
}
void MainWindow::myupdate()
{
static long long count = 0;
static int posx = 0;
static int posy = 0;
disconnect(updateTimer, SIGNAL(timeout()), this, SLOT(myupdate()));
temperature = serial->get_temp();
// Display temperature (lcdNumber)
ui->lcdN_Data->display(temperature);
// calc pos on view
posy = ui->gridLayout->geometry().height()/2 -temperature;
posx += m_dep_x;
if (posx > ui->gridLayout->geometry().width())
draw_background(posx);
if (count > 1 && posx > m_dep_x)
{
drawfirststep(posx, posy);
}
else
{
// first loop after reset
// init part draw x axis
draw_background(0);
}
// calc moyenne (qfuture)
moyenne_update(posx, posy, &count); // count++ here
endpos_update(&posx);
if (!m_moyennepath)
{
m_moyennepath = new QPainterPath();
m_moyennepath->moveTo(posx, moyenne / ((count < m_nbvalmoy) ? count : m_nbvalmoy));
}
m_moyennepath->lineTo(posx, moyenne / ((count < m_nbvalmoy) ? count : m_nbvalmoy));
setmoyenne( moyenne / ((count < m_nbvalmoy) ? count : m_nbvalmoy));
connect(updateTimer, SIGNAL(timeout()), this, SLOT(myupdate()), Qt::QueuedConnection);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_b_stop_clicked()
{
static int state = 0;
state++;
if (state%2)
{
disconnect(updateTimer, SIGNAL(timeout()), this, SLOT(myupdate()));
}
else
{
connect(updateTimer, SIGNAL(timeout()), this, SLOT(myupdate()));
}
}
void MainWindow::on_cBscroll_toggled(bool checked)
{
if (!checked)
{
if (m_olx + m_dep_x > ui->gridLayout->geometry().width())
init_graph();
}
}
void MainWindow::on_send_clicked()
{
double temp_send=ui->doubleSpinBox->value();
serial->write(ui->doubleSpinBox->text());
m_consigne = (int)temp_send;
// serial->write(temp_send);
qDebug()<<temp_send;
}
void MainWindow::on_sB_Rand_valueChanged(int arg1)
{
serial->set_rand(arg1);
}
void MainWindow::on_sB_speed_valueChanged(int arg1)
{
serial->set_speed(arg1);
}
void MainWindow::on_sB_update_valueChanged(int arg1)
{
updateTimer->stop();
m_timereset = arg1;
updateTimer->start(m_timereset);
}
void MainWindow::on_b_open_clicked()
{
serial->set_sername(ui->tE_Name->toPlainText());
serial->set_speed(ui->sB_speed->value());
serial->set_baudrate(ui->cB_BaudRate->currentText().toInt());
switch (ui->cB_DataBits->currentIndex()) {
case 0:
serial->set_databits(8);
break;
case 1:
serial->set_databits(5);
break;
case 2:
serial->set_databits(6);
break;
case 3:
serial->set_databits(7);
break;
case 4:
serial->set_databits(-1);
break;
default:
break;
}
serial->set_parity(ui->cB_Parity->currentIndex());
serial->set_stopBits(ui->cB_StopBits->currentIndex());
serial->set_flowcontrol(ui->cB_FlowControl->currentIndex());
serial->openSerialPort();
}
void MainWindow::on_b_serClose_clicked()
{
serial->closeSerialPort();
}
void MainWindow::on_sB_movex_valueChanged(int arg1)
{
m_dep_x = arg1;
}
void MainWindow::on_radioButton_clicked()
{
if (ui->radioButton->isChecked())
g_moyennepath->hide();
else
g_moyennepath->show();
}
void MainWindow::on_sB_nbMoyenne_valueChanged(int arg1)
{
m_nbvalmoy = arg1;
if (moytab)
delete moytab;
future.cancel();
moytab = (int*) malloc(sizeof(int) * m_nbvalmoy);
int i = m_nbvalmoy;
while (i--)
{
moytab[i] = 0;
}
}