I paired a bluetooth gamepad to my raspberry wich created two device files. One for directions and the other for the buttons. read a file works fine but i cant read both at the same time.
int main()
{
char devname1[] = "/dev/input/event0";
char devname2[] = "/dev/input/event2";
int device1 = open(devname1, O_RDONLY);
int device2 = open(devname2, O_RDONLY);
struct input_event ev1;
struct input_event ev2;
while(1)
{
read(device1,&ev1, sizeof(ev1));
read(device2,&ev2, sizeof(ev2));
logger(ev1);
logger(ev2);
}
}
I created two file descriptors and read the data into two seperate structures. While outputing the gamepad output the programm sometimes print just from the one file and sometimes just from the second one.
Whats the propper way to read both files?