Line 6... |
Line 6... |
6 |
#include <iostream> |
6 |
#include <iostream> |
7 |
#include <stdio.h> |
7 |
#include <stdio.h> |
8 |
|
8 |
|
9 |
using namespace std; |
9 |
using namespace std; |
10 |
|
10 |
|
- |
|
11 |
void UI(void); |
11 |
|
12 |
|
12 |
Scope::Scope(QWidget *parent) { // CONSTRUCTOR, graphic stuff |
13 |
Scope::Scope(QWidget *parent) { // CONSTRUCTOR, graphic stuff |
13 |
dataAquired=0; |
14 |
dataAquired=0; |
14 |
|
15 |
|
15 |
// data=new int[LEN*sizeof(int)]; ; |
16 |
// data=new int[LEN*sizeof(int)]; ; |
Line 25... |
Line 26... |
25 |
scaleSlider->setRange(1, 256); |
26 |
scaleSlider->setRange(1, 256); |
26 |
scaleSlider->setValue(DEF_SCALE); |
27 |
scaleSlider->setValue(DEF_SCALE); |
27 |
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int))); |
28 |
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int))); |
28 |
|
29 |
|
29 |
shiftSlider = new QSlider(Qt::Horizontal,this); |
30 |
shiftSlider = new QSlider(Qt::Horizontal,this); |
30 |
shiftSlider->setRange(-60000, +60000); |
31 |
shiftSlider->setRange(0, +60000); |
31 |
shiftSlider->setValue(DEF_SHIFT); |
32 |
shiftSlider->setValue(DEF_SHIFT); |
32 |
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int))); |
33 |
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int))); |
33 |
|
34 |
|
34 |
updateTimer = new QTimer(this); |
35 |
updateTimer = new QTimer(this); |
35 |
updateTimer->start(TICK); |
36 |
updateTimer->start(TICK); |
36 |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
37 |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
37 |
|
38 |
|
- |
|
39 |
labels[1] = new QLabel(this); |
- |
|
40 |
/*QString tempStr; |
- |
|
41 |
tempStr.setNum(shift); |
38 |
QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 ) |
42 |
labels[1]->setText("Zero level: " + tempStr); |
- |
|
43 |
labels[1]->setGeometry (20, 550, 200, 20); |
- |
|
44 |
labels[1]->show(); |
- |
|
45 |
shiftSlider->setGeometry(QRect(20,580,400,60)); |
- |
|
46 |
shiftSlider->show();*/ |
- |
|
47 |
|
- |
|
48 |
|
- |
|
49 |
labels[2] = new QLabel(this); |
- |
|
50 |
this->UI();/* |
- |
|
51 |
tempStr.setNum(scale); |
- |
|
52 |
labels[2]->setText("Divisor: " + tempStr); |
- |
|
53 |
labels[2]->setGeometry (20, 630, 400, 20); |
- |
|
54 |
labels[2]->show(); |
39 |
scaleSlider->setGeometry(QRect(20,600,400,60)); |
55 |
scaleSlider->setGeometry(QRect(20,660,400,60)); |
40 |
scaleSlider->show(); |
56 |
scaleSlider->show();*/ |
41 |
|
57 |
|
42 |
shiftSlider->setGeometry(QRect(20,680,400,60)); |
- |
|
43 |
shiftSlider->show(); |
- |
|
- |
|
58 |
} |
44 |
|
59 |
|
- |
|
60 |
void Scope::UI(void) { |
45 |
// getData(); |
61 |
QString tempStr; |
- |
|
62 |
tempStr.setNum(shift); |
- |
|
63 |
labels[1]->setText("Zero level: " + tempStr); |
- |
|
64 |
labels[1]->setGeometry (20, 550, 200, 20); |
- |
|
65 |
labels[1]->show(); |
- |
|
66 |
shiftSlider->setGeometry(QRect(20,580,400,60)); |
- |
|
67 |
shiftSlider->show(); |
46 |
|
68 |
|
- |
|
69 |
tempStr.setNum(scale); |
- |
|
70 |
labels[2]->setText("Divisor: " + tempStr); |
- |
|
71 |
labels[2]->setGeometry (20, 630, 400, 20); |
- |
|
72 |
labels[2]->show(); |
- |
|
73 |
scaleSlider->setGeometry(QRect(20,660,400,60)); |
- |
|
74 |
scaleSlider->show(); |
47 |
} |
75 |
} |
48 |
|
76 |
|
49 |
|
77 |
|
- |
|
78 |
|
- |
|
79 |
|
- |
|
80 |
|
- |
|
81 |
|
50 |
Scope::~Scope() { |
82 |
Scope::~Scope() { |
51 |
delete [] data; |
83 |
delete [] data; |
52 |
} |
84 |
} |
53 |
|
85 |
|
54 |
|
86 |
|
Line 65... |
Line 97... |
65 |
painter.drawLine(LEFT-1,TOP+HEIGHT/2,LEFT+WIDTH+1,TOP+HEIGHT/2); |
97 |
painter.drawLine(LEFT-1,TOP+HEIGHT/2,LEFT+WIDTH+1,TOP+HEIGHT/2); |
66 |
|
98 |
|
67 |
int i; |
99 |
int i; |
68 |
|
100 |
|
69 |
for(i=0;i<LEN;i++) { |
101 |
for(i=0;i<LEN;i++) { |
70 |
data[i] = (data[i] + shift)/scale; |
102 |
data[i] = (data[i] - shift)/scale; |
71 |
} |
103 |
} |
72 |
|
104 |
|
73 |
for(i=0;i<LEN-1;i++) { |
105 |
for(i=0;i<LEN-1;i++) { |
74 |
painter.drawLine(PIXPT_X*i+LEFT,TOP+HEIGHT/2-PIXPT_Y*data[i],PIXPT_X*(i+1)+LEFT,TOP+HEIGHT/2-data[i+1]*PIXPT_Y); |
106 |
painter.drawLine(PIXPT_X*i+LEFT,TOP+HEIGHT/2-PIXPT_Y*data[i],PIXPT_X*(i+1)+LEFT,TOP+HEIGHT/2-data[i+1]*PIXPT_Y); |
75 |
} |
107 |
} |
76 |
cout << "Screen updated"<<endl; |
108 |
//cout << "Screen updated"<<endl; |
77 |
} |
109 |
} |
78 |
} |
110 |
} |
79 |
|
111 |
|
80 |
|
112 |
|
81 |
void Scope::getData() { |
113 |
void Scope::getData() { |
Line 85... |
Line 117... |
85 |
FILE *serial=fopen("/dev/ttyUSB0","r+"); |
117 |
FILE *serial=fopen("/dev/ttyUSB0","r+"); |
86 |
|
118 |
|
87 |
if (serial==NULL) { |
119 |
if (serial==NULL) { |
88 |
cout << "Serial port error."<<endl; |
120 |
cout << "Serial port error."<<endl; |
89 |
} else { |
121 |
} else { |
90 |
cout << "Serial port open."<<endl; |
122 |
//cout << "Serial port open."<<endl; |
- |
|
123 |
|
91 |
fwrite(&c,sizeof(char),1,serial); // poprosime o data |
124 |
fwrite(&c,sizeof(char),1,serial); // poprosime o data |
92 |
fread(buffer,sizeof(uint8_t),2*LEN,serial); // a berem je |
125 |
fread(buffer,sizeof(uint8_t),2*LEN,serial); // a berem je |
- |
|
126 |
|
93 |
cout << "Serial transfer completed."<<endl; |
127 |
// cout << "Serial transfer completed."<<endl; |
94 |
fclose(serial); |
128 |
fclose(serial); |
95 |
|
129 |
|
96 |
int i; |
130 |
int i; |
97 |
for(i=0;i<LEN;i++) { |
131 |
for(i=0;i<LEN;i++) { |
98 |
data[i]=buffer[2*i]*256+buffer[2*i+1]; |
132 |
data[i]=buffer[2*i]*256+buffer[2*i+1]; |
99 |
// cout << 1*data[i] <<endl; |
133 |
// cout << 1*data[i] <<endl; |
100 |
} |
134 |
} |
101 |
cout << "Screen updating...."<<endl; |
135 |
// cout << "Screen updating...."<<endl; |
- |
|
136 |
|
102 |
dataAquired=1; |
137 |
dataAquired=1; |
103 |
update(); |
138 |
update(); |
104 |
} |
139 |
} |
105 |
} |
140 |
} |
106 |
|
141 |
|
107 |
|
142 |
|
108 |
void Scope::setScale(int val) { |
143 |
void Scope::setScale(int val) { |
109 |
scale=val; |
144 |
scale=val; |
- |
|
145 |
UI(); |
110 |
} |
146 |
} |
111 |
|
147 |
|
112 |
void Scope::setShift(int val) { |
148 |
void Scope::setShift(int val) { |
113 |
shift=val; |
149 |
shift=val; |
- |
|
150 |
UI(); |
114 |
} |
151 |
} |