gnuplot,顾名思义就是一个画平面图的软件,当然立体图也是可以画的。在Linux下,这是一个相当容易上手的画轨迹的软件。
之前做Touchscreen的时候,手指抬起来的时候坐标有时会乱飞,一直不知道为什么,我就想到用这个软件来把轨迹图画出来。
最终结果如下:
蓝色,紫色,红色的三段是实际的轨迹,但是绿色就是错误的坐标了,不知道是采样还是驱动的问题,总之错误的坐标是发上来了。
画图的脚本如下:
- #!/usr/bin/gnuplot
-
set autoscale # scale axes automatically
-
unset log # remove any log-scaling
-
unset label # remove any previous labels
-
set xtic auto # set xtics automatically
-
set ytic auto # set ytics automatically
-
set title "jitter"
-
set xlabel "x axis"
-
set ylabel "y axis"
-
set yrange [] reverse
-
plot "log1" using ($1):($2) title 'log1' with linespoints ,"log2" using 1:2 title 'log2' with linespoints ,"log3" using 1:2 title 'log3' with linespoints ,"log4" using 1:2 title 'log4' with linespoints
-
#where <style> is either `lines`, `points`, `linespoints`, `impulses`, `dots`, `steps`, `fsteps`, `histeps`, `errorbars`, `labels`, `xerrorbars`, `yerrorbars`, `xyerrorbars`, `errorlines`, `xerrorlines`, `yerrorlines`, `xyerrorlines`, `boxes`, `histograms`, `filledcurves`, `boxerrorbars`, `boxxyerrorbars`, `financebars`, `candlesticks`, `vectors`, `image`, `rgbimage` or `pm3d`.
log1:
- 2707 3332
-
2732 3429
-
2754 3542
-
2779 3652
-
2803 3764
-
2824 3877
-
2841 3963
-
2852 4029
-
2863 4076
-
2866 4118
-
2867 4128
-
2867 4132
-
2866 4146
-
2866 4142
-
2869 4139
-
2868 4137
-
2871 4124
-
2872 4121
-
2870 4122
-
2869 4115
-
2869 4119
-
2868 4113
-
2869 4111
-
2869 4115
-
2866 4110
-
2867 4096
-
2889 4423
log2:
- 2889 4423
-
1351 4708
-
1364 1205
-
1352 1205
log3:
- 1352 1205
-
1404 1205
-
1352 1221
-
1404 1221
-
1350 1222
-
1350 1506
-
1350 1222
-
1364 1221
-
1352 1221
-
1350 1506
-
1350 1650
-
1352 1505
-
1350 1506
-
1352 1505
-
1350 1206
-
1352 1505
-
1351 1340
log4:
- 1351 1340
-
1351 2084
-
1350 1506
-
1352 1649
-
1351 1696
-
1351 2084
-
1352 1649
-
1351 1696
-
1351 1792
-
1351 2084
-
1351 1792
-
1351 2084
-
1351 1792
-
1350 1718
-
1351 1792
-
1350 1938
-
1350 2086
-
1351 1792
-
1350 1938
-
1351 1792
-
1351 2084
-
1351 1792
-
1351 2084
-
1350 1650
-
1351 2084
-
1350 1650
以上这些轨迹点都是从input event得到的,
首先是dump出input event,
# cat /dev/touchscreen > file
然后是用自己写的程序转化成坐标点。
# event_analyzer file
代码
event_analyzer.c
- #include <stdio.h>
-
#include <stdlib.h>
-
#include <strings.h>
-
#include <string.h>
-
#include <sys/types.h>
-
#include <sys/stat.h>
-
#include <fcntl.h>
-
#include <unistd.h>
-
#include <errno.h>
-
#include <linux/input.h>
-
-
//typedef __signed__ short __s16;
-
//typedef unsigned short __u16;
-
//
-
//typedef __signed__ int __s32;
-
//typedef unsigned int __u32;
-
//
-
//typedef long __kernel_time_t;
-
//typedef long __kernel_suseconds_t;
-
//
-
//struct timeval {
-
// __kernel_time_t tv_sec; /* seconds */
-
// __kernel_suseconds_t tv_usec; /* microseconds */
-
//};
-
//
-
//struct input_event {
-
// struct timeval time;
-
// __u16 type;
-
// __u16 code;
-
// __s32 value;
-
//};
-
-
char updown[2][10]={"up","down"};
-
char keyname[5][10]={"left","middle","right","finger","touch"};
-
-
int main( int argc, char **argv )
-
{
-
int i,fd,fd_out,readin;
-
FILE *stream;
-
int x,y,unknown;
-
char name[256],name_out[256];
-
int key[5]={};
-
struct input_event buf;
-
bzero(&buf,sizeof(buf));
-
for (i=1 ; i<argc ; i++) {
-
strcpy(name,argv[i]);
-
strcpy(name_out,name);
-
strcat(name_out,"_out");
-
//puts(name_out);
-
if((fd = open(name,O_RDONLY)) == -1) {
-
perror(name);
-
continue;
-
}
-
else {
-
printf("------------------------------------------------------------\n%s:\n",name);
-
x=0;
-
y=0;
-
unknown=0;
-
bzero(&buf,sizeof(buf));
-
bzero(&key,sizeof(key));
-
-
stream = fopen( name_out , "w+");
-
if (stream == NULL) {
-
perror(name_out);
-
// continue;
-
}
-
-
while((readin = read(fd,&buf,sizeof(buf))) == sizeof(buf)) {
-
//printf("%u-%u-%hu-%hu-%d\n",buf.time.tv_sec,buf.time.tv_usec,buf.type,buf.code,buf.value);
-
if (buf.type == EV_ABS) {
-
if (buf.code == ABS_X) {
-
x = buf.value ;
-
} else if (buf.code == ABS_Y) {
-
y = buf.value ;
-
} else {
-
unknown |= 1;
-
}
-
} else if (buf.type == EV_REL) {
-
unknown |= 2;
-
} else if (buf.type == EV_KEY) {
-
switch (buf.code) {
-
case BTN_LEFT: key[0] |= 2 | buf.value; break;
-
case BTN_MIDDLE: key[1] |= 2 | buf.value; break;
-
case BTN_RIGHT: key[2] |= 2 | buf.value; break;
-
case BTN_TOOL_FINGER: key[3] |= 2 | buf.value; break;
-
case BTN_TOUCH: key[4] |= 2 | buf.value; break;
-
default: unknown |= 4; break;
-
}
-
} else if (buf.type == EV_SYN && buf.code == SYN_REPORT) {
-
// if ( !x || !y ) {
-
// continue;
-
// }
-
char tmp[256]={};
-
char tmp2[256]={};
-
snprintf(tmp,256,"%d\t%d\t",x,y);
-
int i;
-
for (i=0 ; i<5 ; i++) {
-
if ( key[i] & 0x02 ) {
-
snprintf(tmp2,256,"%s <%s %s>",tmp,keyname[i],updown[key[i] & 0x01]);
-
strcpy(tmp,tmp2);
-
}
-
}
-
// if ( unknown )
-
// snprintf(tmp,256,"%s ",tmp,unknown);
-
printf("%s\n",tmp);
-
fprintf(stream,"%s\n",tmp);
-
// x=0;
-
// y=0;
-
unknown=0;
-
bzero(&buf,sizeof(buf));
-
bzero(&key,sizeof(key));
-
} else {
-
unknown |= 8;
-
}
-
}
-
if (readin > 0) {
-
fprintf(stdout,"readin = %d\n",readin);
-
}
-
}
-
close(fd);
-
fclose(stream);
-
}
-
-
return 0;
-
}
阅读(1356) | 评论(0) | 转发(0) |