forked from berndporr/qwt-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.cpp
91 lines (71 loc) · 2.19 KB
/
window.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
#include "window.h"
// #include "adcreader.h"
#include <cmath> // for sine stuff
Window::Window() : gain(5), count(0)
{
knob = new QwtKnob;
// 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 = new QwtThermo;
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 );
}
curve = new QwtPlotCurve;
plot = new QwtPlot;
// 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 = new QVBoxLayout;
vLayout->addWidget(knob);
vLayout->addWidget(thermo);
// plot to the left of knob and thermometer
hLayout = new QHBoxLayout;
hLayout->addLayout(vLayout);
hLayout->addWidget(plot);
setLayout(hLayout);
// This is a demo for a thread which can be
// used to read from the ADC asynchronously.
// At the moment it doesn't do anything else than
// running in an endless loop and which prints out "tick"
// every second.
// adcreader = new ADCreader();
// adcreader->start();
}
Window::~Window() {
// tells the thread to no longer run its endless loop
// adcreader->quit();
// wait until the run method has terminated
// adcreader->wait();
// delete adcreader;
}
void Window::timerEvent( QTimerEvent * )
{
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;
}