65int main(
int argc,
char **argv )
68 SDL_JoystickEventState ( SDL_QUERY );
69 if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK) < 0 )
71 yError (
"JoystickCheck: Unable to initialize joystick system: %s\n", SDL_GetError() );
77 int joystick_num = SDL_NumJoysticks ();
80 if (joystick_num <= 0)
82 yError (
"JoystickCheck: no joysticks found.\n");
87 fprintf ( stderr,
"JoystickCheck: (%d) joystick(s) found.\n",joystick_num);
89 SDL_Joystick* joy1 = SDL_JoystickOpen ( joy_id );
92 yError (
"Could not open default joystick.\n" );
95 int numAxes = SDL_JoystickNumAxes ( joy1 );
96 int numBalls = SDL_JoystickNumBalls ( joy1 );
97 int numHats = SDL_JoystickNumHats ( joy1 );
98 int numButtons = SDL_JoystickNumButtons ( joy1 );
101 double* firstAxes =
new double [numAxes];
102 double* firstBalls =
new double [numBalls];
103 double* firstHats =
new double [numHats];
104 double* firstButtons =
new double [numButtons];
105 double* valAxes =
new double [numAxes];
106 double* valBalls =
new double [numBalls];
107 double* valHats =
new double [numHats];
108 double* valButtons =
new double [numButtons];
111 for (
int trial=0; trial < 1000; trial++ )
113 yarp::os::Time::delay(0.010);
114 SDL_JoystickUpdate();
118 for (
int i=0; i < numAxes; i++)
119 firstAxes[i] = (
double)SDL_JoystickGetAxis(joy1, i);
122 for (
int i=0; i < numHats; i++)
123 firstHats[i] = (
double)SDL_JoystickGetHat(joy1, i);
124 for (
int i=0; i < numButtons; i++)
125 firstButtons[i] = (
double)SDL_JoystickGetButton(joy1, i);
129 for (
int i=0; i < numAxes; i++)
131 valAxes[i] = (double)SDL_JoystickGetAxis(joy1, i);
132 if (fabs(valAxes[i]-firstAxes[i])>25000)
140 for (
int i=0; i < numHats; i++)
142 valHats[i] = (double)SDL_JoystickGetHat(joy1, i);
143 if (fabs(valHats[i]-firstHats[i])>100)
149 for (
int i=0; i < numButtons; i++)
151 valButtons[i] = (double)SDL_JoystickGetButton(joy1, i);
152 if (fabs(valButtons[i]-firstButtons[i])>0.5)
162 yInfo (
"joysticks activity detected.\n" );
167 yInfo (
"no joysticks are currently used.\n" );