You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.3 KiB

  1. /* Through this source code, you could see the point output architechture of touch device.
  2. You could follow below code to do point parsing. And develop your own app. */
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <fcntl.h>
  8. #include <limits.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <linux/input.h>
  12. /*Note: If you couldn't build this source code successfully, it may caused by the old kernel issue.
  13. Please enable below define depending on your kernel version */
  14. //#define KERNEL_2_6_35_DOWNWARD /* As kernel <= 2.6.35 */
  15. //#define KERNEL_2_6_32_DOWNWARD /* As kernel <= 2.6.32 */
  16. //#define KERNEL_2_6_29_DOWNWARD /* As kernel <= 2.6.29 */
  17. typedef struct tagevent
  18. {
  19. struct timeval time;
  20. unsigned short type;
  21. unsigned short code;
  22. int value;
  23. } input_event;
  24. void ParseEvent( input_event ev )
  25. {
  26. static unsigned short X, Y, State;
  27. static unsigned short X2, Y2, State2;
  28. static unsigned char bIsSecond;
  29. if( ev.type == EV_ABS ) {
  30. switch( ev.code ) {
  31. #ifndef KERNEL_2_6_35_DOWNWARD
  32. case ABS_MT_SLOT:
  33. printf(" [ABS_MT_SLOT] code = %3d, value = %4d\n", ev.code , ev.value);
  34. break;
  35. #endif
  36. #ifndef KERNEL_2_6_32_DOWNWARD
  37. case ABS_MT_PRESSURE:
  38. printf(" [ABS_MT_PRESSURE] code = %3d, value = %4d\n", ev.code , ev.value);
  39. break;
  40. #endif
  41. #ifndef KERNEL_2_6_29_DOWNWARD
  42. case ABS_MT_TRACKING_ID:
  43. printf(" [ABS_MT_TRACKING_ID] code = %3d, value = %4d\n", ev.code , ev.value);
  44. break;
  45. case ABS_MT_POSITION_X:
  46. printf(" [ABS_MT_POSITION_X] code = %3d, value = %4d\n", ev.code , ev.value);
  47. break;
  48. case ABS_MT_POSITION_Y:
  49. printf(" [ABS_MT_POSITION_Y] code = %3d, value = %4d\n", ev.code , ev.value);
  50. break;
  51. case ABS_MT_TOUCH_MAJOR:
  52. printf(" [ABS_MT_TOUCH_MAJOR] code = %3d, value = %4d\n", ev.code , ev.value);
  53. break;
  54. case ABS_MT_WIDTH_MAJOR:
  55. printf(" [ABS_MT_WIDTH_MAJOR] code = %3d, value = %4d\n", ev.code , ev.value);
  56. break;
  57. #endif
  58. case ABS_X:
  59. printf(" [ABS_X] code = %3d, value = %4d\n", ev.code , ev.value);
  60. break;
  61. case ABS_Y:
  62. printf(" [ABS_Y] code = %3d, value = %4d\n", ev.code , ev.value);
  63. break;
  64. case ABS_RX:
  65. printf(" [ABS_RX] code = %3d, value = %4d\n", ev.code , ev.value);
  66. break;
  67. case ABS_RY:
  68. printf(" [ABS_RY] code = %3d, value = %4d\n", ev.code , ev.value);
  69. break;
  70. case ABS_PRESSURE:
  71. printf(" [ABS_PRESSURE] code = %3d, value = %4d\n", ev.code , ev.value);
  72. break;
  73. default:
  74. break;
  75. }
  76. }
  77. else if( ev.type == EV_KEY ){
  78. switch( ev.code ){
  79. case BTN_TOUCH:
  80. printf(" [BTN_TOUCH] code = %3d, value = %4d\n", ev.code , ev.value);
  81. break;
  82. case BTN_LEFT:
  83. printf(" [BTN_LEFT] code = %3d, value = %4d\n", ev.code , ev.value);
  84. break;
  85. case BTN_EXTRA:
  86. printf(" [BTN_EXTRA] code = %3d, value = %4d\n", ev.code , ev.value);
  87. break;
  88. default:
  89. break;
  90. }
  91. }
  92. else if( ev.type == EV_SYN ){
  93. switch( ev.code ){
  94. case SYN_REPORT:
  95. printf(" [SYN_REPORT] code = %3d, value = %4d\n\n", ev.code , ev.value);
  96. break;
  97. #ifndef KERNEL_2_6_29_DOWNWARD
  98. case SYN_MT_REPORT:
  99. printf(" [SYN_MT_REPORT] code = %3d, value = %4d\n", ev.code , ev.value);
  100. break;
  101. #endif
  102. default:
  103. break;
  104. }
  105. }
  106. else if( ev.type == EV_MSC ){
  107. if( ev.code == MSC_SCAN )
  108. printf(" [MSC_SCAN] code = %3d, value = %4d\n", ev.code , ev.value);
  109. }
  110. }
  111. int main( int argc, char **argv )
  112. {
  113. int fd;
  114. unsigned char byFlag = 0; /* 0: Point */
  115. char strPort[64] = { 0 };
  116. fd_set readfds;
  117. if( argc == 1 || argc > 2 ) {
  118. printf(" \nUsage:\n \tGetEvent [Port]\n");
  119. printf("Example:\n \tGetEvent /dev/input/event1\n\n");
  120. return 0;
  121. }
  122. sprintf( strPort, "%s", argv[1] );
  123. printf("Event Port = %s ", strPort);
  124. fd = open(strPort, O_RDONLY );
  125. if( fd >= 0 ) {
  126. printf(" open: ok\n" );
  127. FD_ZERO( &readfds );
  128. FD_SET( fd , &readfds );
  129. while( 1 ) {
  130. if( select( fd+1, &readfds, NULL, NULL, NULL ) > 0 ) {
  131. input_event ev;
  132. if( sizeof( input_event ) == read( fd, &ev, sizeof( input_event ) ) ) {
  133. ParseEvent( ev );
  134. } else {
  135. printf(" Nothing read \n" );
  136. }
  137. }
  138. }
  139. }
  140. return 0;
  141. }