-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathwindow.cpp
More file actions
70 lines (51 loc) · 1.72 KB
/
window.cpp
File metadata and controls
70 lines (51 loc) · 1.72 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
#include "window.h"
#include <cmath> // for sine stuff
Window::Window() : plot( QString("Example Plot") ), gain(5), count(0) // <-- 'c++ initialisation list' - google it!
{
// set up the gain knob
knob.setValue(gain);
// use the Qt signals/slots framework to update the gain -
// every time the knob is moved, the setGain function will be called
connect( &knob, SIGNAL(valueChanged(double)), SLOT(setGain(double)) );
// set up the thermometer
thermo.setFillBrush( QBrush(Qt::red) );
thermo.setRange(0, 20);
thermo.show();
// set up the initial plot data
for( int index=0; index<plotDataSize; ++index )
{
xData[index] = index;
yData[index] = gain * sin( M_PI * index/50 );
}
// make a plot curve from the data and attach it to the plot
curve.setSamples(xData, yData, plotDataSize);
curve.attach(&plot);
plot.replot();
plot.show();
// set up the layout - knob above thermometer
vLayout.addWidget(&knob);
vLayout.addWidget(&thermo);
// plot to the left of knob and thermometer
hLayout.addLayout(&vLayout);
hLayout.addWidget(&plot);
setLayout(&hLayout);
}
void Window::timerEvent( QTimerEvent * )
{
// generate an sine wave input for example purposes - you must get yours from the A/D!
double inVal = gain * sin( M_PI * count/50.0 );
++count;
// add the new input to the plot
memmove( yData, yData+1, (plotDataSize-1) * sizeof(double) );
yData[plotDataSize-1] = inVal;
curve.setSamples(xData, yData, plotDataSize);
plot.replot();
// set the thermometer value
thermo.setValue( inVal + 10 );
}
// this function can be used to change the gain of the A/D internal amplifier
void Window::setGain(double gain)
{
// for example purposes just change the amplitude of the generated input
this->gain = gain;
}