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.StartComm("/dev/input/js0");
After declaration, register callbacks on buttons and axes.
gamepad.
buttons(7)->callback = sigc::mem_fun<int>(*
this,&CallbackClass::gamepadIgnitionONCallback);
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.