mirror of
https://github.com/yawut/SDL.git
synced 2026-04-18 06:46:04 -05:00
Wii U: Add more Game Controllers.
Now SDL2's Game Controller API supports the Wii U Pro Controller, the Wii Classic Controller, the Wii Remote with a Nunchuk, and the Wii Remote without a Nunchuk (sideways). I've tested this with everything but the Classic Controller, as I do not own one to test with.
This commit is contained in:
parent
7d3405e886
commit
e2e7f27d37
|
|
@ -993,8 +993,14 @@ static const char *s_ControllerMappings[] = {
|
|||
"000000004e696e74656e646f20334400,Nintendo 3DS,crc:3210,a:b0,b:b1,back:b2,dpdown:b7,dpleft:b5,dpright:b4,dpup:b6,leftshoulder:b9,lefttrigger:b14,leftx:a0,lefty:a1,rightshoulder:b8,righttrigger:b15,rightx:a2,righty:a3,start:b3,x:b10,y:b11,",
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_WIIU)
|
||||
"576969552047616d6570616400000000,Wii U Gamepad,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"576969552047616d6570616400000000,Wii U Gamepad,a:b1,b:b0,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"49dcab4b72e942a1ad938e4aeb88d868,Wii U Gamepad,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"49dcab4b72e942a1ad938e4aeb88d868,Wii U Gamepad,a:b1,b:b0,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"6972c1586f704c4e9d80cc8957abb814,Wii U Pro Controller,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"6972c1586f704c4e9d80cc8957abb814,Wii U Pro Controller,a:b1,b:b0,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"fc547396886d4f55add913767f0f511c,Wii Classic Controller,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"fc547396886d4f55add913767f0f511c,Wii Classic Controller,a:b1,b:b0,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"cb9d4bbb6936494d891719af55b27e4d,Wii Remote + Nunchuk,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,",
|
||||
"88aa88b54e2742d2b4bbe04284a5a7a1,Wii Remote,a:b7,b:b6,back:b11,dpdown:b12,dpleft:b13,dpright:b15,dpup:b14,start:b10,x:b1,y:b0,",
|
||||
#endif
|
||||
"hidapi,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
NULL
|
||||
|
|
|
|||
|
|
@ -264,11 +264,57 @@ static void WIIU_JoystickSetDevicePlayerIndex(int device_index, int player_index
|
|||
/* Function to return the stable GUID for a plugged in device */
|
||||
static SDL_JoystickGUID WIIU_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
/* These are random GUIDs that were generated with http://guid.one/ . */
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = WIIU_JoystickGetDeviceName(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
|
||||
const int wiiu_device = WIIU_GetDeviceForIndex(device_index);
|
||||
|
||||
switch (wiiu_device)
|
||||
{
|
||||
case WIIU_DEVICE_GAMEPAD:
|
||||
guid = (SDL_JoystickGUID){{0x49, 0xdc, 0xab, 0x4b, 0x72, 0xe9, 0x42, 0xa1, 0xad, 0x93, 0x8e, 0x4a, 0xeb, 0x88, 0xd8, 0x68}};
|
||||
break;
|
||||
|
||||
case WIIU_DEVICE_WPAD(0):
|
||||
case WIIU_DEVICE_WPAD(1):
|
||||
case WIIU_DEVICE_WPAD(2):
|
||||
case WIIU_DEVICE_WPAD(3):
|
||||
switch (lastKnownExts[WIIU_WPAD_CHAN(wiiu_device)])
|
||||
{
|
||||
case WPAD_EXT_CORE:
|
||||
case WPAD_EXT_MPLUS:
|
||||
default:
|
||||
/* Wii Remote */
|
||||
guid = (SDL_JoystickGUID){{0x88, 0xaa, 0x88, 0xb5, 0x4e, 0x27, 0x42, 0xd2, 0xb4, 0xbb, 0xe0, 0x42, 0x84, 0xa5, 0xa7, 0xa1}};
|
||||
break;
|
||||
|
||||
case WPAD_EXT_NUNCHUK:
|
||||
case WPAD_EXT_MPLUS_NUNCHUK:
|
||||
/* Wii Remote + Nunchuk */
|
||||
guid = (SDL_JoystickGUID){{0xcb, 0x9d, 0x4b, 0xbb, 0x69, 0x36, 0x49, 0x4d, 0x89, 0x17, 0x19, 0xaf, 0x55, 0xb2, 0x7e, 0x4d}};
|
||||
break;
|
||||
|
||||
case WPAD_EXT_CLASSIC:
|
||||
case WPAD_EXT_MPLUS_CLASSIC:
|
||||
/* Wii Classic Controller */
|
||||
guid = (SDL_JoystickGUID){{0xfc, 0x54, 0x73, 0x96, 0x88, 0x6d, 0x4f, 0x55, 0xad, 0xd9, 0x13, 0x76, 0x7f, 0x0f, 0x51, 0x1c}};
|
||||
break;
|
||||
|
||||
case WPAD_EXT_PRO_CONTROLLER:
|
||||
/* Wii U Pro Controller */
|
||||
guid = (SDL_JoystickGUID){{0x69, 0x72, 0xc1, 0x58, 0x6f, 0x70, 0x4c, 0x4e, 0x9d, 0x80, 0xcc, 0x89, 0x57, 0xab, 0xb8, 0x14}};
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Unknown */
|
||||
/* The iPhone backend for SDL2 does this if it can't get a GUID. */
|
||||
SDL_zero(guid);
|
||||
break;
|
||||
}
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +365,7 @@ static int WIIU_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
|||
}
|
||||
case WPAD_EXT_NUNCHUK:
|
||||
case WPAD_EXT_MPLUS_NUNCHUK: {
|
||||
joystick->nbuttons = SIZEOF_ARR(wiimote_button_map);
|
||||
joystick->nbuttons = SIZEOF_ARR(nunchuk_button_map);
|
||||
joystick->naxes = 2;
|
||||
joystick->nhats = 0;
|
||||
break;
|
||||
|
|
@ -504,10 +550,10 @@ static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
|
|||
case WPAD_EXT_NUNCHUK:
|
||||
case WPAD_EXT_MPLUS_NUNCHUK: {
|
||||
for(int i = 0; i < joystick->nbuttons; i++)
|
||||
if (kpad.trigger & wiimote_button_map[i])
|
||||
if ((kpad.trigger | (kpad.nunchuck.trigger << 16)) & nunchuk_button_map[i])
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_PRESSED);
|
||||
for(int i = 0; i < joystick->nbuttons; i++)
|
||||
if (kpad.release & wiimote_button_map[i])
|
||||
if ((kpad.release | (kpad.nunchuck.release << 16)) & nunchuk_button_map[i])
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_RELEASED);
|
||||
|
||||
x1 = (int16_t) ((kpad.nunchuck.stick.x) * 0x7ff0);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#define SIZEOF_ARR(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
static VPADButtons vpad_button_map[] =
|
||||
static uint32_t vpad_button_map[] =
|
||||
{
|
||||
VPAD_BUTTON_A, VPAD_BUTTON_B, VPAD_BUTTON_X, VPAD_BUTTON_Y,
|
||||
VPAD_BUTTON_STICK_L, VPAD_BUTTON_STICK_R,
|
||||
|
|
@ -43,8 +43,8 @@ static VPADButtons vpad_button_map[] =
|
|||
VPAD_STICK_R_EMULATION_LEFT, VPAD_STICK_R_EMULATION_UP, VPAD_STICK_R_EMULATION_RIGHT, VPAD_STICK_R_EMULATION_DOWN
|
||||
};
|
||||
|
||||
static WPADButton wiimote_button_map[] = {
|
||||
WPAD_BUTTON_A, WPAD_BUTTON_B, WPAD_BUTTON_Z, WPAD_BUTTON_C,
|
||||
static uint32_t wiimote_button_map[] = {
|
||||
WPAD_BUTTON_A, WPAD_BUTTON_B, 0, 0,
|
||||
0, 0,
|
||||
WPAD_BUTTON_1, WPAD_BUTTON_2,
|
||||
0, 0,
|
||||
|
|
@ -52,18 +52,29 @@ static WPADButton wiimote_button_map[] = {
|
|||
WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_RIGHT, WPAD_BUTTON_DOWN,
|
||||
};
|
||||
|
||||
static WPADClassicButton classic_button_map[] = {
|
||||
static uint32_t nunchuk_button_map[] = {
|
||||
WPAD_BUTTON_A, WPAD_BUTTON_B, WPAD_BUTTON_Z, WPAD_BUTTON_C,
|
||||
0, 0,
|
||||
WPAD_BUTTON_1, WPAD_BUTTON_2,
|
||||
0, 0,
|
||||
WPAD_BUTTON_PLUS, WPAD_BUTTON_MINUS,
|
||||
WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_RIGHT, WPAD_BUTTON_DOWN,
|
||||
WPAD_NUNCHUK_STICK_EMULATION_LEFT << 16, WPAD_NUNCHUK_STICK_EMULATION_UP << 16, WPAD_NUNCHUK_STICK_EMULATION_RIGHT << 16, WPAD_NUNCHUK_STICK_EMULATION_DOWN << 16,
|
||||
};
|
||||
|
||||
static uint32_t classic_button_map[] = {
|
||||
WPAD_CLASSIC_BUTTON_A, WPAD_CLASSIC_BUTTON_B, WPAD_CLASSIC_BUTTON_X,
|
||||
WPAD_CLASSIC_BUTTON_Y,
|
||||
0, 0,
|
||||
WPAD_CLASSIC_BUTTON_L, WPAD_CLASSIC_BUTTON_R,
|
||||
WPAD_CLASSIC_BUTTON_ZL, WPAD_CLASSIC_BUTTON_ZR,
|
||||
WPAD_CLASSIC_BUTTON_PLUS, WPAD_CLASSIC_BUTTON_MINUS,
|
||||
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_RIGHT,
|
||||
WPAD_CLASSIC_BUTTON_DOWN,
|
||||
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_RIGHT, WPAD_CLASSIC_BUTTON_DOWN,
|
||||
WPAD_CLASSIC_STICK_L_EMULATION_LEFT, WPAD_CLASSIC_STICK_L_EMULATION_UP, WPAD_CLASSIC_STICK_L_EMULATION_RIGHT, WPAD_CLASSIC_STICK_L_EMULATION_DOWN,
|
||||
WPAD_CLASSIC_STICK_R_EMULATION_LEFT, WPAD_CLASSIC_STICK_R_EMULATION_UP, WPAD_CLASSIC_STICK_R_EMULATION_RIGHT, WPAD_CLASSIC_STICK_R_EMULATION_DOWN,
|
||||
};
|
||||
|
||||
static WPADProButton pro_button_map[] = {
|
||||
static uint32_t pro_button_map[] = {
|
||||
WPAD_PRO_BUTTON_A, WPAD_PRO_BUTTON_B, WPAD_PRO_BUTTON_X, WPAD_PRO_BUTTON_Y,
|
||||
WPAD_PRO_BUTTON_STICK_L, WPAD_PRO_BUTTON_STICK_R,
|
||||
WPAD_PRO_TRIGGER_L, WPAD_PRO_TRIGGER_R,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user