Refer this url for Gamepad.c and Gamepad.h files.
https://github.com/elanthis/gamepad
Open the joystick using
STATE.fd = open(STATE.device, O_RDWR|O_NONBLOCK);
Structure Definition:
STATE is a structure object.
//It is in Gamepad.h file
open returns -1 on failure.
Set the flag value (defined while declaring variables for joystick) if opened successfully.
Read the joystick input using
(read(STATE[gamepad].fd, &je, sizeof(je)) > 0)
Structure Definition:
je is a structure object
//It is in joystick.h
je is updated now.
je.type is one among the three things mentioned in the joystick.h header file
If a button is pressed , then je.number is an int that denotes the button number as specified by the manufacturer. If a stick is moved , then je.number denotes the axis specification by the manufacturer.
The magnitude is present in the je.value which is assigned to the stick's corresponding variable accordingly.