Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86045
  • 博文数量: 10
  • 博客积分: 283
  • 博客等级: 二等列兵
  • 技术积分: 149
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-24 15:07
文章分类

全部博文(10)

文章存档

2011年(10)

我的朋友

分类: LINUX

2011-12-28 11:05:42

gnuplot,顾名思义就是一个画平面图的软件,当然立体图也是可以画的。在Linux下,这是一个相当容易上手的画轨迹的软件。
之前做Touchscreen的时候,手指抬起来的时候坐标有时会乱飞,一直不知道为什么,我就想到用这个软件来把轨迹图画出来。

最终结果如下:
蓝色,紫色,红色的三段是实际的轨迹,但是绿色就是错误的坐标了,不知道是采样还是驱动的问题,总之错误的坐标是发上来了。

画图的脚本如下:
  1. #!/usr/bin/gnuplot
  2. set autoscale # scale axes automatically
  3. unset log # remove any log-scaling
  4. unset label # remove any previous labels
  5. set xtic auto # set xtics automatically
  6. set ytic auto # set ytics automatically
  7. set title "jitter"
  8. set xlabel "x axis"
  9. set ylabel "y axis"
  10. set yrange [] reverse
  11. 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
  12. #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:
  1. 2707 3332
  2. 2732 3429
  3. 2754 3542
  4. 2779 3652
  5. 2803 3764
  6. 2824 3877
  7. 2841 3963
  8. 2852 4029
  9. 2863 4076
  10. 2866 4118
  11. 2867 4128
  12. 2867 4132
  13. 2866 4146
  14. 2866 4142
  15. 2869 4139
  16. 2868 4137
  17. 2871 4124
  18. 2872 4121
  19. 2870 4122
  20. 2869 4115
  21. 2869 4119
  22. 2868 4113
  23. 2869 4111
  24. 2869 4115
  25. 2866 4110
  26. 2867 4096
  27. 2889 4423

log2:
  1. 2889 4423
  2. 1351 4708
  3. 1364 1205
  4. 1352 1205

log3:
  1. 1352 1205
  2. 1404 1205
  3. 1352 1221
  4. 1404 1221
  5. 1350 1222
  6. 1350 1506
  7. 1350 1222
  8. 1364 1221
  9. 1352 1221
  10. 1350 1506
  11. 1350 1650
  12. 1352 1505
  13. 1350 1506
  14. 1352 1505
  15. 1350 1206
  16. 1352 1505
  17. 1351 1340

log4:
  1. 1351 1340
  2. 1351 2084
  3. 1350 1506
  4. 1352 1649
  5. 1351 1696
  6. 1351 2084
  7. 1352 1649
  8. 1351 1696
  9. 1351 1792
  10. 1351 2084
  11. 1351 1792
  12. 1351 2084
  13. 1351 1792
  14. 1350 1718
  15. 1351 1792
  16. 1350 1938
  17. 1350 2086
  18. 1351 1792
  19. 1350 1938
  20. 1351 1792
  21. 1351 2084
  22. 1351 1792
  23. 1351 2084
  24. 1350 1650
  25. 1351 2084
  26. 1350 1650

以上这些轨迹点都是从input event得到的,
首先是dump出input event,
# cat /dev/touchscreen > file
然后是用自己写的程序转化成坐标点。
# event_analyzer file

代码
event_analyzer.c
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <strings.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <errno.h>
  10. #include <linux/input.h>

  11. //typedef __signed__ short __s16;
  12. //typedef unsigned short __u16;
  13. //
  14. //typedef __signed__ int __s32;
  15. //typedef unsigned int __u32;
  16. //
  17. //typedef long        __kernel_time_t;
  18. //typedef long        __kernel_suseconds_t;
  19. //
  20. //struct timeval {
  21. //    __kernel_time_t        tv_sec;        /* seconds */
  22. //    __kernel_suseconds_t    tv_usec;    /* microseconds */
  23. //};
  24. //
  25. //struct input_event {
  26. //    struct timeval time;
  27. //    __u16 type;
  28. //    __u16 code;
  29. //    __s32 value;
  30. //};

  31. char updown[2][10]={"up","down"};
  32. char keyname[5][10]={"left","middle","right","finger","touch"};

  33. int main( int argc, char **argv )
  34. {
  35.     int i,fd,fd_out,readin;
  36.     FILE *stream;
  37.     int x,y,unknown;
  38.     char name[256],name_out[256];
  39.     int key[5]={};
  40.     struct input_event buf;
  41.     bzero(&buf,sizeof(buf));
  42.     for (i=1 ; i<argc ; i++) {
  43.         strcpy(name,argv[i]);
  44.         strcpy(name_out,name);
  45.         strcat(name_out,"_out");
  46.         //puts(name_out);
  47.         if((fd = open(name,O_RDONLY)) == -1) {
  48.             perror(name);
  49.             continue;
  50.         }
  51.         else {
  52.             printf("------------------------------------------------------------\n%s:\n",name);
  53.             x=0;
  54.             y=0;
  55.             unknown=0;
  56.             bzero(&buf,sizeof(buf));
  57.             bzero(&key,sizeof(key));

  58.             stream = fopen( name_out , "w+");
  59.             if (stream == NULL) {
  60.                 perror(name_out);
  61. //                continue;
  62.             }

  63.             while((readin = read(fd,&buf,sizeof(buf))) == sizeof(buf)) {
  64.                 //printf("%u-%u-%hu-%hu-%d\n",buf.time.tv_sec,buf.time.tv_usec,buf.type,buf.code,buf.value);
  65.                 if (buf.type == EV_ABS) {
  66.                     if (buf.code == ABS_X) {
  67.                     x = buf.value ;
  68.                     } else if (buf.code == ABS_Y) {
  69.                     y = buf.value ;
  70.                     } else {
  71.                         unknown |= 1;
  72.                     }
  73.                 } else if (buf.type == EV_REL) {
  74.                         unknown |= 2;
  75.                 } else if (buf.type == EV_KEY) {
  76.                     switch (buf.code) {
  77.                     case BTN_LEFT: key[0] |= 2 | buf.value; break;
  78.                     case BTN_MIDDLE: key[1] |= 2 | buf.value; break;
  79.                     case BTN_RIGHT: key[2] |= 2 | buf.value; break;
  80.                     case BTN_TOOL_FINGER: key[3] |= 2 | buf.value; break;
  81.                     case BTN_TOUCH: key[4] |= 2 | buf.value; break;
  82.                     default: unknown |= 4; break;
  83.                     }
  84.                 } else if (buf.type == EV_SYN && buf.code == SYN_REPORT) {
  85. //                    if ( !x || !y ) {
  86. //                     continue;
  87. //                    }
  88.                     char tmp[256]={};
  89.                     char tmp2[256]={};
  90.                     snprintf(tmp,256,"%d\t%d\t",x,y);
  91.                     int i;
  92.                     for (i=0 ; i<5 ; i++) {
  93.                         if ( key[i] & 0x02 ) {
  94.                          snprintf(tmp2,256,"%s <%s %s>",tmp,keyname[i],updown[key[i] & 0x01]);
  95.                          strcpy(tmp,tmp2);
  96.                         }
  97.                     }
  98. //                    if ( unknown )
  99. //                     snprintf(tmp,256,"%s ",tmp,unknown);
  100.                     printf("%s\n",tmp);
  101.                     fprintf(stream,"%s\n",tmp);
  102. //                    x=0;
  103. //                    y=0;
  104.                     unknown=0;
  105.                     bzero(&buf,sizeof(buf));
  106.                     bzero(&key,sizeof(key));
  107.                 } else {
  108.                     unknown |= 8;
  109.                 }
  110.             }
  111.             if (readin > 0) {
  112.                 fprintf(stdout,"readin = %d\n",readin);
  113.             }
  114.         }
  115.         close(fd);
  116.         fclose(stream);
  117.     }

  118.     return 0;
  119. }

阅读(1356) | 评论(0) | 转发(0) |
0

上一篇:tsung: 服务器压力测试软件

下一篇:没有了

给主人留下些什么吧!~~