How to use the Gamepad in your project?

In the beginning of your code create a class instance and start the communication on the correct device.

Gamepad gamepad;//Create the instance
gamepad.StartComm("/dev/input/js0");//Connect to the device

After declaration, register callbacks on buttons and axes.

gamepad.buttons(7)->callback = sigc::mem_fun<int>(*this,&CallbackClass::gamepadIgnitionONCallback);//Registry a callback on an axes, this callback is a member function, if the callback is not a member function use sigc::ptr_fun instead

Example of a callback function:

void CallbackClass::GamepadThrottle(int value)
{
        double throttle;
        throttle=(((double)(value)/32768. + 1)/2);
        if(throttle<0.2)
                throttle=throttle*3;
        else
                throttle=throttle/2+0.5;
        
        if(throttle>1)
                throttle=1;
        command.throttle=throttle;
}

In the main loop of your code you must call the function Dispatch() in order to get new data from the device, this function automatically calls the respective callbacks when events occur.

gamepad.Dispatch(false);//Read device and call handlers, use Dispatch(true) to run in verbose mode (default is false)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


atlascar_base
Author(s): Jorge Almeida, Miguel Oliveira, Pedro Salvado, Andre Oliveira and Pedro Pinheiro
autogenerated on Wed Jul 23 04:34:34 2014