iirlaq
Last Updated: February 25, 2016
·
892
· dlion
28864ba1e7e4490c3e5e97e095d4b6c7

Recognize Joystick information with C

For this snippet I use C and plib libraries.
http://plib.sourceforge.net/

#include <plib/js.h>

int main()
{
    jsJoystick *js[1];
    float *assi[1];
    int j;

    jsInit();

   js[0]= new jsJoystick(0);

   if(!js[0]->notWorking()) 
   {
       printf("Joystick's name found: %s\n",js[0]->getName());

       assi[0] = new float[js[0]->getNumAxes()];

       while(!js[0]->notWorking())
       {
           int dato;

           js[0]->read(&dato,assi[0]);
           printf("Button: %x\n",dato);

           for(j=0; j < js[0]->getNumAxes(); j++)
               printf("%+.1f ",assi[0][j]);
           putchar('\n');
           fflush(stdout);
           usleep(10000);
       }
   }
else
       puts("Joystick not found");
return 0;
}

It's simple.
With this snippet i can recognize a joystick and the button that I pressed or when I move the Axes I can retrieve their position.

Say Thanks
Respond