Skip to content

Commit

Permalink
Split controller axes into positive and negative sides so each can be…
Browse files Browse the repository at this point in the history
… bound independently.

Using this a D-Pad can be mapped to a thumbstick and vice versa.
Also added support for inverted axes, improving trigger binding support
  • Loading branch information
slouken committed Dec 27, 2016
1 parent 7c31636 commit 6d7da08
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 342 deletions.
2 changes: 2 additions & 0 deletions include/SDL_joystick.h
Expand Up @@ -232,6 +232,8 @@ extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
*/
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);

#define SDL_JOYSTICK_AXIS_MAX 32767
#define SDL_JOYSTICK_AXIS_MIN -32768
/**
* Get the current state of an axis control on a joystick.
*
Expand Down
662 changes: 392 additions & 270 deletions src/joystick/SDL_gamecontroller.c

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/joystick/windows/SDL_dinputjoystick.c
Expand Up @@ -33,9 +33,7 @@
#endif

#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
#define JOY_AXIS_THRESHOLD (((SDL_JOYSTICK_AXIS_MAX)-(SDL_JOYSTICK_AXIS_MIN))/100) /* 1% motion */

/* external variables referenced. */
extern HWND SDL_HelperWindow;
Expand Down Expand Up @@ -481,8 +479,8 @@ EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
diprg.diph.dwObj = dev->dwType;
diprg.diph.dwHow = DIPH_BYID;
diprg.lMin = AXIS_MIN;
diprg.lMax = AXIS_MAX;
diprg.lMin = SDL_JOYSTICK_AXIS_MIN;
diprg.lMax = SDL_JOYSTICK_AXIS_MAX;

result =
IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
Expand Down
8 changes: 3 additions & 5 deletions src/joystick/windows/SDL_mmjoystick.c
Expand Up @@ -41,10 +41,8 @@
#define MAX_JOYSTICKS 16
#define MAX_AXES 6 /* each joystick can have up to 6 axes */
#define MAX_BUTTONS 32 /* and 32 buttons */
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
/* limit axis to 256 possible positions to filter out noise */
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256)
#define JOY_AXIS_THRESHOLD (((SDL_JOYSTICK_AXIS_MAX)-(SDL_JOYSTICK_AXIS_MIN))/256)
#define JOY_BUTTON_FLAG(n) (1<<n)


Expand Down Expand Up @@ -253,9 +251,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
joystick->hwdata->id = SYS_JoystickID[index];
for (i = 0; i < MAX_AXES; ++i) {
if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) {
joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i];
joystick->hwdata->transaxis[i].offset = SDL_JOYSTICK_AXIS_MIN - axis_min[i];
joystick->hwdata->transaxis[i].scale =
(float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]);
(float) (SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN) / (axis_max[i] - axis_min[i]);
} else {
joystick->hwdata->transaxis[i].offset = 0;
joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */
Expand Down
Binary file modified test/axis.bmp
Binary file not shown.

0 comments on commit 6d7da08

Please sign in to comment.