-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaincontrols.cpp
502 lines (426 loc) · 16.2 KB
/
maincontrols.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
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Slot for port opened successfully */
/******************************************************************************************************************/
/*void MainWindow::portOpenedSuccess()
{
//qDebug() << "Port opened signal received!";
ui->statusBar->showMessage("Conectado!"); // Disable controls if port is open
ui->saveJPGButton->setEnabled(true); // Enable button for saving plot
crearGrafico1(); // Create the QCustomPlot area // Create the QCustomPlot area
updateTimer.setInterval(500); // Slot is refreshed 20 times per second
/********* Modificacion
* ui->stopPlotButton->setText("Stop Plot"); // Enable button for stopping plot
* ui->stopPlotButton->setEnabled(true);
* updateTimer.stop(); // Stop updating plot timer
*
* Con la modificacion no inicia solo el grafico
*
plotting = false;
ui->stopPlotButton->setEnabled(true);
ui->stopPlotButton->setText("Iniciar! ");
connected = true; // Set flags
//plotting = true;
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* 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");
}
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Imprime las coordenadas del puntero del mouse en el barra de estado */
/******************************************************************************************************************/
void MainWindow::onMouseMoveInPlot(QMouseEvent *event)
{
int xx = ui->plot->xAxis->pixelToCoord(event->x());
double yy = ui->plot->yAxis->pixelToCoord(event->y());
QDateTime tt;
tt.fromTime_t(xx);
QString coordinates("X: %1 Y: %2");
coordinates = coordinates.arg(tt.fromTime_t(xx).toString()).arg(yy);
ui->statusBar->showMessage(coordinates);
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Shows a window with instructions */
/******************************************************************************************************************/
void MainWindow::on_actionHow_to_use_triggered()
{
helpWindow = new HelpWindow(this);
helpWindow->setWindowTitle("Como usar esta aplicacion!");
helpWindow->show();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/**Create the GUI */
/******************************************************************************************************************/
void MainWindow::createUI()
{
max_slider = 100;
min_slider = 0;
high = 40.00;
lower = -10.00;
res = (high-lower)/max_slider; // Que me permita variar de 40ºC hasta -10ºC
termometros[0] = ui->Thermo;
termometros[1] = ui->Thermo_2;
termometros[2] = ui->Thermo_3;
termometros[3] = ui->Thermo_4;
termometros[4] = ui->Thermo_5;
termometros[5] = ui->Thermo_6;
termometros[6] = ui->Thermo_7;
termometros[7] = ui->Thermo_8;
temps_actuales[0] = ui->label_t1;
temps_actuales[1] = ui->label_t2;
temps_actuales[2] = ui->label_t3;
temps_actuales[3] = ui->label_t4;
temps_actuales[4] = ui->label_t5;
temps_actuales[5] = ui->label_t6;
temps_actuales[6] = ui->label_t7;
temps_actuales[7] = ui->label_t8;
for(int i = 0; i<8; i++)
{
temperaturas.temp[i] = 18.00;
termometros[i]->setMaximum(35.00);
termometros[i]->setMinimum(-5.00);
}
UpdateTemps();
sliders[0] = ui->verticalSlider;
sliders[1] = ui->verticalSlider_2;
sliders[2] = ui->verticalSlider_3;
sliders[3] = ui->verticalSlider_4;
sliders[4] = ui->verticalSlider_5;
sliders[5] = ui->verticalSlider_6;
sliders[6] = ui->verticalSlider_7;
sliders[7] = ui->verticalSlider_8;
edit_target[0] = ui->doubleSpinBox;
edit_target[1] = ui->doubleSpinBox_2;
edit_target[2] = ui->doubleSpinBox_3;
edit_target[3] = ui->doubleSpinBox_4;
edit_target[4] = ui->doubleSpinBox_5;
edit_target[5] = ui->doubleSpinBox_6;
edit_target[6] = ui->doubleSpinBox_7;
edit_target[7] = ui->doubleSpinBox_8;
for(int i = 0; i<8; i++)
{
edit_target[i]->setMaximum(40.00);
edit_target[i]->setMinimum(-10.00);
}
ui->fecha1Historico->setDate(QDate::currentDate().addMonths(-1));
ui->fecha2Historico->setDateTime(QDateTime::currentDateTime());
salidaAct[0] = ui->habilitadoCheckBox1;
salidaAct[1] = ui->habilitadoCheckBox2;
salidaAct[2] = ui->habilitadoCheckBox3;
salidaAct[3] = ui->habilitadoCheckBox4;
salidaAct[4] = ui->habilitadoCheckBox5;
salidaAct[5] = ui->habilitadoCheckBox6;
salidaAct[6] = ui->habilitadoCheckBox7;
salidaAct[7] = ui->habilitadoCheckBox8;
frioHab[0] = ui->frioCheckBox;
frioHab[1] = ui->frioCheckBox_2;
frioHab[2] = ui->frioCheckBox_3;
frioHab[3] = ui->frioCheckBox_4;
frioHab[4] = ui->frioCheckBox_5;
frioHab[5] = ui->frioCheckBox_6;
frioHab[6] = ui->frioCheckBox_7;
frioHab[7] = ui->frioCheckBox_8;
calorHab[0] = ui->calorCheckBox;
calorHab[1] = ui->calorCheckBox_2;
calorHab[2] = ui->calorCheckBox_3;
calorHab[3] = ui->calorCheckBox_4;
calorHab[4] = ui->calorCheckBox_5;
calorHab[5] = ui->calorCheckBox_6;
calorHab[6] = ui->calorCheckBox_7;
calorHab[7] = ui->calorCheckBox_8;
frioSal[0] = ui->salidaFrioLineEdit;
frioSal[1] = ui->salidaFrioLineEdit_2;
frioSal[2] = ui->salidaFrioLineEdit_3;
frioSal[3] = ui->salidaFrioLineEdit_4;
frioSal[4] = ui->salidaFrioLineEdit_5;
frioSal[5] = ui->salidaFrioLineEdit_6;
frioSal[6] = ui->salidaFrioLineEdit_7;
frioSal[7] = ui->salidaFrioLineEdit_8;
calorSal[0] = ui->salidaCalorLineEdit;
calorSal[1] = ui->salidaCalorLineEdit_2;
calorSal[2] = ui->salidaCalorLineEdit_3;
calorSal[3] = ui->salidaCalorLineEdit_4;
calorSal[4] = ui->salidaCalorLineEdit_5;
calorSal[5] = ui->salidaCalorLineEdit_6;
calorSal[6] = ui->salidaCalorLineEdit_7;
calorSal[7] = ui->salidaCalorLineEdit_8;
led_frio[0] = ui->fled1;
led_frio[1] = ui->fled2;
led_frio[2] = ui->fled3;
led_frio[3] = ui->fled4;
led_frio[4] = ui->fled5;
led_frio[5] = ui->fled6;
led_frio[6] = ui->fled7;
led_frio[7] = ui->fled8;
led_calor[0] = ui->hled1;
led_calor[1] = ui->hled2;
led_calor[2] = ui->hled3;
led_calor[3] = ui->hled4;
led_calor[4] = ui->hled5;
led_calor[5] = ui->hled6;
led_calor[6] = ui->hled7;
led_calor[7] = ui->hled8;
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* 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();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* 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();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* 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();
}
/******************************************************************************************************************/
/******************************************************************************************************************/
/* Spin box for changing the Y Tick step */
/******************************************************************************************************************/
void MainWindow::on_spinYStep_valueChanged(int arg1)
{
ui->plot->yAxis->setTickStep(arg1);
ui->plot->replot();
}
/******************************************************************************************************************/
void MainWindow::SetActualTemp(int fermentador, double temp)
{
if( fermentador >=0 && fermentador<8)
{
termometros[fermentador]->setValue(temp);
temps_actuales[fermentador]->setText(QString::number(temp)+" ºC");
}
}
void MainWindow::UpdateTemps()
{
for(int i = 0; i < CANT; i++)
{
SetActualTemp(i, temperaturas.temp[i]);
}
}
void MainWindow::UpdateTargets()
{
for(int i = 0; i < CANT; i++)
{
edit_target[i]->setValue(temp_target.set_temp[i]);
}
}
void MainWindow::UpdateConfig()
{
/* uint8_t frio; // Utilizo los bits como booleanos
uint8_t calor; // Utilizo los bits como booleanos
uint8_t salida_frio[8];
uint8_t salida_calor[8];
uint8_t habilitado; // Utilizo los bits como booleanos
uint8_t fulltime;
float temp[2];
QCheckBox *salidaAct[CANT];
QCheckBox *frioHab[CANT];
QCheckBox *calorHab[CANT];
QLineEdit *frioSal[CANT];
QLineEdit *calorSal[CANT];
uint8_t estado_bombas;
uint8_t estado_salidas_cold, estado_salidas_hot;
*/
uint8_t tmp;
uint8_t mask = 0x01;
for(int i = 0; i < CANT; i++)
{
qDebug() << "Mascara = "<< (int)mask;
tmp = configuracion.frio&mask;
qDebug() << "FRIO Luego de mascara = "<< tmp;
if(tmp>0)
{
frioHab[i]->setChecked(1);
}
else
{
frioHab[i]->setChecked(0);
}
tmp = configuracion.calor&mask;
qDebug() << "CALOR Luego de mascara = "<< tmp;
if(tmp>0)
{
calorHab[i]->setChecked(1);
}
else
{
calorHab[i]->setChecked(0);
}
tmp = configuracion.habilitado&mask;
qDebug() << "HABILITADO Luego de mascara = "<< tmp;
if(tmp>0)
{
salidaAct[i]->setChecked(1);
}
else
{
salidaAct[i]->setChecked(0);
}
frioSal[i]->setText(QString::number(configuracion.salida_frio[i]));
calorSal[i]->setText(QString::number(configuracion.salida_calor[i]));
// Prendo Leds de valvulas frio
tmp = configuracion.estado_salidas_cold&mask;
if(tmp>0)
{
led_frio[i]->setChecked(1);
}
else
{
led_frio[i]->setChecked(0);
}
// Prendo Leds de valvulas frio
tmp = configuracion.estado_salidas_hot&mask;
if(tmp>0)
{
led_calor[i]->setChecked(1);
}
else
{
led_calor[i]->setChecked(0);
}
mask = mask*2;
}
ui->temp9Label->setText(QString::number(configuracion.temp[0]));
ui->temp10Label->setText(QString::number(configuracion.temp[1]));
ui->fullTimeCheckBox->setChecked((bool)configuracion.fulltime);
}
void MainWindow::on_verticalSlider_valueChanged(int value)
{
edit_target[0]->setValue(CalcRange(value));
ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_2_valueChanged(int value)
{
edit_target[1]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_3_valueChanged(int value)
{
edit_target[2]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_4_valueChanged(int value)
{
edit_target[3]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_5_valueChanged(int value)
{
edit_target[4]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_6_valueChanged(int value)
{
edit_target[5]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_7_valueChanged(int value)
{
edit_target[6]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_verticalSlider_8_valueChanged(int value)
{
edit_target[7]->setValue(CalcRange(value));
//ui->progressBar->setValue(value);
}
void MainWindow::on_doubleSpinBox_valueChanged(double arg1)
{
sliders[0]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_2_valueChanged(double arg1)
{
sliders[1]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_3_valueChanged(double arg1)
{
sliders[2]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_4_valueChanged(double arg1)
{
sliders[3]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_5_valueChanged(double arg1)
{
sliders[4]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_6_valueChanged(double arg1)
{
sliders[5]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_7_valueChanged(double arg1)
{
sliders[6]->setValue(CalcRange(arg1));
}
void MainWindow::on_doubleSpinBox_8_valueChanged(double arg1)
{
sliders[7]->setValue(CalcRange(arg1));
}
conf MainWindow::getConfigFromForm()
{
/* uint8_t frio; // Utilizo los bits como booleanos
uint8_t calor; // Utilizo los bits como booleanos
uint8_t salida_frio[8];
uint8_t salida_calor[8];
uint8_t habilitado; // Utilizo los bits como booleanos
uint8_t fulltime;
float temp[2];
QCheckBox *salidaAct[CANT];
QCheckBox *frioHab[CANT];
QCheckBox *calorHab[CANT];
QLineEdit *frioSal[CANT];
QLineEdit *calorSal[CANT];
*/
uint8_t tmp;
uint8_t mask = 0x01;
conf t;
t.frio = 0;
t.calor = 0;
t.habilitado = 0;
if(ui->fullTimeCheckBox->isChecked())
{
t.fulltime = 0x01;
}
for(int i = 0; i < CANT; i++)
{
qDebug() << "Mascara = "<< (int)mask;
t.salida_frio[i] = this->frioSal[i]->text().toUInt();
t.salida_calor[i] = this->calorSal[i]->text().toUInt();
t.frio += frioHab[i]->isChecked()*mask;
t.calor += calorHab[i]->isChecked()*mask;
t.habilitado += salidaAct[i]->isChecked()*mask;
mask = mask*2;
}
return t;
}