static boolean SetButtonAxisPositive(txt_joystick_axis_t *joystick_axis) { int button; button = FindPressedAxisButton(joystick_axis); if (button >= 0) { *joystick_axis->axis |= CREATE_BUTTON_AXIS(0, button); return true; } return false; }
static boolean SetButtonAxisPositive(int *axis_index) { int button; button = FindPressedAxisButton(); if (button >= 0) { *axis_index |= CREATE_BUTTON_AXIS(0, button); return true; } return false; }
static boolean CalibrateAxis(txt_joystick_axis_t *joystick_axis) { int best_axis; int best_value; int best_invert; Sint16 axis_value; int i; // Check all axes to find which axis has the largest value. We test // for one axis at a time, so eg. when we prompt to push the joystick // left, whichever axis has the largest value is the left axis. best_axis = 0; best_value = 0; best_invert = 0; for (i = 0; i < SDL_JoystickNumAxes(joystick_axis->joystick); ++i) { axis_value = SDL_JoystickGetAxis(joystick_axis->joystick, i); if (joystick_axis->bad_axis[i]) { continue; } if (abs(axis_value) > best_value) { best_value = abs(axis_value); best_invert = axis_value > 0; best_axis = i; } } // Did we find one axis that had a significant value? if (best_value > 32768 / 4) { // Save the best values we have found *joystick_axis->axis = best_axis; *joystick_axis->invert = best_invert; return true; } // Otherwise, maybe this is a "button axis", like the PS3 SIXAXIS // controller that exposes the D-pad as four individual buttons. // Search for a button. i = FindPressedAxisButton(joystick_axis); if (i >= 0) { *joystick_axis->axis = CREATE_BUTTON_AXIS(i, 0); *joystick_axis->invert = 0; return true; } // Maybe it's a D-pad that is presented as a hat. This sounds weird // but gamepads like this really do exist; an example is the // Nyko AIRFLO Ex. i = FindUncenteredHat(joystick_axis->joystick, joystick_axis->invert); if (i >= 0) { *joystick_axis->axis = i; return true; } // User pressed the button without pushing the joystick anywhere. return false; }