Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Use Joysticks/Joypads in an Application: (3 Items)
   
Use Joysticks/Joypads in an Application  
Hello Community,

i want to use a Logitech Cordless Rumblepad in my application to guide a robot. How can i access this Joypad inside my 
application? I read that using io-hid may be the right way, but I cant find documentation about how to program it.

An example source code would be really nice.

Thank you very much.

Best regards

Peter Fischer
Re: Use Joysticks/Joypads in an Application  
Hi Peter,

The current version of the devi-hid driver does support joysticks and gamepads, although not officially and to a limited
 extent (only via the resmgr interface).

I have the exact gamepad you are refering to let me see about getting it to work with what is currently shipping and if 
it works I will give you a source example of how to use it.

Erick

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;
}