I'm using ubuntu 10.04
I'm writing a small program to read the input of a gamepad (ps3) that needs a driver (sixad). I used popen to create a process and run the driver in background. Also I want to know when the gamepad is connected, so I need to catch the sixad messages, I made popen("sixad -s (start) 2>&1, "r")) to read from both stdout and stderr. When I got the message that the gamepad is connected I was thinking in breaking the while loop, and to proceed with the rest of the program.
I tested the following code, but I don't understand the results (more below), why the loop isn't always running?.
I'm a complete newbie, I don't know if this is the correct way of doing what I want, so any suggestions will be very appreciated.
Terminal: when I don't press the PS buttonCode:FILE *fp1; printf("popen\n"); if ((fp1 = popen("sixad -s 2>&1","r")) == NULL) { fprintf(stderr, "Fail opening popen\n"); exit(EXIT_FAILURE); } char linha[400]; printf("\n1"); while(fgets(linha,400,fp1)!=NULL) { printf("\n2"); char *n=strstr(linha,"Connected PLAYSTATION(R)3 Controller"); printf("\n3"); printf("\n[%s]%s",n,linha); printf("\n4"); if(n=='\0') { printf("\n5"); } printf("\n6"); } printf("\n7");
Terminal: when I press the PS button @5 and the gamepad is sucessfully connected1
2
3
[(null)]sixad[2114]: sixad started, press the PS button now
4
5
1
2
3
[(null)]sixad[2432]: sixad started, press the PS button now
4
5
6
2
3
[Connected PLAYSTATION(R)3 Controller (00:23:06:A4:E6:AA)
]sixad[2446]: Connected PLAYSTATION(R)3 Controller (00:23:06:A4:E6:AA)
4



LinkBack URL
About LinkBacks


