/Designs/Oscilloscope/DOC/stav.txt
1,9 → 1,10
Zatim je zprovezneno zakladni samplovani a binarni data transfer na strane atmegy a
prijem a zobrazeni dat na strane PC.
prijem a zobrazeni dat na strane PC. Ovladani uz skoro nejak vypada.
 
Dal:
Dat dohromady kod qscope, at se v tom da poradne vyznat.
Zakladni dokumentace. Nakreslit zapojeni modulu a analogove cesty.
Nastavitelny time base. Mereni time base pomoci timeru.
Musim vykrast trigger ze sveho starsiho projektu.
Nastavitelny time base. Mereni time base pomoci timeru.
Zpouzitelnit qscope.
Nakreslit zapojeni modulu a analogove cesty.
Oboustrana komunikace.
 
Zlepsit uroven kodu qscope....
/Designs/Oscilloscope/SW/PC_side/qscope/main.cpp
27,7 → 27,7
{
QApplication app(argc, argv);
Window window;
window.setGeometry(800, 200, 560, 690);
window.setGeometry(500, 200, 460, 760);
window.show();
return app.exec();
}
/Designs/Oscilloscope/SW/PC_side/qscope/moc_scope.cpp
1,7 → 1,7
/****************************************************************************
** Meta object code from reading C++ file 'scope.h'
**
** Created: Sun Aug 14 02:02:16 2011
** Created: Sun Aug 14 13:57:52 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.2)
**
** WARNING! All changes made in this file will be lost!
/Designs/Oscilloscope/SW/PC_side/qscope/qscope
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/Designs/Oscilloscope/SW/PC_side/qscope/scope.cpp
8,38 → 8,25
 
using namespace std;
 
#define TICK 150 // time in ms for one sampling (LEN values)
#define LEN 100 // number of sampled values
 
#define DEF_SCALE 256 //divisor
#define DEF_SHIFT 0
 
#define LEFT 10
#define TOP 10
#define PIXPT_X 4
#define PIXPT_Y 1
#define WIDTH (PIXPT_X*LEN)
#define HEIGHT (PIXPT_Y*512)
 
 
Scope::Scope(QWidget *parent) {
Scope::Scope(QWidget *parent) { // CONSTRUCTOR, graphic stuff
dataAquired=0;
 
data=new int[LEN*sizeof(int)]; ;
// data=new int[LEN*sizeof(int)]; ;
 
int i;
for(i=0;i<LEN;i++)
for(i=0;i<LEN;i++) // buffer init
data[i]=0;
 
scale=DEF_SCALE;
scale=DEF_SCALE; // default coords: data[i] = (data[i] + shift)/scale;
shift=DEF_SHIFT;
scaleSlider = new QSlider(Qt::Horizontal);
scaleSlider = new QSlider(Qt::Horizontal,this);
scaleSlider->setRange(1, 256);
scaleSlider->setValue(DEF_SCALE);
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int)));
shiftSlider = new QSlider(Qt::Horizontal);
shiftSlider = new QSlider(Qt::Horizontal,this);
shiftSlider->setRange(-60000, +60000);
shiftSlider->setValue(DEF_SHIFT);
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int)));
48,9 → 35,11
updateTimer->start(TICK);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData()));
scaleSlider->setGeometry(QRect(50,250,400,10));
QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )
scaleSlider->setGeometry(QRect(20,600,400,60));
scaleSlider->show();
shiftSlider->setGeometry(QRect(50,300,800,10));
shiftSlider->setGeometry(QRect(20,680,400,60));
shiftSlider->show();
 
// getData();
67,14 → 56,11
 
QPainter painter(this);
 
/* if (head>-1)
painter.drawText(10,20,QString::number(data[head]));*/
 
if (dataAquired) {
painter.drawLine(LEFT-1,TOP,LEFT-1,TOP+HEIGHT); //verticals
painter.drawLine(LEFT-1,TOP,LEFT-1,TOP+HEIGHT); //vertical bound box lines
painter.drawLine(LEFT+WIDTH+1,TOP,LEFT+WIDTH+1,TOP+HEIGHT);
 
painter.drawLine(LEFT-1,TOP,LEFT+WIDTH+1,TOP); //horizontals
painter.drawLine(LEFT-1,TOP,LEFT+WIDTH+1,TOP); //horizontals bound box lines
painter.drawLine(LEFT-1,TOP+HEIGHT,LEFT+WIDTH+1,TOP+HEIGHT);
painter.drawLine(LEFT-1,TOP+HEIGHT/2,LEFT+WIDTH+1,TOP+HEIGHT/2);
 
87,6 → 73,7
for(i=0;i<LEN-1;i++) {
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);
}
cout << "Screen updated"<<endl;
}
}
 
93,24 → 80,28
 
void Scope::getData() {
char c='m';
uint8_t buffer[2*LEN];
 
cout << "Serial transfer start."<<endl;
FILE *serial=fopen("/dev/ttyUSB0","r+");
fwrite(&c,sizeof(char),1,serial); // poprosime o data
fread(buffer,sizeof(uint8_t),2*LEN,serial); // a berem je
 
int i;
for(i=0;i<LEN;i++) {
data[i]=buffer[2*i]*256+buffer[2*i+1];
cout << 1*data[i] <<endl;
if (serial==NULL) {
cout << "Serial port error."<<endl;
} else {
cout << "Serial port open."<<endl;
fwrite(&c,sizeof(char),1,serial); // poprosime o data
fread(buffer,sizeof(uint8_t),2*LEN,serial); // a berem je
cout << "Serial transfer completed."<<endl;
fclose(serial);
int i;
for(i=0;i<LEN;i++) {
data[i]=buffer[2*i]*256+buffer[2*i+1];
// cout << 1*data[i] <<endl;
}
cout << "Screen updating...."<<endl;
dataAquired=1;
update();
}
dataAquired=1;
// head=LEN-1;
 
 
update();
// cout << "Screen updated."<<endl;
}
 
 
121,6 → 112,3
void Scope::setShift(int val) {
shift=val;
}
 
 
 
/Designs/Oscilloscope/SW/PC_side/qscope/scope.h
6,6 → 6,19
#include <QSlider>
#include <stdint.h>
 
#define TICK 150 // time in ms for one sampling (of LEN values)
#define LEN 100 // number of sampled values
 
#define DEF_SCALE 256 //divisor
#define DEF_SHIFT 0
 
#define LEFT 10
#define TOP 10
#define PIXPT_X 4
#define PIXPT_Y 1
#define WIDTH (PIXPT_X*LEN)
#define HEIGHT (PIXPT_Y*512)
 
class Scope : public QWidget
{
Q_OBJECT
23,9 → 36,9
void paintEvent(QPaintEvent *event);
 
private:
int * data;
uint8_t buffer[2*LEN];
int data[LEN];
char dataAquired;
int head;
long shift, scale;