Peter Fischer
|
Re: Use Joysticks/Joypads in an Application
|
Peter Fischer
01/28/2009 7:30 AM
post20908
|
Re: Use Joysticks/Joypads in an Application
That would be really great, Eric.
I have managed to connect the joypad correctly to the system.
With the hidview utility I can see that it is recognized and what data the joypad sends.
"All" I need to do now is access the joypad in the same way hidview does. Is there source code of hidview available?
Using devi-hid I also succeded in creating the entry /dev/devi/joystick0.
I read that all you have to do is opening this file like a normal file.
I tried with the following code, but read from the file blocks...
If you have any suggestions, please write here.
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
int fd;
int size_read;
char fileName[]="/dev/devi/joystick0";
char buffer[80];
cout << "Starting Joystick Output" << endl;
/* Open a file for input */
fd = open( fileName, O_RDONLY );
if(fd==-1)
{
cerr << "Could not open" << fileName<< endl;
}
else
{
cout << "File "<< fileName << " opened successfully. " << fd << endl;
}
while(true)
{
/* Read the text */
cout << "Calling read()..." << endl;
size_read = read( fd, buffer, sizeof( buffer ) );
cout << "Reading completed. " << endl;
/* Test for error */
if( size_read == -1 ) {
cerr << "Error reading " << fileName << endl;
close( fd );
return EXIT_FAILURE;
}
else
{
// print out data
cout << size_read << endl;
cout << buffer << endl;
}
}
/* Close the file */
close( fd );
return EXIT_SUCCESS;
}
|
|
|