How to get Rawdata touch screen coordinates using Linux

there is a display with a microphone display with a capacity of 3 m. It is connected to my debian system via usb and recongnized as a human interface (hidden). I'm trying to access and click information in real time ... if it concerns, I want to know where (x, y) is and pass it through netcat to another host.

Unfortunately, I can only get the raw data using

cat /dev/input/event2 | hexdump 

or evtest

You get a hex code that is not documented anywhere ...

Does anyone know how to get this information? There must be a way to extract it from the hex code. Unfortunately, I have no idea how to interpret the hex code. I could not find any source where it was documented ...

Is there a way that the Kernel can provide me with this desired information in real time? As a working solution, there could be a solution, where can the X-Server tell me? The touch screen behaves like a mouse in X. I actually tried to get the x, y position of the mouse using xlib. But it was too slow and didn’t tell me if someone was touching or not ...

early!

test output:

 Event: time 1425319271.595631, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 51 Event: time 1425319271.595631, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 10304 Event: time 1425319271.595631, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30629 Event: time 1425319271.595631, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 893 Event: time 1425319271.595631, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 414 Event: time 1425319271.595631, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1 Event: time 1425319271.595631, type 3 (EV_ABS), code 0 (ABS_X), value 10304 Event: time 1425319271.595631, type 3 (EV_ABS), code 1 (ABS_Y), value 30629 Event: time 1425319271.595631, -------------- SYN_REPORT ------------ Event: time 1425319271.601632, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 10306 Event: time 1425319271.601632, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30625 Event: time 1425319271.601632, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 962 Event: time 1425319271.601632, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 421 Event: time 1425319271.601632, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1 Event: time 1425319271.601632, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 52 Event: time 1425319271.601632, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 15416 Event: time 1425319271.601632, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 24159 Event: time 1425319271.601632, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 649 Event: time 1425319271.601632, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 354 Event: time 1425319271.601632, type 3 (EV_ABS), code 0 (ABS_X), value 10306 Event: time 1425319271.601632, type 3 (EV_ABS), code 1 (ABS_Y), value 30625 Event: time 1425319271.601632, -------------- SYN_REPORT ------------ Event: time 1425319271.606626, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0 Event: time 1425319271.606626, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 10318 Event: time 1425319271.606626, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30609 Event: time 1425319271.606626, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 1014 Event: time 1425319271.606626, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 426 Event: time 1425319271.606626, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1 Event: time 1425319271.606626, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 24161 Event: time 1425319271.606626, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 681 Event: time 1425319271.606626, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 376 Event: time 1425319271.606626, type 3 (EV_ABS), code 0 (ABS_X), value 10318 Event: time 1425319271.606626, type 3 (EV_ABS), code 1 (ABS_Y), value 30609 Event: time 1425319271.606626, -------------- SYN_REPORT ------------ Event: time 1425319271.611629, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0 Event: time 1425319271.611629, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 10320 Event: time 1425319271.611629, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30605 Event: time 1425319271.611629, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 1053 Event: time 1425319271.611629, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 430 Event: time 1425319271.611629, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1 Event: time 1425319271.611629, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 705 Event: time 1425319271.611629, type 3 (EV_ABS), code 49 (ABS_MT_TOUCH_MINOR), value 392 Event: time 1425319271.611629, type 3 (EV_ABS), code 0 (ABS_X), value 10320 Event: time 1425319271.611629, type 3 (EV_ABS), code 1 (ABS_Y), value 30605 
+6
source share
1 answer

Console Solution

You can get the analyzed coordinates using the evtest tool.

  • If you only need one-touch coordinates: find the fields ABS_X and ABS_Y :

     type 3 (EV_ABS), code 0 (ABS_X), value 10306 type 3 (EV_ABS), code 1 (ABS_Y), value 30625 
  • If you need coordinates with a few touches:

    • ABS_MT_SLOT stands for the number of fingers.
    • ABS_MT_POSITION_X and ABS_MT_POSITION_Y - coordinates

    Finger # 0:

     type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0 type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 10318 type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 30609 

    Finger # 1:

     type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1 type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 20301 type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 24161 

For example, if you need to send coordinates with one touch over the network, you can use the script as follows:

 #!/bin/sh # ---- Global variables ---- input=/dev/input/event0 code_prefix="ABS" code="${code_prefix}_[XY]" val_regex=".*(${code_prefix}_\(.\)), value \([-]\?[0-9]\+\)" val_subst="\1=\2" # ---- Functions ---- send_axis() { # 1. Convert axis value ($1) from device specific units # 2. Send this axis value via UDP packet echo $1 } process_line() { while read line; do axis=$(echo $line | grep "^Event:" | grep $code | \ sed "s/$val_regex/$val_subst/") if [ -n "$axis" ]; then send_axis $axis fi done } # ---- Entry point ---- if [ $(id -u) -ne 0 ]; then echo "This script must be run from root" >&2 exit 1 fi evtest $input | process_line 

Software solution

You can write a C application that will read your event file. The resulting binary data can be easily interpreted; see Section 5 in the kernel documentation . You can wait for the next piece of data using select() syscall.

 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h> #define EVENT_DEVICE "/dev/input/event2" #define EVENT_TYPE EV_ABS #define EVENT_CODE_X ABS_X #define EVENT_CODE_Y ABS_Y /* TODO: Close fd on SIGINT (Ctrl-C), if it open */ int main(int argc, char *argv[]) { struct input_event ev; int fd; char name[256] = "Unknown"; if ((getuid ()) != 0) { fprintf(stderr, "You are not root! This may not work...\n"); return EXIT_SUCCESS; } /* Open Device */ fd = open(EVENT_DEVICE, O_RDONLY); if (fd == -1) { fprintf(stderr, "%s is not a vaild device\n", EVENT_DEVICE); return EXIT_FAILURE; } /* Print Device Name */ ioctl(fd, EVIOCGNAME(sizeof(name)), name); printf("Reading from:\n"); printf("device file = %s\n", EVENT_DEVICE); printf("device name = %s\n", name); for (;;) { const size_t ev_size = sizeof(struct input_event); ssize_t size; /* TODO: use select() */ size = read(fd, &ev, ev_size); if (size < ev_size) { fprintf(stderr, "Error size when reading\n"); goto err; } if (ev.type == EVENT_TYPE && (ev.code == EVENT_CODE_X || ev.code == EVENT_CODE_Y)) { /* TODO: convert value to pixels */ printf("%s = %d\n", ev.code == EVENT_CODE_X ? "X" : "Y", ev.value); } } return EXIT_SUCCESS; err: close(fd); return EXIT_FAILURE; } 

Coordinate units

First of all, you need to know the following:

  • where is the origin point (ie [x=0;y=0] )
  • which devices use to represent coordinates.

This information can usually be found in the driver code for your device.

This is the driver for your device.

It looks like you need to divide the axis value from evtest by 65535 and multiply it by the width or height of the device (in pixels). For example, if you get X = 30000, and the width of your LCD panel is 1080 pixels, you need to do:

 X = round((30000 / 65535) * 1080) = 494 pixels 
+16
source

Source: https://habr.com/ru/post/983279/


All Articles