Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleep 1s after UI_DEV_CREATE #213

Open
tillthendofworld opened this issue Mar 7, 2024 · 0 comments
Open

sleep 1s after UI_DEV_CREATE #213

tillthendofworld opened this issue Mar 7, 2024 · 0 comments

Comments

@tillthendofworld
Copy link

tillthendofworld commented Mar 7, 2024

int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
......
ioctl(fd, UI_DEV_CREATE);
/*
* On UI_DEV_CREATE the kernel will create the device node for this
* device. We are inserting a pause here so that userspace has time
* to detect, initialize the new device, and can start listening to
* the event, otherwise it will not notice the event we are about
* to send.
*/
//sleep(1);
write(...); // not work, if not sleep(1)

https://kernel.org/doc/html/v4.12/input/uinput.html#examples

    '''  a not work example, draw circle inf, 
         the first BTN_TOUCH,1 is ignored because the device not created'''
    def draw_cricle(x0=600,y0=1493,n=4,r=50):
         n=int(n)
         for k in range(0,n):
             angle = 2*math.pi*(k/n+3/4)
             x = r*math.cos(angle)+x0
             y = r*math.sin(angle)+y0
             yield int(x),int(y)
     code= ''
     self.TRACKING_ID+=1
     code+= f'// {x0},{y0}\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_SLOT, {int(slot_id)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_TRACKING_ID, {int(self.TRACKING_ID)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_X, {int(x0)});\n'
     code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_Y, {int(y0)});\n'
     code+= f'emit(uinputfd, EV_KEY, BTN_TOUCH, 1);\n'
     code+= f'emit(uinputfd, EV_SYN, SYN_REPORT, 0);\n'
     code+= '''while(1) {\n'''
     for idx,(x,y) in enumerate(draw_cricle()):
         code+= f'  usleep({int(s*1000000)});//{s}s\n' #s=0.01 s
         code+= f'// move {x},{y}\n'
         # code+= f'emit(uinputfd, EV_ABS, ABS_MT_SLOT, {int(slot_id)});\n'
         code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_X, {int(x)});\n'
         code+= f'emit(uinputfd, EV_ABS, ABS_MT_POSITION_Y, {int(y)});\n'
         code+= f'emit(uinputfd, EV_SYN, SYN_REPORT, 0);\n'
     code+= '''}         \n'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant