Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Make gamecontroller triggers have values in 0 - 32767.
Browse files Browse the repository at this point in the history
This changes the old behavior of having values in the -32768 - 32767
range, like regular joystick axis. Now "button as axis" triggers (like
on Logitech controllers) and regular axis triggers (like on Xbox
controllers) have the same resting value, 0.
  • Loading branch information
jorgenpt committed Apr 19, 2013
1 parent eadd9c5 commit c166dfb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -157,7 +157,18 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
{
if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through
{
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.raxes[event->jaxis.axis], event->jaxis.value );
SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
Sint16 value = event->jaxis.value;
switch (axis)
{
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
/* Shift it to be 0 - 32767. */
value = ( value + 32768 ) / 2;
default:
break;
}
SDL_PrivateGameControllerAxis( controllerlist, axis, value );
}
else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button
{
Expand Down Expand Up @@ -187,7 +198,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
}
else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis
{
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32768 : 0 );
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
}
break;
}
Expand Down

0 comments on commit c166dfb

Please sign in to comment.