0

I am working on an embedded Linux (kernel 5.10.24) with a touch screen.
Now I want to trigger touch event by writing to /dev/input/eventX corresponding to the touch screen.

To figure out the event I want to emulate, I firstly collected the events by touching the screen. Then I hard coded the events in codes and write them one by one to the /dev/input/eventX.

Below are the events I got from a touching.

~ # ./touchevent
timeS=1651152027,timeUS=312095,type=3,code=57,value=50
timeS=1651152027,timeUS=312095,type=3,code=53,value=218
timeS=1651152027,timeUS=312095,type=3,code=54,value=1223
timeS=1651152027,timeUS=312095,type=3,code=48,value=54
timeS=1651152027,timeUS=312095,type=3,code=58,value=54
timeS=1651152027,timeUS=312095,type=1,code=330,value=1
timeS=1651152027,timeUS=312095,type=0,code=0,value=0
timeS=1651152027,timeUS=448388,type=3,code=57,value=-1
timeS=1651152027,timeUS=448388,type=1,code=330,value=0
timeS=1651152027,timeUS=448388,type=0,code=0,value=0

I hardcoded the first 7 events (including an EV_SYN) to write to /dev/input/eventX.

#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/input.h>
int main( void )
{
        int                     fd;
        int                     ret;
        struct input_event      event;

        fd = open( "/dev/input/event0", O_RDWR);
        if ( fd < 0 )
        {
                perror( "/dev/input/event0" );
                return(-1);
        }

        event.type = 3;
        event.code = 53;
        event.value = 218;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        event.type = 3;
        event.code = 54;
        event.value = 1223;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        event.type = 3;
        event.code = 48;
        event.value = 54;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        event.type = 3;
        event.code = 58;
        event.value = 54;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        event.type = 1;
        event.code = 330;
        event.value = 1;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        event.type = 0;
        event.code = 0;
        event.value = 0;
        ret     = write( fd, &event, sizeof(struct input_event) );
        printf("ret: %d\n", ret);

        close( fd );
.....
}

When I ran the code on the target, there is NO expected response from the touch screen.
I am not sure if it is possible to emulate touch events by writing to /dev/input/eventX, if so, what did I miss on doing it ?

I don't have sendevent/getevent tools from Andriod, and I want to do this by myself.

1 Answer 1

0

With plenty of test-and-trials, I finally make the event injection work.
Firstly, I checked the kernel code of input device and touch screen device driver, I found writing to /dev/input/event0 uses the similar logic as TS driver to report an event.
This confirmed me this is a right direction.

Second, I changed testing way as follows,

  1. Record the complete events from screen touching.
  2. Replay all of the events by writing to /dev/input/event0.
  3. Check the screen to confirm it is working as touching from fingers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .