Created
September 3, 2017 08:25
-
-
Save kyujin-cho/3772c0cd25497bac81d540d36d08d9f4 to your computer and use it in GitHub Desktop.
Make bulk touch events using send events code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <errno.h> | |
#include <fcntl.h> | |
#include <linux/input.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/ioctl.h> | |
#include <unistd.h> | |
#define X 225 | |
#define Y0 450 | |
#define Y1 850 | |
#define Y2 1250 | |
#define Y3 1650 | |
#define Y4 2050 | |
int main_run(int fd, int a, int b, int c) { | |
struct input_event event; | |
memset(&event, 0, sizeof(event)); | |
event.type = a; | |
event.code = b; | |
event.value = c; | |
return (write(fd, &event, sizeof(event)) >= (ssize_t) sizeof(event)); | |
} | |
int simtouch_main(int argc, char *argv[]) | |
{ | |
if(argc != 3) { | |
fprintf(stderr, "not a proper argument"); | |
return 1; | |
} | |
int fd; | |
ssize_t ret; | |
int version; | |
struct input_event event; | |
FILE* fp; | |
int init[4][3] = { | |
// init | |
{3, 57, 0xd000}, | |
{1, 330, 1}, | |
{1, 325, 1}, | |
{0, 0, 0}, | |
}; | |
int touches[10000][2]; | |
float delays[10000]; | |
int finalize[5][3] = { | |
{0, 0, 0}, | |
{3, 57, 4294967295}, | |
{0, 0, 0}, | |
{1, 330, 0}, | |
{1, 325, 0}, | |
{0, 0, 0} | |
}; | |
fprintf(stderr, "opening %s\n", argv[1]); | |
fd = open(argv[1], O_RDWR); | |
if(fd < 0) { | |
fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno)); | |
return 1; | |
} | |
fprintf(stderr, "importing note %s\n", argv[2]); | |
fp = fopen(argv[2], "r"); | |
if(fp == NULL) { | |
fprintf(stderr, "could not open %s%s\n", argv[2]); | |
} | |
int x, y; | |
double time; | |
int touch_i = 0 | |
while(!feof(fp)) { | |
fscanf(fp, "%d %d %f\n", &x, &y, &time); | |
touches[touch_i][0] = x; | |
touches[touch_i][1] = y; | |
delays[touch_i] = time; | |
touch_i++; | |
} | |
touches[touch_i][0] = -1; | |
touches[touch_i][1] = -1; | |
delays[touch_i] = -1.0; | |
if (ioctl(fd, EVIOCGVERSION, &version)) { | |
fprintf(stderr, "could not get driver version for %s, %s\n", argv[optind], strerror(errno)); | |
return 1; | |
} | |
int i = 0; | |
while(touches[i][0] != -1) { | |
for(int i = 0; i < 4; i++) { | |
if(!main_run(fd, init[i][0], init[i][1], init[i][2])) { | |
fprintf(stderr, "Error while executing init %d\n", i); | |
return -1; | |
} | |
} | |
if(!(main_run(fd, 3, 53, touches[i][0]) && main_run(fd, 3, 54, touches[i][1]))) { | |
fprintf(stderr, "Error while executing main\n"); | |
return -1; | |
} | |
for(int i = 0; i < 5; i++) { | |
if(!main_run(fd, finalize[i][0], finalize[i][1], finalize[i][2])) { | |
fprintf(stderr, "Error while executing finalize %d\n", i); | |
return -1; | |
} | |
} | |
i++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment