2116 |
paro |
1 |
#include "scope.h" |
|
|
2 |
|
|
|
3 |
#include <QPainter> |
|
|
4 |
#include <iostream> |
|
|
5 |
#include <stdio.h> |
|
|
6 |
|
|
|
7 |
using namespace std; |
|
|
8 |
|
|
|
9 |
#define LEN 128 |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
Scope::Scope(QWidget *parent) { |
|
|
13 |
dataAquired=0; |
|
|
14 |
|
|
|
15 |
updateTimer = new QTimer(this); |
|
|
16 |
updateTimer->start(250); |
|
|
17 |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
|
|
18 |
} |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
Scope::~Scope() { |
|
|
22 |
delete [] data; |
|
|
23 |
} |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
void Scope::paintEvent(QPaintEvent* event) { |
|
|
27 |
if (dataAquired) { |
|
|
28 |
QPainter painter(this); |
|
|
29 |
|
|
|
30 |
painter.drawLine(9,45,9,300); |
|
|
31 |
painter.drawLine(522,45,522,300); |
|
|
32 |
painter.drawLine(9,45,522,45); |
|
|
33 |
painter.drawLine(9,300,522,300); |
|
|
34 |
int i; |
|
|
35 |
for(i=0;i<LEN-1;i++) { |
|
|
36 |
painter.drawLine(4*i+10,300-(unsigned char)data[i],4*i+4+10,300-(unsigned char)data[i+1]); |
|
|
37 |
} |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
void Scope::getData() { |
|
|
42 |
char c='a'; |
|
|
43 |
data=new char[LEN*sizeof(char)]; |
|
|
44 |
|
|
|
45 |
FILE *serial=fopen("/dev/ttyUSB0","r+"); |
|
|
46 |
fwrite(&c,sizeof(char),1,serial); // ask for data |
|
|
47 |
fread(data,sizeof(char),LEN,serial); // and take them |
|
|
48 |
fclose(serial); |
|
|
49 |
|
|
|
50 |
dataAquired=1; |
|
|
51 |
update(); |
|
|
52 |
} |
|
|
53 |
|