Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int g_fdTouchScreen;
- const char *g_pDevice = "/dev/input/event0"; // Find proper the event number with the evtest command from terminal
- struct input_event g_ieTouchScreen;
- int g_iTouchX = 0;
- int g_iTouchY = 0;
- int g_iTouchPressure = 0;
- /******************************************************************************
- * InitDisplay - Initialize the dislay and touch screen
- ******************************************************************************/
- void InitDisplay(void)
- {
- if((g_fdTouchScreen = open(g_pDevice, O_RDWR | O_NONBLOCK)) == -1) {
- perror("Error opening Touch Screen");
- exit(EXIT_FAILURE);
- }
- }
- // Looks like the OS gets the event first?
- // Try to write nothing to the file so it doesnt get used by the OS
- g_ieTouchScreen.type = 0;
- g_ieTouchScreen.code = 0;
- g_ieTouchScreen.value = 0;
- lseek(g_fdTouchScreen, SEEK_CUR, -sizeof(struct input_event));
- write(g_fdTouchScreen, &g_ieTouchScreen, sizeof(struct input_event));
- //printf("time %ld.%06ldttype %dtcode %dtvalue %dn", ieTouchScreen.time.tv_sec, ieTouccreen.time.tv_usec, ieTouchScreen.type, ieTouchScreen.code, ieTouchScreen.value);
- if (g_ieTouchScreen.type == EV_ABS)
- {
- if (g_ieTouchScreen.code == ABS_X)
- {
- g_iTouchX = (int)((g_ieTouchScreen.value - 150.0f) / 4.7f);
- //printf("Absolute X: %dn", g_iTouchX); // X left 150 right 4000 - real divisor should be 4.8125 but this gives closer pixel values
- }
- else if (g_ieTouchScreen.code == ABS_Y)
- {
- g_iTouchY = (int)((g_ieTouchScreen.value - 300.0f) / 7.18f);
- //printf("Absolute Y: %dn", g_iTouchY); // Y top 300 bottom 3750 = 7.1875
- }
- else if (g_ieTouchScreen.code == ABS_PRESSURE)
- {
- if (g_ieTouchScreen.value >= 59000)
- g_iTouchPressure = (g_ieTouchScreen.value - 59000) / 50;
- //printf("Pressure: %dn", g_iTouchPressure);
- }
- else
- printf("Code: %02Xn", g_ieTouchScreen.code);
- }
- return (1);
- }
- // Try to write nothing to the file so it doesn't get used by the OS
- g_ieTouchScreen.type = 0;
- g_ieTouchScreen.code = 0;
- g_ieTouchScreen.value = 0;
- lseek(g_fdTouchScreen, SEEK_CUR, -sizeof(struct input_event));
- write(g_fdTouchScreen, &g_ieTouchScreen, sizeof(struct input_event));
Add Comment
Please, Sign In to add comment