Ejemplo n.º 1
0
/* return its power level */
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return (SDL_JOYSTICK_POWER_UNKNOWN);
    }
    return joystick->epowerlevel;
}
Ejemplo n.º 2
0
/*
 * Get the ball axis change since the last poll
 */
int
SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy)
{
    int retval;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (-1);
    }

    retval = 0;
    if (ball < joystick->nballs) {
        if (dx) {
            *dx = joystick->balls[ball].dx;
        }
        if (dy) {
            *dy = joystick->balls[ball].dy;
        }
        joystick->balls[ball].dx = 0;
        joystick->balls[ball].dy = 0;
    } else {
        SDL_SetError("Joystick only has %d balls", joystick->nballs);
        retval = -1;
    }
    return (retval);
}
Ejemplo n.º 3
0
/*
 * Opens a haptic device from a joystick.
 */
SDL_Haptic *
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
{
    SDL_Haptic *haptic;
    SDL_Haptic *hapticlist;

    /* Make sure there is room. */
    if (SDL_NumHaptics() <= 0) {
        SDL_SetError("Haptic: There are %d haptic devices available",
                     SDL_NumHaptics());
        return NULL;
    }

    /* Must be a valid joystick */
    if (!SDL_PrivateJoystickValid(joystick)) {
        SDL_SetError("Haptic: Joystick isn't valid.");
        return NULL;
    }

    /* Joystick must be haptic */
    if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
        SDL_SetError("Haptic: Joystick isn't a haptic device.");
        return NULL;
    }

    hapticlist = SDL_haptics;
    /* Check to see if joystick's haptic is already open */
    while ( hapticlist )
    {
        if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
            haptic = hapticlist;
            ++haptic->ref_count;
            return haptic;
        }
        hapticlist = hapticlist->next;
    }

    /* Create the haptic device */
    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
    if (haptic == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize the haptic device */
    SDL_memset(haptic, 0, sizeof(SDL_Haptic));
    haptic->rumble_id = -1;
    if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
        SDL_free(haptic);
        return NULL;
    }

    /* Add haptic to list */
    ++haptic->ref_count;
    /* Link the haptic in the list */
    haptic->next = SDL_haptics;
    SDL_haptics = haptic;

    return haptic;
}
Ejemplo n.º 4
0
/*
 * Get the device index of an opened joystick.
 */
int
SDL_JoystickIndex(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (-1);
    }
    return (joystick->index);
}
Ejemplo n.º 5
0
/*
 * Get the number of trackballs on a joystick
 */
int
SDL_JoystickNumBalls(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return (-1);
    }
    return (joystick->nballs);
}
Ejemplo n.º 6
0
/*
 * Get the number of multi-dimensional axis controls on a joystick
 */
int
SDL_JoystickNumAxes(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (-1);
    }
    return (joystick->naxes);
}
Ejemplo n.º 7
0
/*
 * Get the number of hats on a joystick
 */
int
SDL_JoystickNumHats(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (-1);
    }
    return (joystick->nhats);
}
Ejemplo n.º 8
0
/*
 * Get the number of buttons on a joystick
 */
int
SDL_JoystickNumButtons(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (-1);
    }
    return (joystick->nbuttons);
}
Ejemplo n.º 9
0
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        SDL_JoystickGUID emptyGUID;
        SDL_zero(emptyGUID);
        return emptyGUID;
    }
    return SDL_SYS_JoystickGetGUID(joystick);
}
Ejemplo n.º 10
0
/*
 * Return if the joystick in question is currently attached to the system,
 *  \return SDL_FALSE if not plugged in, SDL_TRUE if still present.
 */
SDL_bool
SDL_JoystickGetAttached(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return SDL_FALSE;
    }

    return SDL_SYS_JoystickAttached(joystick);
}
Ejemplo n.º 11
0
/*
 * Get the instance id for this opened joystick
 */
SDL_JoystickID
SDL_JoystickInstanceID(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return (-1);
    }

    return (joystick->instance_id);
}
Ejemplo n.º 12
0
/*
 * Get the friendly name of this joystick
 */
const char *
SDL_JoystickName(SDL_Joystick * joystick)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return (NULL);
    }

    return (joystick->name);
}
Ejemplo n.º 13
0
/*
 * Opens a haptic device from a joystick.
 */
SDL_Haptic *
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
{
    int i;
    SDL_Haptic *haptic;

    /* Must be a valid joystick */
    #ifdef SDL_JOYSTICK_DISABLED
    /* if joystick support is disabled it can't be valid */
    return -1;
    #else
    if (!SDL_PrivateJoystickValid(joystick)) {
        SDL_SetError("Haptic: Joystick isn't valid.");
        return NULL;
    }
    #endif

    /* Joystick must be haptic */
    if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
        SDL_SetError("Haptic: Joystick isn't a haptic device.");
        return NULL;
    }

    /* Check to see if joystick's haptic is already open */
    for (i = 0; SDL_haptics[i]; i++) {
        if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i], joystick)) {
            haptic = SDL_haptics[i];
            ++haptic->ref_count;
            return haptic;
        }
    }

    /* Create the haptic device */
    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
    if (haptic == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize the haptic device */
    SDL_memset(haptic, 0, sizeof(SDL_Haptic));
    haptic->rumble_id = -1;
    if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
        SDL_free(haptic);
        return NULL;
    }

    /* Add haptic to list */
    ++haptic->ref_count;
    for (i = 0; SDL_haptics[i]; i++)
        /* Skip to next haptic */ ;
    SDL_haptics[i] = haptic;

    return haptic;
}
Ejemplo n.º 14
0
/*
 * Close a joystick previously opened with SDL_JoystickOpen()
 */
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
    int i;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return;
    }

    /* First decrement ref count */
    if (--joystick->ref_count > 0) {
        return;
    }

    /* Lock the event queue - prevent joystick polling */
    SDL_Lock_EventThread();

    if (joystick == default_joystick) {
        default_joystick = NULL;
    }
    SDL_SYS_JoystickClose(joystick);

    /* Remove joystick from list */
    for (i = 0; SDL_joysticks[i]; ++i) {
        if (joystick == SDL_joysticks[i]) {
            SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i + 1],
                        (SDL_numjoysticks - i) * sizeof(joystick));
            break;
        }
    }

    /* Let the event thread keep running */
    SDL_Unlock_EventThread();

    /* Free the data associated with this joystick */
    if (joystick->axes) {
        SDL_free(joystick->axes);
    }
    if (joystick->hats) {
        SDL_free(joystick->hats);
    }
    if (joystick->balls) {
        SDL_free(joystick->balls);
    }
    if (joystick->buttons) {
        SDL_free(joystick->buttons);
    }
    SDL_free(joystick);
}
Ejemplo n.º 15
0
/*
 * Get the initial state of an axis control on a joystick
 */
SDL_bool
SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick, int axis, Sint16 *state)
{
    if (!SDL_PrivateJoystickValid(joystick)) {
        return SDL_FALSE;
    }
    if (axis >= joystick->naxes) {
        SDL_SetError("Joystick only has %d axes", joystick->naxes);
        return SDL_FALSE;
    }
    if (state) {
        *state = joystick->axes[axis].initial_value;
    }
    return joystick->axes[axis].has_initial_value;
}
Ejemplo n.º 16
0
/*
 * Get the current state of a button on a joystick
 */
Uint8
SDL_JoystickGetButton(SDL_Joystick * joystick, int button)
{
    Uint8 state;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (0);
    }
    if (button < joystick->nbuttons) {
        state = joystick->buttons[button];
    } else {
        SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
        state = 0;
    }
    return (state);
}
Ejemplo n.º 17
0
/*
 * Get the current state of a hat on a joystick
 */
Uint8
SDL_JoystickGetHat(SDL_Joystick * joystick, int hat)
{
    Uint8 state;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (0);
    }
    if (hat < joystick->nhats) {
        state = joystick->hats[hat];
    } else {
        SDL_SetError("Joystick only has %d hats", joystick->nhats);
        state = 0;
    }
    return (state);
}
Ejemplo n.º 18
0
/*
 * Get the current state of an axis control on a joystick
 */
Sint16
SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis)
{
    Sint16 state;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return (0);
    }
    if (axis < joystick->naxes) {
        state = joystick->axes[axis];
    } else {
        SDL_SetError("Joystick only has %d axes", joystick->naxes);
        state = 0;
    }
    return (state);
}
Ejemplo n.º 19
0
/*
 * Returns SDL_TRUE if joystick has haptic features.
 */
int
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
{
    int ret;

    /* Must be a valid joystick */
    if (!SDL_PrivateJoystickValid(&joystick)) {
        return -1;
    }

    ret = SDL_SYS_JoystickIsHaptic(joystick);

    if (ret > 0)
        return SDL_TRUE;
    else if (ret == 0)
        return SDL_FALSE;
    else
        return -1;
}
Ejemplo n.º 20
0
/*
 * Close a joystick previously opened with SDL_JoystickOpen()
 */
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
    int i;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return;
    }

    /* First decrement ref count */
    if (--joystick->ref_count > 0) {
        return;
    }

    SDL_SYS_JoystickClose(joystick);

    /* Remove joystick from list */
    for (i = 0; SDL_joysticks[i]; ++i) {
        if (joystick == SDL_joysticks[i]) {
            SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i + 1],
                        (SDL_numjoysticks - i) * sizeof(joystick));
            break;
        }
    }

    /* Free the data associated with this joystick */
    if (joystick->axes) {
        SDL_free(joystick->axes);
    }
    if (joystick->hats) {
        SDL_free(joystick->hats);
    }
    if (joystick->balls) {
        SDL_free(joystick->balls);
    }
    if (joystick->buttons) {
        SDL_free(joystick->buttons);
    }
    SDL_free(joystick);
}
Ejemplo n.º 21
0
/*
 * Returns SDL_TRUE if joystick has haptic features.
 */
int
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
{
    int ret;

    /* Must be a valid joystick */
    #ifdef SDL_JOYSTICK_DISABLED
    /* if joystick support is disabled it can't be valid */
    return -1;
    #else
    if (!SDL_PrivateJoystickValid(joystick)) {
        return -1;
    }
    #endif

    ret = SDL_SYS_JoystickIsHaptic(joystick);

    if (ret > 0)
        return SDL_TRUE;
    else if (ret == 0)
        return SDL_FALSE;
    else
        return -1;
}
Ejemplo n.º 22
0
/*
 * Opens a haptic device from a joystick.
 */
SDL_Haptic *
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
{
    int i;
    SDL_Haptic *haptic;

    /* Make sure there is room. */
    if (SDL_numhaptics <= 0) {
        SDL_SetError("Haptic: There are %d haptic devices available",
                     SDL_numhaptics);
        return NULL;
    }

    /* Must be a valid joystick */
    if (!SDL_PrivateJoystickValid(joystick)) {
        SDL_SetError("Haptic: Joystick isn't valid.");
        return NULL;
    }

    /* Joystick must be haptic */
    if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
        SDL_SetError("Haptic: Joystick isn't a haptic device.");
        return NULL;
    }

    /* Check to see if joystick's haptic is already open */
    for (i = 0; SDL_haptics[i]; i++) {
        if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i], joystick)) {
            haptic = SDL_haptics[i];
            ++haptic->ref_count;
            return haptic;
        }
    }

    /* Create the haptic device */
    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
    if (haptic == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize the haptic device */
    SDL_memset(haptic, 0, sizeof(SDL_Haptic));
    haptic->rumble_id = -1;
    if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
        SDL_free(haptic);
        return NULL;
    }

    /* Add haptic to list */
    for (i = 0; SDL_haptics[i]; i++)
        /* Skip to next haptic */ ;
    if (i >= SDL_numhaptics) {
        SDL_free(haptic);
        SDL_SetError("Haptic: Trying to add device past the number originally detected");
        return NULL;
    }
    SDL_haptics[i] = haptic;
    ++haptic->ref_count;

    return haptic;
}