| 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 |
#define TICK 150 // time in ms for one sampling (LEN values) |
| 11 |
#define LEN 100 |
12 |
#define LEN 100 // number of sampled values |
| - |
|
13 |
|
| 12 |
#define DEF_SCALE 1 |
14 |
#define DEF_SCALE 256 //divisor |
| 13 |
#define DEF_SHIFT 0 |
15 |
#define DEF_SHIFT 0 |
| 14 |
|
16 |
|
| 15 |
#define LEFT 10 |
17 |
#define LEFT 10 |
| 16 |
#define WIDTH 512 |
18 |
#define TOP 10 |
| - |
|
19 |
#define PIXPT_X 4 |
| 17 |
#define HEIGHT 600 |
20 |
#define PIXPT_Y 1 |
| - |
|
21 |
#define WIDTH (PIXPT_X*LEN) |
| - |
|
22 |
#define HEIGHT (PIXPT_Y*512) |
| 18 |
|
23 |
|
| 19 |
#define PIXPT 2 |
- |
|
| 20 |
|
24 |
|
| 21 |
Scope::Scope(QWidget *parent) { |
25 |
Scope::Scope(QWidget *parent) { |
| 22 |
dataAquired=0; |
26 |
dataAquired=0; |
| 23 |
head=-1; |
- |
|
| 24 |
|
27 |
|
| 25 |
data=new int[LEN*sizeof(int)]; ; |
28 |
data=new int[LEN*sizeof(int)]; ; |
| 26 |
|
29 |
|
| 27 |
int i; |
30 |
int i; |
| 28 |
for(i=1;i<LEN;i++) |
31 |
for(i=0;i<LEN;i++) |
| 29 |
data[i]=0; |
32 |
data[i]=0; |
| 30 |
|
33 |
|
| 31 |
scale=DEF_SCALE; |
34 |
scale=DEF_SCALE; |
| 32 |
shift=DEF_SHIFT; |
35 |
shift=DEF_SHIFT; |
| 33 |
|
36 |
|
| 34 |
scaleSlider = new QSlider(Qt::Horizontal); |
37 |
scaleSlider = new QSlider(Qt::Horizontal); |
| 35 |
scaleSlider->setRange(1, 128); |
38 |
scaleSlider->setRange(1, 256); |
| 36 |
scaleSlider->setValue(DEF_SCALE); |
39 |
scaleSlider->setValue(DEF_SCALE); |
| 37 |
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int))); |
40 |
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int))); |
| 38 |
|
41 |
|
| 39 |
shiftSlider = new QSlider(Qt::Horizontal); |
42 |
shiftSlider = new QSlider(Qt::Horizontal); |
| 40 |
shiftSlider->setRange(-60000, +60000); |
43 |
shiftSlider->setRange(-60000, +60000); |
| 41 |
shiftSlider->setValue(DEF_SHIFT); |
44 |
shiftSlider->setValue(DEF_SHIFT); |
| 42 |
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int))); |
45 |
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int))); |
| 43 |
|
46 |
|
| 44 |
updateTimer = new QTimer(this); |
47 |
updateTimer = new QTimer(this); |
| 45 |
updateTimer->start(150); |
48 |
updateTimer->start(TICK); |
| 46 |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
49 |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
| 47 |
|
50 |
|
| 48 |
scaleSlider->setGeometry(QRect(50,250,400,10)); |
51 |
scaleSlider->setGeometry(QRect(50,250,400,10)); |
| 49 |
scaleSlider->show(); |
52 |
scaleSlider->show(); |
| 50 |
shiftSlider->setGeometry(QRect(50,300,800,10)); |
53 |
shiftSlider->setGeometry(QRect(50,300,800,10)); |
| Line 62... |
Line 65... |
| 62 |
|
65 |
|
| 63 |
void Scope::paintEvent(QPaintEvent* event) { |
66 |
void Scope::paintEvent(QPaintEvent* event) { |
| 64 |
|
67 |
|
| 65 |
QPainter painter(this); |
68 |
QPainter painter(this); |
| 66 |
|
69 |
|
| 67 |
if (head>-1) |
70 |
/* if (head>-1) |
| 68 |
painter.drawText(10,20,QString::number(data[head])); |
71 |
painter.drawText(10,20,QString::number(data[head]));*/ |
| 69 |
|
72 |
|
| 70 |
if (dataAquired) { |
73 |
if (dataAquired) { |
| 71 |
painter.drawLine(LEFT-1,45,LEFT-1,HEIGHT); |
74 |
painter.drawLine(LEFT-1,TOP,LEFT-1,TOP+HEIGHT); //verticals |
| 72 |
painter.drawLine(LEFT+WIDTH,45,LEFT+WIDTH,HEIGHT); |
75 |
painter.drawLine(LEFT+WIDTH+1,TOP,LEFT+WIDTH+1,TOP+HEIGHT); |
| 73 |
painter.drawLine(LEFT-1,45,LEFT+WIDTH,45); |
- |
|
| 74 |
painter.drawLine(LEFT-1,HEIGHT,LEFT+WIDTH,HEIGHT); |
- |
|
| 75 |
|
76 |
|
| - |
|
77 |
painter.drawLine(LEFT-1,TOP,LEFT+WIDTH+1,TOP); //horizontals |
| - |
|
78 |
painter.drawLine(LEFT-1,TOP+HEIGHT,LEFT+WIDTH+1,TOP+HEIGHT); |
| 76 |
// painter.drawLine(LEFT-1,HEIGHT/2,LEFT+WIDTH,HEIGHT/2); |
79 |
painter.drawLine(LEFT-1,TOP+HEIGHT/2,LEFT+WIDTH+1,TOP+HEIGHT/2); |
| 77 |
|
80 |
|
| 78 |
int i; |
81 |
int i; |
| 79 |
|
82 |
|
| 80 |
|
- |
|
| 81 |
/* for(i=head+1;i<LEN-1;i++) |
- |
|
| 82 |
painter.drawLine(PIXPT*(i-head)+LEFT,HEIGHT-data[i],PIXPT*(i-head+1)+LEFT,HEIGHT-data[i+1]); |
- |
|
| 83 |
painter.drawLine(PIXPT*(LEN-head-1)+LEFT,HEIGHT-data[LEN-1],PIXPT*(LEN-head+1)+LEFT,HEIGHT-data[0]); |
- |
|
| 84 |
for(i=0;i<head;i++) |
- |
|
| 85 |
painter.drawLine(PIXPT*(i+LEN-head)+LEFT,HEIGHT-data[i],PIXPT*(i+LEN-head+1)+10,HEIGHT-data[i+1]);*/ |
- |
|
| 86 |
|
- |
|
| 87 |
for(i=0;i<LEN;i++) { |
83 |
for(i=0;i<LEN;i++) { |
| 88 |
data[i] = (data[i] + shift)/scale; |
84 |
data[i] = (data[i] + shift)/scale; |
| 89 |
// data[i] = data[i] + HEIGHT/2; |
- |
|
| 90 |
} |
85 |
} |
| 91 |
|
86 |
|
| 92 |
for(i=0;i<LEN-1;i++) { |
87 |
for(i=0;i<LEN-1;i++) { |
| 93 |
painter.drawLine(PIXPT*i+LEFT,HEIGHT-data[i],PIXPT*(i+1)+10,HEIGHT-data[i+1]); |
88 |
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); |
| 94 |
} |
89 |
} |
| 95 |
} |
90 |
} |
| 96 |
} |
91 |
} |
| 97 |
|
92 |
|
| - |
|
93 |
|
| 98 |
void Scope::getData() { |
94 |
void Scope::getData() { |
| 99 |
char c='m'; |
95 |
char c='m'; |
| 100 |
uint8_t buffer[2*LEN]; |
96 |
uint8_t buffer[2*LEN]; |
| 101 |
|
97 |
|
| 102 |
|
98 |
|