-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
144 lines (124 loc) · 3.12 KB
/
window.cpp
File metadata and controls
144 lines (124 loc) · 3.12 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
#include "window.h"
#include "adcreader.h"
#include <cmath> // for sine stuff
double max=0.0;
Window::Window() : func(0),count(0)
{
knob = new QwtKnob;
// set up the gain knob
knob->setValue(0);
// use the Qt signals/slots framework to update the gain -
// every time the knob is moved, the setFunc function will be called
connect( knob, SIGNAL(valueChanged(double)), SLOT(setFunc(double)) );
// set up the thermometer
//thr=new QPushButton;
//thr->setText(tr("Threshold"));
//thr->show();
m_label = new QwtTextLabel;
m_label->setText("Max: ");
m_label->show();
m1_label= new QwtTextLabel;
m1_label->setText("0");
m1_label->show();
// set up the initial plot data
for( int index=0; index<plotDataSize; ++index )
{
xData[index] = index;
yData[index] = 0;
}
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(m_label);
vLayout->addWidget(m1_label);
//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 * )
{
int inval;
double fsrvolt;
double fsrres;
double fsrcon;
double fsrforce;
double slope;
double inv=3300;
double val=65536;
double res=10000;
double condd=1000000;
double value;
count =0;
while(adcreader->read_enable()){
inval=adcreader->get_samples();
if (func==1){
inval=inval+32768-12668;
slope= inv/val;
fsrvolt=slope*inval;
fsrres=(inv-fsrvolt)*res;
fsrres/=fsrvolt;
fsrcon=condd;
fsrcon/=fsrres;
if(fsrcon<=1000){
fsrforce=fsrcon/80;
}else{
fsrforce=fsrcon-1000;
fsrforce/=30;
}
if (max<fsrforce){
max=fsrforce;
}
char m_buf[sizeof(max)];
sprintf(m_buf,"%f",max);
m1_label->setText(m_buf);
value=fsrforce;
}else if (func==2){
max=0;
if (inval>=10000){
value=1;
}else{
max=0;
value=0;
}
}else {
value=inval;
}
// add the new input to the plot
memmove( yData, yData+1, (plotDataSize-1) * sizeof(double) );
yData[plotDataSize-1] = value;
curve->setSamples(xData, yData, plotDataSize);
plot->replot();
}
// set the thermometer value
//thermo->setValue( inVal + 20 );
}
// this function can be used to change the gain of the A/D internal amplifier
void Window::setFunc(double func)
{
// for example purposes just change the amplitude of the generated input
this->func = func;
}