-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscopewindow.cpp
664 lines (584 loc) · 18.7 KB
/
scopewindow.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
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
#include <QTimer>
#include <QPainter>
#include <QApplication>
#include <QTimerEvent>
#include <QPaintEvent>
#include <QMessageBox>
#include <QFileInfo>
extern "C" {
#include<stdio.h>
#include<fcntl.h>
#include<stdlib.h>
#include<fcntl.h>
#include<signal.h>
}
#include "scopewindow.h"
#include "special.h"
#ifdef _WIN32
#include <initguid.h>
DEFINE_GUID(g_guidServiceClass, 0xb62c4e8d, 0x62cc, 0x404b, 0xbb, 0xbf, 0xbf, 0x3e, 0x3b, 0xbb, 0x13, 0x74);
#endif
ScopeWindow::ScopeWindow(Attys_scope *attys_scope_tmp)
: QWidget(attys_scope_tmp) {
tb_init = 1;
tb_counter = tb_init;
attys_scope = attys_scope_tmp;
// erase plot
eraseFlag = 1;
// for ASCII
rec_file = NULL;
// filename
rec_filename = QString();
finalFilename = QString();
// flag if data has been recorded and we need a new filename
recorded = 0;
//////////////////////////////////////////////////////////////
// points to itself for the message listener
attysScopeCommMessage.scopeWindow = this;
// sample returned when an Attys disconnects
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
dummySample[i] = DUMMY_SAMPLE_CONSTANT;
}
// initialise the graphics stuff
ypos = new int**[attysScan.getNAttysDevices()];
yzero = new int*[attysScan.getNAttysDevices()];
assert(ypos != NULL);
assert(yzero != NULL);
minV = new float*[attysScan.getNAttysDevices()];
maxV = new float*[attysScan.getNAttysDevices()];
for(int devNo=0;devNo<attysScan.getNAttysDevices();devNo++) {
attysScan.getAttysComm(devNo)->registerMessageCallback(&attysScopeCommMessage);
ypos[devNo]=new int*[AttysComm::NCHANNELS];
yzero[devNo]=new int[AttysComm::NCHANNELS];
minV[devNo] = new float[AttysComm::NCHANNELS];
maxV[devNo] = new float[AttysComm::NCHANNELS];
assert(ypos[devNo] != NULL);
for(int i=0;i<AttysComm::NCHANNELS;i++) {
minV[devNo][i] = -10;
maxV[devNo][i] = 10;
ypos[devNo][i] = new int[MAX_DISP_X];
yzero[devNo][i] = 0;
assert( ypos[devNo][i] != NULL);
for(int j=0;j<MAX_DISP_X;j++) {
ypos[devNo][i][j]=0;
}
}
}
xpos=0;
nsamples=0;
adAvgBuffer = new float*[attysScan.getNAttysDevices()];
assert( adAvgBuffer != NULL );
unfiltDAQData = new float*[attysScan.getNAttysDevices()];
filtDAQData = new float*[attysScan.getNAttysDevices()];
assert( unfiltDAQData != NULL );
assert(filtDAQData != NULL);
for(int devNo=0;devNo<attysScan.getNAttysDevices();devNo++) {
// floating point buffer for plotting
adAvgBuffer[devNo]=new float[AttysComm::NCHANNELS];
assert( adAvgBuffer[devNo] != NULL );
for(int i=0;i<AttysComm::NCHANNELS;i++) {
adAvgBuffer[devNo][i]=0;
}
// raw data buffer for saving the data
unfiltDAQData[devNo] = new float[AttysComm::NCHANNELS];
filtDAQData[devNo] = new float[AttysComm::NCHANNELS];
assert( unfiltDAQData[devNo] != NULL );
assert(filtDAQData[devNo] != NULL);
for(int i=0;i<AttysComm::NCHANNELS;i++) {
unfiltDAQData[devNo][i]=0;
filtDAQData[devNo][i] = 0;
}
}
}
void ScopeWindow::startDAQ() {
for (int i = 0; i < attysScan.getNAttysDevices(); i++) {
if (attysScan.getAttysComm(i)) {
attysScan.getAttysComm(i)->setAdc_samplingrate_index(attys_scope->samplingRate->getSamplingRate());
attysScan.getAttysComm(i)->setBiasCurrent(attys_scope->current[i]->getCurrent());
int curr_ch1 = 0;
int curr_ch2 = 0;
switch (attys_scope->special[i][0]->getSpecial()) {
case SPECIAL_NORMAL:
attysScan.getAttysComm(i)->setAdc0_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
break;
case SPECIAL_ECG:
attysScan.getAttysComm(i)->setAdc0_mux_index(attysScan.getAttysComm(i)->ADC_MUX_ECG_EINTHOVEN);
break;
case SPECIAL_TEMPERATURE:
attysScan.getAttysComm(i)->setAdc0_mux_index(attysScan.getAttysComm(i)->ADC_MUX_TEMPERATURE);
break;
case SPECIAL_I:
attysScan.getAttysComm(i)->setAdc0_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
curr_ch1 = 1;
break;
default:
attysScan.getAttysComm(i)->setAdc0_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
}
attysScan.getAttysComm(i)->setAdc0_gain_index(attys_scope->special[i][0]->getGainIndex());
switch (attys_scope->special[i][1]->getSpecial()) {
case SPECIAL_NORMAL:
attysScan.getAttysComm(i)->setAdc1_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
break;
case SPECIAL_ECG:
attysScan.getAttysComm(i)->setAdc1_mux_index(attysScan.getAttysComm(i)->ADC_MUX_ECG_EINTHOVEN);
break;
case SPECIAL_TEMPERATURE:
attysScan.getAttysComm(i)->setAdc1_mux_index(attysScan.getAttysComm(i)->ADC_MUX_TEMPERATURE);
break;
case SPECIAL_I:
attysScan.getAttysComm(i)->setAdc1_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
curr_ch2 = 1;
break;
default:
attysScan.getAttysComm(i)->setAdc1_mux_index(attysScan.getAttysComm(i)->ADC_MUX_NORMAL);
}
attysScan.getAttysComm(i)->setAdc1_gain_index(attys_scope->special[i][1]->getGainIndex());
attysScan.getAttysComm(i)->enableCurrents(curr_ch1, 0, curr_ch2);
attysScan.getAttysComm(i)->setAccel_full_scale_index(attys_scope->acceleration[i]->getAccelerationIndex());
}
}
counter.start(500,this);
mainTimerID = startTimer(50); // run continuous timer
for (int i = 0; i < attysScan.getNAttysDevices(); i++) {
if (attysScan.getAttysComm(i))
attysScan.getAttysComm(i)->start();
}
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = attysScan.getAttysComm(n)->INDEX_Acceleration_X; i <= attysScan.getAttysComm(n)->INDEX_Acceleration_Z; i++) {
minV[n][i] = -attysScan.getAttysComm(n)->getAccelFullScaleRange();
maxV[n][i] = attysScan.getAttysComm(n)->getAccelFullScaleRange();
}
for (int i = attysScan.getAttysComm(n)->INDEX_Magnetic_field_X; i <= attysScan.getAttysComm(n)->INDEX_Magnetic_field_Z; i++) {
minV[n][i] = -attysScan.getAttysComm(n)->getMagFullScaleRange();
maxV[n][i] = attysScan.getAttysComm(n)->getMagFullScaleRange();
}
if (attys_scope->special[n][0]->getSpecial() == SPECIAL_TEMPERATURE) {
minV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_1] = -20;
maxV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_1] = 80;
}
else {
minV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_1] = -attysScan.getAttysComm(n)->getADCFullScaleRange(0);
maxV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_1] = attysScan.getAttysComm(n)->getADCFullScaleRange(0);
}
// _RPT1(0, "ADC1 max = %f\n", attysScan.getAttysComm(n]->getADCFullScaleRange(0));
if (attys_scope->special[n][1]->getSpecial() == SPECIAL_TEMPERATURE) {
minV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_2] = -20;
maxV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_2] = 80;
}
else {
minV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_2] = -attysScan.getAttysComm(n)->getADCFullScaleRange(1);
maxV[n][attysScan.getAttysComm(n)->INDEX_Analogue_channel_2] = attysScan.getAttysComm(n)->getADCFullScaleRange(1);
}
// GPIO channel 1 min/max range
minV[n][attysScan.getAttysComm(n)->INDEX_GPIO0] = -1;
maxV[n][attysScan.getAttysComm(n)->INDEX_GPIO0] = 1;
// GPIO channel 2 min/max range
minV[n][attysScan.getAttysComm(n)->INDEX_GPIO1] = -1;
maxV[n][attysScan.getAttysComm(n)->INDEX_GPIO1] = 1;
// _RPT1(0, "ADC2 max = %f\n", attysScan.getAttysComm(n]->getADCFullScaleRange(1));
}
}
ScopeWindow::~ScopeWindow() {
if (rec_file) {
fclose(rec_file);
}
for(int i=0; i<attysScan.getNAttysDevices();i++) {
if (attysScan.getAttysComm(i)) {
attysScan.getAttysComm(i)->quit();
}
}
}
void ScopeWindow::updateTime() {
QString s;
if (!rec_file) {
if (rec_filename.isEmpty()) {
s = QString::asprintf(EXECUTABLE_NAME " " VERSION);
} else {
if (recorded) {
s=finalFilename + " --- file saved";
} else {
s=rec_filename + " --- press REC to record ";
}
}
} else {
if (!finalFilename.isEmpty()) {
s = finalFilename +
QString::asprintf("--- rec: %ldsec", nsamples / attysScan.getAttysComm(0)->getSamplingRateInHz());
}
}
attys_scope->setWindowTitle( s );
std::string s2;
if (udpSocket) {
if (udpStatus < 0) {
s2 = " UDP broadcast error. ";
} else {
s2 = " UDP broadcast. ";
}
}
if (hasPythonPipe()) {
s2 = s2 + " Python script running. ";
}
attys_scope->setInfo(s2.c_str());
}
void ScopeWindow::setFilename(QString name,int tsv) {
rec_filename = name;
recorded=0;
if (tsv) {
separator='\t';
} else {
separator=',';
}
}
void ScopeWindow::startUDP(int port)
{
stopUDP();
udpSocket = new QUdpSocket(this);
udpPort = port;
_RPT1(0, "UDP transmit on port %d\n",port);
}
void ScopeWindow::stopUDP()
{
if (udpSocket != NULL) {
delete udpSocket;
}
udpSocket = NULL;
}
void ScopeWindow::writeCSV(char* tmp) {
sprintf(tmp, "%e", ((double)nPluginSamples) / ((double)attysScan.getAttysComm(0)->getSamplingRateInHz()));
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
float phy = unfiltDAQData[n][i];
sprintf(tmp+strlen(tmp), ",%e", phy);
}
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
float phy = filtDAQData[n][i];
sprintf(tmp+strlen(tmp), ",%e", phy);
}
}
sprintf(tmp+strlen(tmp), "\n");
}
void ScopeWindow::writeUDP() {
if (!udpSocket) return;
char tmp[1024];
writeCSV(tmp);
if (udpSocket) {
if (udpStatus > -1) {
#ifdef __linux__
// thre seems to be a bug either in QT or deeper down that broadcast packets
// won't work under Linux so we send them just to the localhost. That works!
udpStatus = udpSocket->writeDatagram(tmp, strlen(tmp), QHostAddress("127.0.0.1"), udpPort);
#else
udpStatus = udpSocket->writeDatagram(tmp, strlen(tmp), QHostAddress::Broadcast, udpPort);
#endif
//_RPT1(0, "%s", tmp);
}
}
}
void ScopeWindow::startPython(QString filename) {
for(auto& p:pythonPipes) {
if (!(p.running())) {
int r = p.start(filename);
if (r < 0) {
QString msg;
msg = "Command >>"+filename+"<< failed.";
QMessageBox* msgBox = new QMessageBox;
msgBox->setText(msg);
msgBox->setModal(true);
msgBox->show();
return;
}
return;
}
}
QString msg;
msg = "Too many python scripts are running. The command >>"+filename+"<< could not be started.";
QMessageBox* msgBox = new QMessageBox;
msgBox->setText(msg);
msgBox->setModal(true);
msgBox->show();
return;
}
void ScopeWindow::stopPython() {
for(auto& p:pythonPipes) {
p.stop();
}
}
void ScopeWindow::writePython() {
for(auto& p:pythonPipes) {
char tmp[1024];
writeCSV(tmp);
p.write(tmp);
}
}
void ScopeWindow::openFile() {
QRegExp reg("[0-9]{1,9}$");
if (rec_filename.isEmpty()) {
throw "Empty filename";
}
finalFilename = rec_filename;
rec_file = fopen(finalFilename.toLocal8Bit().constData(), "wt");
// could we open it?
if (!rec_file) {
rec_filename = QString();
attys_scope->recCheckBox->setChecked(0);
attys_scope->recCheckBox->setEnabled(0);
recorded = 0;
attys_scope->enableControls();
throw finalFilename.toLocal8Bit().constData();
}
fprintf(rec_file, "# %lu", (unsigned long)time(NULL));
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
char tmp[256];
attysScan.getAttysComm(n)->getBluetoothAdressString(tmp);
fprintf(rec_file, "%c%s", separator, tmp);
}
fprintf(rec_file, "\n");
}
void ScopeWindow::startRec() {
if (recorded) return;
if (rec_filename == NULL) return;
attys_scope->disableControls();
// counter for samples
nsamples = 0;
start_time = time(NULL);
try {
openFile();
} catch (const char* msg) {
fprintf(stderr,
"Writing failed.\n");
QMessageBox msgBox;
msgBox.setText(QString(msg) + QString(" could not be saved: ") + QString(strerror(errno)));
msgBox.exec();
finalFilename = "";
}
}
void ScopeWindow::clearAllRingbuffers() {
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
attysScan.getAttysComm(n)->resetRingbuffer();
}
_RPT0(0, "Ringbuffers cleared.\n");
}
// called after an Attys has re-connected
void ScopeWindow::attysHasReconnected() {
_RPT0(0, "Attys has reconnected.\n");
if (reconnectFlag) {
nsamples = (time(NULL) - start_time) * attysScan.getAttysComm(0)->getSamplingRateInHz();
reconnectFlag = 0;
}
}
void ScopeWindow::stopRec() {
if (rec_file) {
fclose(rec_file);
rec_file = NULL;
recorded = 1;
}
// re-enabel channel switches
attys_scope->enableControls();
// we should have a filename, get rid of it and create an empty one
rec_filename = QString();
finalFilename = QString();
}
void ScopeWindow::writeFile() {
if (!rec_file) return;
fprintf(rec_file, "%e", ((double)nsamples) / ((double)attysScan.getAttysComm(0)->getSamplingRateInHz()));
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
float phy = unfiltDAQData[n][i];
fprintf(rec_file, "%c%e", separator, phy);
}
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
float phy = filtDAQData[n][i];
fprintf(rec_file, "%c%e", separator, phy);
}
}
fprintf(rec_file, "\n");
}
// called by the refresh timer
void ScopeWindow::paintEvent(QPaintEvent *) {
QPainter paint( this );
QPen penData[3]={QPen(QColor(0,255,255),1),
QPen(QColor(255,255,0),1),
QPen(QColor(255,0,255),1)};
QPen penWhite(Qt::white,2);
int act = 0;
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
if (attys_scope->
channel[n][i]->
isActive()) {
paint.setPen(penData[act % 3]);
QString s = QString::fromStdString(attysScan.getAttysComm(0)->
CHANNEL_SHORT_DESCRIPTION[attys_scope->channel[n][i]->getChannel()]);
if (attysScan.getAttysComm(n)->hasActiveConnection()) {
s = QString::asprintf("%d ", n) + s;
}
else {
s = QString::asprintf("%d offline", n);
}
paint.drawText(QPoint(0,yzero[n][i]), s);
for(int x = 0; x < (w-1); x++) {
if ((x < (xpos-1)) || (x > (xpos+3))) {
paint.drawLine(x, ypos[n][i][x],
x + 1, ypos[n][i][x + 1]);
if (x % 2) {
paint.drawPoint(x, yzero[n][i]);
}
}
}
act++;
}
}
}
}
void ScopeWindow::setTB(int us) {
tb_init=us/(1000000/ attysScan.getAttysComm(0)->getSamplingRateInHz());
tb_counter=tb_init;
for(int n=0;n<attysScan.getNAttysDevices();n++) {
for(int i=0;i<AttysComm::NCHANNELS;i++) {
adAvgBuffer[n][i]=0;
}
}
}
void ScopeWindow::calcScreenParameters() {
w = width();
h = height();
num_channels=0;
for(int n=0;n<attysScan.getNAttysDevices();n++) {
for(int i=0;i<AttysComm::NCHANNELS;i++) {
if (attys_scope->channel[n][i]->isActive()) {
num_channels++;
}
}
}
if (num_channels < 1) {
return;
}
base = h / num_channels;
}
void ScopeWindow::convertSampleToPlot(float **buffer) {
int act = 1;
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
if (attys_scope->
channel[n][i]->
isActive()) {
float dy = (float)base / (float)(maxV[n][attys_scope->channel[n][i]->getChannel()]
- minV[n][attys_scope->channel[n][i]->getChannel()]);
float gain = attys_scope->gain[n][i]->getGain();
float value = buffer[n][i] * gain;
int yZero = base*act - (int)((0 - minV[n][attys_scope->channel[n][i]->getChannel()])*dy);
int yTmp = base*act - (int)((value - minV[n][attys_scope->channel[n][i]->getChannel()])*dy);
ypos[n][i][xpos] = yTmp;
yzero[n][i] = yZero;
act++;
}
}
}
if ((++xpos) >= w) {
xpos = 0;
}
}
void ScopeWindow::processData() {
// let's empty the ring bufferes and plot them
for (;;) {
// number of devices which re-connect at the moment
int nReconnecting = 0;
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
int hasSample = attysScan.getAttysComm(n)->hasSampleAvailable();
int isActive = attysScan.getAttysComm(n)->hasActiveConnection();
if (isActive) {
// we should have samples here but if not we return and
// wait for some
if (!hasSample) return;
}
else {
// no data available but soon, so no sample to get
// but can be set to zero temporarily
nReconnecting++;
}
}
if (nReconnecting == attysScan.getNAttysDevices()) {
if (nsamples > 0) {
reconnectFlag = 1;
}
return;
}
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
float* values;
if (attysScan.getAttysComm(n)->hasActiveConnection()) {
values = attysScan.getAttysComm(n)->getSampleFromBuffer();
}
else {
values = dummySample;
}
if (attys_scope->special[n][0]->getSpecial() == SPECIAL_TEMPERATURE) {
values[attysScan.getAttysComm(n)->INDEX_Analogue_channel_1] =
AttysComm::phys2temperature(values[attysScan.getAttysComm(n)->INDEX_Analogue_channel_1]);
}
if (attys_scope->special[n][1]->getSpecial() == SPECIAL_TEMPERATURE) {
values[attysScan.getAttysComm(n)->INDEX_Analogue_channel_2] =
AttysComm::phys2temperature(values[attysScan.getAttysComm(n)->INDEX_Analogue_channel_2]);
}
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
unfiltDAQData[n][i] = values[i];
if (attys_scope->channel[n][i]->isActive()) {
float value = values[attys_scope->channel[n][i]->getChannel()];
value = attys_scope->highpass[n][i]->filter(value);
value = attys_scope->lowpass[n][i]->filter(value);
value = attys_scope->bandstop[n][i]->filter(value);
filtDAQData[n][i] = value;
// average response if TB is slower than sampling rate
adAvgBuffer[n][i] = adAvgBuffer[n][i] + value;
}
else {
filtDAQData[n][i] = 0;
}
}
}
// save data
if (attys_scope->recCheckBox->checkState()) {
writeFile();
}
writeUDP();
writePython();
nsamples++;
nPluginSamples++;
tb_counter--;
// enough averaged?
if (tb_counter <= 0) {
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
adAvgBuffer[n][i] = adAvgBuffer[n][i] / tb_init;
}
}
// plot the stuff
convertSampleToPlot(adAvgBuffer);
// clear buffer
tb_counter = tb_init;
for (int n = 0; n < attysScan.getNAttysDevices(); n++) {
for (int i = 0; i < AttysComm::NCHANNELS; i++) {
adAvgBuffer[n][i] = 0;
}
}
}
}
}
void ScopeWindow::timerEvent( QTimerEvent *event )
{
if (mainTimerID == event->timerId()) {
processData();
calcScreenParameters();
update();
return;
}
if (counter.timerId() == event->timerId()) {
updateTime();
return;
}
QWidget::timerEvent(event);
}
void ScopeWindow::clearScreen()
{
eraseFlag = 1;
repaint();
}