Guest User

Untitled

a guest
Oct 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. int g_fdTouchScreen;
  2. const char *g_pDevice = "/dev/input/event0"; // Find proper the event number with the evtest command from terminal
  3. struct input_event g_ieTouchScreen;
  4.  
  5. int g_iTouchX = 0;
  6. int g_iTouchY = 0;
  7. int g_iTouchPressure = 0;
  8.  
  9. /******************************************************************************
  10. * InitDisplay - Initialize the dislay and touch screen
  11. ******************************************************************************/
  12. void InitDisplay(void)
  13. {
  14. if((g_fdTouchScreen = open(g_pDevice, O_RDWR | O_NONBLOCK)) == -1) {
  15. perror("Error opening Touch Screen");
  16. exit(EXIT_FAILURE);
  17. }
  18. }
  19.  
  20. // Looks like the OS gets the event first?
  21. // Try to write nothing to the file so it doesnt get used by the OS
  22. g_ieTouchScreen.type = 0;
  23. g_ieTouchScreen.code = 0;
  24. g_ieTouchScreen.value = 0;
  25. lseek(g_fdTouchScreen, SEEK_CUR, -sizeof(struct input_event));
  26. write(g_fdTouchScreen, &g_ieTouchScreen, sizeof(struct input_event));
  27.  
  28. //printf("time %ld.%06ldttype %dtcode %dtvalue %dn", ieTouchScreen.time.tv_sec, ieTouccreen.time.tv_usec, ieTouchScreen.type, ieTouchScreen.code, ieTouchScreen.value);
  29. if (g_ieTouchScreen.type == EV_ABS)
  30. {
  31. if (g_ieTouchScreen.code == ABS_X)
  32. {
  33. g_iTouchX = (int)((g_ieTouchScreen.value - 150.0f) / 4.7f);
  34. //printf("Absolute X: %dn", g_iTouchX); // X left 150 right 4000 - real divisor should be 4.8125 but this gives closer pixel values
  35. }
  36. else if (g_ieTouchScreen.code == ABS_Y)
  37. {
  38. g_iTouchY = (int)((g_ieTouchScreen.value - 300.0f) / 7.18f);
  39. //printf("Absolute Y: %dn", g_iTouchY); // Y top 300 bottom 3750 = 7.1875
  40. }
  41. else if (g_ieTouchScreen.code == ABS_PRESSURE)
  42. {
  43. if (g_ieTouchScreen.value >= 59000)
  44. g_iTouchPressure = (g_ieTouchScreen.value - 59000) / 50;
  45. //printf("Pressure: %dn", g_iTouchPressure);
  46. }
  47. else
  48. printf("Code: %02Xn", g_ieTouchScreen.code);
  49. }
  50. return (1);
  51. }
  52.  
  53. // Try to write nothing to the file so it doesn't get used by the OS
  54. g_ieTouchScreen.type = 0;
  55. g_ieTouchScreen.code = 0;
  56. g_ieTouchScreen.value = 0;
  57. lseek(g_fdTouchScreen, SEEK_CUR, -sizeof(struct input_event));
  58. write(g_fdTouchScreen, &g_ieTouchScreen, sizeof(struct input_event));
Add Comment
Please, Sign In to add comment