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; }
{"joystick_strafe_invert", 0}, {"joyb_fire", -1}, {"joyb_use", -1}, {"joyb_strafe", -1}, {"joyb_speed", -1}, {"joyb_strafeleft", -1}, {"joyb_straferight", -1}, {"joyb_prevweapon", -1}, {"joyb_nextweapon", -1}, {"joyb_menu_activate", -1}, {NULL, 0}, }; static const joystick_config_t ps3_controller[] = { {"joystick_x_axis", CREATE_BUTTON_AXIS(7, 5)}, {"joystick_y_axis", CREATE_BUTTON_AXIS(4, 6)}, {"joyb_fire", 15}, // Square {"joyb_speed", 14}, // X {"joyb_use", 13}, // Circle {"joyb_jump", 12}, // Triangle {"joyb_strafeleft", 8}, // Bottom shoulder buttons {"joyb_straferight", 9}, {"joyb_prevweapon", 10}, // Top shoulder buttons {"joyb_nextweapon", 11}, {"joyb_menu_activate", 3}, // Start {NULL, 0}, }; static const joystick_config_t airflo_controller[] = {