| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | #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_BUTTON_FLAG(n) (1<<n) |
| | | |
| | | |
| | |
| | | char regvalue[256]; |
| | | char regname[256]; |
| | | |
| | | SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s\\%s", |
| | | SDL_snprintf(regkey, SDL_arraysize(regkey), |
| | | #ifdef UNICODE |
| | | "%S\\%s\\%S", |
| | | #else |
| | | "%s\\%s\\%s", |
| | | #endif |
| | | REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR); |
| | | hTopKey = HKEY_LOCAL_MACHINE; |
| | | regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey); |
| | |
| | | } |
| | | |
| | | /* open that registry key */ |
| | | SDL_snprintf(regkey, SDL_arraysize(regkey), "%s\\%s", REGSTR_PATH_JOYOEM, |
| | | regname); |
| | | SDL_snprintf(regkey, SDL_arraysize(regkey), |
| | | #ifdef UNICODE |
| | | "%S\\%s", |
| | | #else |
| | | "%s\\%s", |
| | | #endif |
| | | REGSTR_PATH_JOYOEM, regname); |
| | | regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey); |
| | | if (regresult != ERROR_SUCCESS) { |
| | | return NULL; |
| | |
| | | return (SDL_SYS_numjoysticks); |
| | | } |
| | | |
| | | int SDL_SYS_NumJoysticks() |
| | | int |
| | | SDL_SYS_NumJoysticks(void) |
| | | { |
| | | return SDL_SYS_numjoysticks; |
| | | } |
| | | |
| | | void SDL_SYS_JoystickDetect() |
| | | void |
| | | SDL_SYS_JoystickDetect(void) |
| | | { |
| | | } |
| | | |
| | |
| | | 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 */ |
| | |
| | | }; |
| | | DWORD pos[MAX_AXES]; |
| | | struct _transaxis *transaxis; |
| | | int value, change; |
| | | int value; |
| | | JOYINFOEX joyinfo; |
| | | |
| | | joyinfo.dwSize = sizeof(joyinfo); |
| | |
| | | transaxis = joystick->hwdata->transaxis; |
| | | for (i = 0; i < joystick->naxes; i++) { |
| | | if (joyinfo.dwFlags & flags[i]) { |
| | | value = |
| | | (int) (((float) pos[i] + |
| | | transaxis[i].offset) * transaxis[i].scale); |
| | | change = (value - joystick->axes[i]); |
| | | if ((change < -JOY_AXIS_THRESHOLD) |
| | | || (change > JOY_AXIS_THRESHOLD)) { |
| | | SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value); |
| | | } |
| | | value = (int) (((float) pos[i] + transaxis[i].offset) * transaxis[i].scale); |
| | | SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value); |
| | | } |
| | | } |
| | | |
| | |
| | | if (joyinfo.dwFlags & JOY_RETURNBUTTONS) { |
| | | for (i = 0; i < joystick->nbuttons; ++i) { |
| | | if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) { |
| | | if (!joystick->buttons[i]) { |
| | | SDL_PrivateJoystickButton(joystick, (Uint8) i, |
| | | SDL_PRESSED); |
| | | } |
| | | SDL_PrivateJoystickButton(joystick, (Uint8) i, SDL_PRESSED); |
| | | } else { |
| | | if (joystick->buttons[i]) { |
| | | SDL_PrivateJoystickButton(joystick, (Uint8) i, |
| | | SDL_RELEASED); |
| | | } |
| | | SDL_PrivateJoystickButton(joystick, (Uint8) i, SDL_RELEASED); |
| | | } |
| | | } |
| | | } |
| | |
| | | Uint8 pos; |
| | | |
| | | pos = TranslatePOV(joyinfo.dwPOV); |
| | | if (pos != joystick->hats[0]) { |
| | | SDL_PrivateJoystickHat(joystick, 0, pos); |
| | | } |
| | | SDL_PrivateJoystickHat(joystick, 0, pos); |
| | | } |
| | | } |
| | | |