early-access version 1667
This commit is contained in:
37
externals/SDL/src/joystick/SDL_gamecontroller.c
vendored
37
externals/SDL/src/joystick/SDL_gamecontroller.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -470,6 +470,10 @@ static int SDLCALL SDL_GameControllerEventWatcher(void *userdata, SDL_Event * ev
|
||||
*/
|
||||
static ControllerMapping_t *SDL_CreateMappingForAndroidController(SDL_JoystickGUID guid)
|
||||
{
|
||||
const int face_button_mask = ((1 << SDL_CONTROLLER_BUTTON_A) |
|
||||
(1 << SDL_CONTROLLER_BUTTON_B) |
|
||||
(1 << SDL_CONTROLLER_BUTTON_X) |
|
||||
(1 << SDL_CONTROLLER_BUTTON_Y));
|
||||
SDL_bool existing;
|
||||
char mapping_string[1024];
|
||||
int button_mask;
|
||||
@@ -481,6 +485,10 @@ static ControllerMapping_t *SDL_CreateMappingForAndroidController(SDL_JoystickGU
|
||||
/* Accelerometer, shouldn't have a game controller mapping */
|
||||
return NULL;
|
||||
}
|
||||
if (!(button_mask & face_button_mask) || !axis_mask) {
|
||||
/* We don't know what buttons or axes are supported, don't make up a mapping */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_strlcpy(mapping_string, "none,*,", sizeof(mapping_string));
|
||||
|
||||
@@ -574,18 +582,13 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
|
||||
|
||||
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
|
||||
|
||||
if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) {
|
||||
if ((vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) ||
|
||||
(vendor == USB_VENDOR_SHENZHEN && product == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER)) {
|
||||
/* GameCube driver has 12 buttons and 6 axes */
|
||||
SDL_strlcat(mapping_string, "a:b0,b:b1,dpdown:b6,dpleft:b4,dpright:b5,dpup:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,righttrigger:a5,rightx:a2,righty:a3,start:b8,x:b2,y:b3,", sizeof(mapping_string));
|
||||
} else {
|
||||
/* All other controllers have the standard set of 19 buttons and 6 axes */
|
||||
if (!SDL_IsJoystickNintendoSwitchPro(vendor, product) ||
|
||||
SDL_GetHintBoolean(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, SDL_TRUE)) {
|
||||
SDL_strlcat(mapping_string, "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,", sizeof(mapping_string));
|
||||
} else {
|
||||
/* Nintendo Switch Pro Controller with swapped face buttons to match Xbox Controller physical layout */
|
||||
SDL_strlcat(mapping_string, "a:b1,b:b0,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:b3,y:b2,", sizeof(mapping_string));
|
||||
}
|
||||
SDL_strlcat(mapping_string, "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,", sizeof(mapping_string));
|
||||
|
||||
if (SDL_IsJoystickXboxOneSeriesX(vendor, product)) {
|
||||
/* XBox One Series X Controllers have a share button under the guide button */
|
||||
@@ -604,13 +607,27 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_PS5:
|
||||
/* PS5 controllers have a microphone button and an additional touchpad button */
|
||||
SDL_strlcat(mapping_string, "misc1:b15,touchpad:b16", sizeof(mapping_string));
|
||||
SDL_strlcat(mapping_string, "touchpad:b15,misc1:b16", sizeof(mapping_string));
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
/* Nintendo Switch Pro controllers have a screenshot button */
|
||||
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
|
||||
/* Joy-Cons have extra buttons in the same place as paddles */
|
||||
if (SDL_IsJoystickNintendoSwitchJoyConLeft(vendor, product)) {
|
||||
SDL_strlcat(mapping_string, "paddle2:b17,paddle4:b19,", sizeof(mapping_string));
|
||||
}
|
||||
else if (SDL_IsJoystickNintendoSwitchJoyConRight(vendor, product)) {
|
||||
SDL_strlcat(mapping_string, "paddle1:b16,paddle3:b18,", sizeof(mapping_string));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (vendor == 0 && product == 0) {
|
||||
/* This is a Bluetooth Nintendo Switch Pro controller */
|
||||
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
|
||||
} else if (vendor == USB_VENDOR_GOOGLE && product == USB_PRODUCT_GOOGLE_STADIA_CONTROLLER) {
|
||||
/* The Google Stadia controller has a share button and a Google Assistant button */
|
||||
SDL_strlcat(mapping_string, "misc1:b15,", sizeof(mapping_string));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -375,6 +375,7 @@ static const char *s_ControllerMappings [] =
|
||||
"03000000a00500003232000008010000,8BitDo Zero Gamepad,a:b1,b:b2,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"03000000a00500003232000009010000,8BitDo Zero Gamepad,a:b0,b:b1,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"03000000a00500003232000009010000,8BitDo Zero Gamepad,a:b1,b:b0,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"03000000710100001904000000010000,Amazon Luna Gamepad,a:b0,b:b1,back:b11,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b9,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
"03000000c62400001a89000000010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b14,leftshoulder:b6,leftstick:b15,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b16,righttrigger:a4,rightx:a2,righty:a3,start:b13,x:b3,y:b4,",
|
||||
"03000000c62400001b89000000010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
|
||||
"03000000d62000002a79000000010000,BDA PS4 Fightpad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
|
||||
@@ -480,6 +481,7 @@ static const char *s_ControllerMappings [] =
|
||||
"03000000830500006020000000000000,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,back:b6,leftshoulder:b4,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b3,y:b2,",
|
||||
#endif
|
||||
#if defined(__LINUX__)
|
||||
"xinput,*,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"03000000c82d00000090000011010000,8BitDo FC30 Pro,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b3,y:b4,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"03000000c82d00000090000011010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
"05000000c82d00001038000000010000,8BitDo FC30 Pro,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,",
|
||||
@@ -535,6 +537,7 @@ static const char *s_ControllerMappings [] =
|
||||
"030000006f0e00001302000000010000,Afterglow,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"03000000100000008200000011010000,Akishop Customs PS360+ v1.66,a:b1,b:b2,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
|
||||
"05000000491900000204000021000000,Amazon Fire Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b17,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b12,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
|
||||
"05000000710100001904000000010000,Amazon Luna Gamepad,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b11,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
"03000000790000003018000011010000,Arcade Fightstick F300,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
|
||||
"03000000c62400001b89000011010000,BDA MOGA XP5-X Plus,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
|
||||
"03000000d62000002a79000011010000,BDA PS4 Fightpad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
|
||||
@@ -580,6 +583,7 @@ static const char *s_ControllerMappings [] =
|
||||
"03000000242e00008816000001010000,Hyperkin X91,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"03000000d80400008200000003000000,IMS PCU#0 Gamepad Interface,a:b1,b:b0,back:b4,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,start:b5,x:b3,y:b2,",
|
||||
"03000000fd0500000030000000010000,InterAct GoPad I-73000 (Fighting Game Layout),a:b3,b:b4,back:b6,leftx:a0,lefty:a1,rightshoulder:b2,righttrigger:b5,start:b7,x:b0,y:b1,",
|
||||
"05000000491900000204000000000000,Ipega PG-9087S,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
|
||||
"030000006e0500000320000010010000,JC-U3613M - DirectInput Mode,a:b2,b:b3,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3,start:b11,x:b0,y:b1,",
|
||||
"03000000300f00001001000010010000,Jess Tech Dual Analog Rumble Pad,a:b2,b:b3,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b0,y:b1,",
|
||||
"03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
|
||||
@@ -619,6 +623,7 @@ static const char *s_ControllerMappings [] =
|
||||
"030000005e040000d102000001010000,Microsoft X-Box One pad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"030000005e0400008502000000010000,Microsoft X-Box pad (Japan),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
|
||||
"030000005e0400008902000021010000,Microsoft X-Box pad v2 (US),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
|
||||
"030000005e0400008902000020010000,Microsoft Xbox Controller S,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b5,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b2,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b3,y:b4,",
|
||||
"05000000d6200000ad0d000001000000,Moga Pro,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
"030000006b140000010c000010010000,NACON GC-400ES,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
|
||||
"030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
|
||||
@@ -742,7 +747,6 @@ static const char *s_ControllerMappings [] =
|
||||
"030000005e040000a102000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"030000005e040000a102000007010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"03000000450c00002043000010010000,XEOX Gamepad SL-6556-BK,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
|
||||
"xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"0000000058626f782033363020576900,Xbox 360 Wireless Controller,a:b0,b:b1,back:b14,dpdown:b11,dpleft:b12,dpright:b13,dpup:b10,guide:b7,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
|
||||
"030000005e040000a102000014010000,Xbox 360 Wireless Receiver (XBOX),a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
|
||||
"0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
|
||||
@@ -807,6 +811,7 @@ static const char *s_ControllerMappings [] =
|
||||
"050000007e05000009200000ffff0f00,Nintendo Switch Pro Controller,a:b0,b:b1,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:b10,rightx:a2,righty:a3,start:b16,x:b17,y:b2,sdk<=:28,", /* Extremely slow in Bluetooth mode on Android */
|
||||
"050000004c05000068020000dfff3f00,PS3 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,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,",
|
||||
"030000004c050000cc09000000006800,PS4 Controller,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,",
|
||||
"050000004c050000c405000000783f00,PS4 Controller,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,",
|
||||
"050000004c050000c4050000fffe3f00,PS4 Controller,a:b1,b:b17,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:+a4,rightx:a2,righty:a5,start:b16,x:b0,y:b2,",
|
||||
"050000004c050000c4050000ffff3f00,PS4 Controller,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,",
|
||||
"050000004c050000cc090000fffe3f00,PS4 Controller,a:b1,b:b17,back:b15,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:a4,rightx:a2,righty:a5,start:b16,x:b0,y:b2,",
|
||||
@@ -817,7 +822,12 @@ static const char *s_ControllerMappings [] =
|
||||
"050000003215000007070000ffff3f00,Razer Raiju Mobile,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,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,",
|
||||
"050000003215000000090000bf7f3f00,Razer Serval,a:b0,b:b1,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,x:b2,y:b3,",
|
||||
"050000004f0400000ed00000fffe3f00,ThrustMaster eSwap PRO Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
"050000005e0400008e02000000783f00,Xbox 360 Controller,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,",
|
||||
"050000005e040000000b000000783f00,Xbox One Elite 2 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
|
||||
"050000005e040000e002000000783f00,Xbox One S Controller,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,",
|
||||
"050000005e040000ea02000000783f00,Xbox One S Controller,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,",
|
||||
"050000005e040000fd020000ff7f3f00,Xbox One S Controller,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,",
|
||||
"050000005e040000120b000000783f00,Xbox One Series X Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
|
||||
"050000005e040000130b0000ffff3f00,Xbox One Series X Controller,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,",
|
||||
"050000005e040000e00200000ffe3f00,Xbox One Wireless Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b3,leftstick:b15,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b16,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b17,y:b2,",
|
||||
"050000005e040000fd020000ffff3f00,Xbox One Wireless Controller,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,",
|
||||
@@ -833,9 +843,13 @@ static const char *s_ControllerMappings [] =
|
||||
"05000000ac05000001000000ff076d01,*,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
|
||||
"05000000ac050000020000004f066d02,*,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b4,rightshoulder:b5,x:b2,y:b3,",
|
||||
"050000004c050000cc090000df070000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
|
||||
"050000004c050000cc090000df870001,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
|
||||
"050000004c050000cc090000ff070000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
|
||||
"050000004c050000cc090000ff870001,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,touchpad:b11,x:b2,y:b3,",
|
||||
"050000004c050000e60c0000df870000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,touchpad:b10,x:b2,y:b3,",
|
||||
"050000004c050000e60c0000ff870000,PS5 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,touchpad:b11,x:b2,y:b3,",
|
||||
"05000000ac0500000300000043006d03,Remote,a:b0,b:b2,leftx:a0,lefty:a1,",
|
||||
"050000005e040000050b0000df070001,Xbox Elite Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b10,paddle2:b12,paddle3:b11,paddle4:b13,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
|
||||
"050000005e040000050b0000ff070001,Xbox Elite Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,paddle1:b11,paddle2:b13,paddle3:b12,paddle4:b14,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
|
||||
"050000005e040000e0020000df070000,Xbox Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b2,y:b3,",
|
||||
"050000005e040000e0020000ff070000,Xbox Wireless Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,",
|
||||
@@ -846,6 +860,10 @@ static const char *s_ControllerMappings [] =
|
||||
#if defined(SDL_JOYSTICK_EMSCRIPTEN)
|
||||
"default,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_VITA)
|
||||
"50535669746120436f6e74726f6c6c65,PSVita Controller,a:b2,b:b1,back:b10,dpdown:b6,dpleft:b7,dpright:b9,dpup:b8,leftshoulder:b4,leftstick:b14,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b15,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b3,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
|
||||
};
|
||||
|
||||
|
91
externals/SDL/src/joystick/SDL_joystick.c
vendored
91
externals/SDL/src/joystick/SDL_joystick.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -62,6 +62,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
|
||||
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
|
||||
&SDL_WINDOWS_JoystickDriver,
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_WINMM)
|
||||
&SDL_WINMM_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
&SDL_LINUX_JoystickDriver,
|
||||
#endif
|
||||
@@ -83,9 +86,18 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
|
||||
#ifdef SDL_JOYSTICK_USBHID /* !!! FIXME: "USBHID" is a generic name, and doubly-confusing with HIDAPI next to it. This is the *BSD interface, rename this. */
|
||||
&SDL_BSD_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_OS2
|
||||
&SDL_OS2_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_PSP
|
||||
&SDL_PSP_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_VIRTUAL
|
||||
&SDL_VIRTUAL_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_VITA
|
||||
&SDL_VITA_JoystickDriver
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED)
|
||||
&SDL_DUMMY_JoystickDriver
|
||||
#endif
|
||||
@@ -160,9 +172,6 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
|
||||
int device_index;
|
||||
int existing_player_index;
|
||||
|
||||
if (player_index < 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (player_index >= SDL_joystick_player_count) {
|
||||
SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players));
|
||||
if (!new_players) {
|
||||
@@ -184,7 +193,9 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
|
||||
SDL_joystick_players[existing_player_index] = -1;
|
||||
}
|
||||
|
||||
SDL_joystick_players[player_index] = instance_id;
|
||||
if (player_index >= 0) {
|
||||
SDL_joystick_players[player_index] = instance_id;
|
||||
}
|
||||
|
||||
/* Update the driver with the new index */
|
||||
device_index = SDL_JoystickGetDeviceIndexFromInstanceID(instance_id);
|
||||
@@ -341,7 +352,7 @@ SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
|
||||
Uint32 id = MAKE_VIDPID(SDL_JoystickGetVendor(joystick),
|
||||
SDL_JoystickGetProduct(joystick));
|
||||
|
||||
/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
|
||||
/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
|
||||
|
||||
if (joystick->naxes == 2) {
|
||||
/* Assume D-pad or thumbstick style axes are centered at 0 */
|
||||
@@ -405,6 +416,7 @@ SDL_JoystickOpen(int device_index)
|
||||
joystick->instance_id = instance_id;
|
||||
joystick->attached = SDL_TRUE;
|
||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
||||
joystick->led_expiration = SDL_GetTicks();
|
||||
|
||||
if (driver->Open(joystick, device_index) < 0) {
|
||||
SDL_free(joystick);
|
||||
@@ -943,6 +955,7 @@ int
|
||||
SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
int result;
|
||||
SDL_bool isfreshvalue;
|
||||
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
return -1;
|
||||
@@ -950,13 +963,17 @@ SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
|
||||
SDL_LockJoysticks();
|
||||
|
||||
if (red == joystick->led_red &&
|
||||
green == joystick->led_green &&
|
||||
blue == joystick->led_blue) {
|
||||
isfreshvalue = red != joystick->led_red ||
|
||||
green != joystick->led_green ||
|
||||
blue != joystick->led_blue;
|
||||
|
||||
if ( isfreshvalue || SDL_TICKS_PASSED( SDL_GetTicks(), joystick->led_expiration ) ) {
|
||||
result = joystick->driver->SetLED(joystick, red, green, blue);
|
||||
joystick->led_expiration = SDL_GetTicks() + SDL_LED_MIN_REPEAT_MS;
|
||||
}
|
||||
else {
|
||||
/* Avoid spamming the driver */
|
||||
result = 0;
|
||||
} else {
|
||||
result = joystick->driver->SetLED(joystick, red, green, blue);
|
||||
}
|
||||
|
||||
/* Save the LED value regardless of success, so we don't spam the driver */
|
||||
@@ -1247,7 +1264,6 @@ SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
|
||||
SDL_PrivateJoystickTouchpad(joystick, i, j, SDL_RELEASED, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
||||
@@ -1805,7 +1821,9 @@ SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 produc
|
||||
0x15e4, /* Numark */
|
||||
0x162e, /* Joytech */
|
||||
0x1689, /* Razer Onza */
|
||||
0x1949, /* Lab126, Inc. */
|
||||
0x1bad, /* Harmonix */
|
||||
0x20d6, /* PowerA */
|
||||
0x24c6, /* PowerA */
|
||||
};
|
||||
|
||||
@@ -1829,6 +1847,7 @@ SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 produc
|
||||
0x0e6f, /* PDP */
|
||||
0x0f0d, /* Hori */
|
||||
0x1532, /* Razer Wildcat */
|
||||
0x20d6, /* PowerA */
|
||||
0x24c6, /* PowerA */
|
||||
0x2e24, /* Hyperkin */
|
||||
};
|
||||
@@ -1881,6 +1900,10 @@ SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 produc
|
||||
case k_eControllerType_SwitchInputOnlyController:
|
||||
type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
|
||||
break;
|
||||
case k_eControllerType_SwitchJoyConLeft:
|
||||
case k_eControllerType_SwitchJoyConRight:
|
||||
type = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_FALSE) ? SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO : SDL_CONTROLLER_TYPE_UNKNOWN;
|
||||
break;
|
||||
default:
|
||||
type = SDL_CONTROLLER_TYPE_UNKNOWN;
|
||||
break;
|
||||
@@ -1912,6 +1935,25 @@ SDL_IsJoystickXboxOneSeriesX(Uint16 vendor_id, Uint16 product_id)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
if (vendor_id == USB_VENDOR_POWERA_ALT) {
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_SERIES_X_POWERA) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
if (vendor_id == USB_VENDOR_MICROSOFT) {
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_S_REV2_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -1944,6 +1986,28 @@ SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id)
|
||||
return (eType == k_eControllerType_SwitchInputOnlyController);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
EControllerType eType = GuessControllerType(vendor_id, product_id);
|
||||
return (eType == k_eControllerType_SwitchJoyConLeft ||
|
||||
eType == k_eControllerType_SwitchJoyConRight);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
EControllerType eType = GuessControllerType(vendor_id, product_id);
|
||||
return (eType == k_eControllerType_SwitchJoyConLeft);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
EControllerType eType = GuessControllerType(vendor_id, product_id);
|
||||
return (eType == k_eControllerType_SwitchJoyConRight);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
@@ -1991,7 +2055,8 @@ static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
|
||||
MAKE_VIDPID(0x046d, 0xc299), /* Logitech G25 */
|
||||
MAKE_VIDPID(0x046d, 0xc29a), /* Logitech Driving Force GT */
|
||||
MAKE_VIDPID(0x046d, 0xc29b), /* Logitech G27 */
|
||||
MAKE_VIDPID(0x046d, 0xc24f), /* Logitech G29 */
|
||||
MAKE_VIDPID(0x046d, 0xc24f), /* Logitech G29 (PS3) */
|
||||
MAKE_VIDPID(0x046d, 0xc260), /* Logitech G29 (PS4) */
|
||||
MAKE_VIDPID(0x046d, 0xc261), /* Logitech G920 (initial mode) */
|
||||
MAKE_VIDPID(0x046d, 0xc262), /* Logitech G920 (active mode) */
|
||||
MAKE_VIDPID(0x044f, 0xb65d), /* Thrustmaster Wheel FFB */
|
||||
|
8
externals/SDL/src/joystick/SDL_joystick_c.h
vendored
8
externals/SDL/src/joystick/SDL_joystick_c.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -68,6 +68,9 @@ extern SDL_bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id);
|
||||
/* Function to return whether a joystick is an Xbox One Series X controller */
|
||||
extern SDL_bool SDL_IsJoystickXboxOneSeriesX(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
/* Function to return whether a joystick is an Xbox One controller connected via Bluetooth */
|
||||
extern SDL_bool SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
/* Function to return whether a joystick is a PS4 controller */
|
||||
extern SDL_bool SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
@@ -77,6 +80,9 @@ extern SDL_bool SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id);
|
||||
/* Function to return whether a joystick is a Nintendo Switch Pro controller */
|
||||
extern SDL_bool SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id);
|
||||
extern SDL_bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id);
|
||||
extern SDL_bool SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id);
|
||||
extern SDL_bool SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id);
|
||||
extern SDL_bool SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
/* Function to return whether a joystick is a Steam Controller */
|
||||
extern SDL_bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
|
||||
|
10
externals/SDL/src/joystick/SDL_sysjoystick.h
vendored
10
externals/SDL/src/joystick/SDL_sysjoystick.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -24,7 +24,6 @@
|
||||
#define SDL_sysjoystick_h_
|
||||
|
||||
/* This is the system specific header for the SDL joystick API */
|
||||
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_joystick_c.h"
|
||||
|
||||
@@ -100,6 +99,7 @@ struct _SDL_Joystick
|
||||
Uint8 led_red;
|
||||
Uint8 led_green;
|
||||
Uint8 led_blue;
|
||||
Uint32 led_expiration;
|
||||
|
||||
SDL_bool attached;
|
||||
SDL_bool is_game_controller;
|
||||
@@ -190,6 +190,8 @@ typedef struct _SDL_JoystickDriver
|
||||
/* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */
|
||||
#define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF
|
||||
|
||||
#define SDL_LED_MIN_REPEAT_MS 5000
|
||||
|
||||
/* The available joystick drivers */
|
||||
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
|
||||
@@ -204,6 +206,10 @@ extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_VITA_JoystickDriver;
|
||||
|
||||
#endif /* SDL_sysjoystick_h_ */
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -69,7 +69,7 @@
|
||||
#include <sys/joystick.h>
|
||||
#endif
|
||||
|
||||
#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
|
||||
#if SDL_HAVE_MACHINE_JOYSTICK_H
|
||||
#include <machine/joystick.h>
|
||||
#endif
|
||||
|
||||
@@ -546,7 +546,7 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
|
||||
Sint32 dpad[4] = {0, 0, 0, 0};
|
||||
#endif
|
||||
|
||||
#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H || defined(__FreeBSD_kernel__) || defined(__DragonFly_)
|
||||
#if defined(__FREEBSD__) || SDL_HAVE_MACHINE_JOYSTICK_H || defined(__FreeBSD_kernel__) || defined(__DragonFly_)
|
||||
struct joystick gameport;
|
||||
static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
|
||||
|
||||
@@ -591,7 +591,7 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
|
||||
#endif /* defined(__FREEBSD__) || SDL_HAVE_MACHINE_JOYSTICK_H */
|
||||
|
||||
rep = &joy->hwdata->inreport;
|
||||
|
||||
|
16
externals/SDL/src/joystick/controller_type.h
vendored
16
externals/SDL/src/joystick/controller_type.h
vendored
@@ -181,6 +181,7 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x0079, 0x0006 ), k_eControllerType_UnknownNonSteamController, NULL }, // DragonRise Generic USB PCB, sometimes configured as a PC Twin Shock Controller - looks like a DS3 but the face buttons are 1-4 instead of symbols
|
||||
|
||||
{ MAKE_CONTROLLER_ID( 0x0079, 0x18d4 ), k_eControllerType_XBox360Controller, NULL }, // GPD Win 2 X-Box Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x03eb, 0xff02 ), k_eControllerType_XBox360Controller, NULL }, // Wooting Two
|
||||
{ MAKE_CONTROLLER_ID( 0x044f, 0xb326 ), k_eControllerType_XBox360Controller, NULL }, // Thrustmaster Gamepad GP XID
|
||||
{ MAKE_CONTROLLER_ID( 0x045e, 0x028e ), k_eControllerType_XBox360Controller, "Xbox 360 Controller" }, // Microsoft X-Box 360 pad
|
||||
{ MAKE_CONTROLLER_ID( 0x045e, 0x028f ), k_eControllerType_XBox360Controller, "Xbox 360 Controller" }, // Microsoft X-Box 360 pad v2
|
||||
@@ -254,6 +255,7 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x1689, 0xfd00 ), k_eControllerType_XBox360Controller, NULL }, // Razer Onza Tournament Edition
|
||||
{ MAKE_CONTROLLER_ID( 0x1689, 0xfd01 ), k_eControllerType_XBox360Controller, NULL }, // Razer Onza Classic Edition
|
||||
{ MAKE_CONTROLLER_ID( 0x1689, 0xfe00 ), k_eControllerType_XBox360Controller, NULL }, // Razer Sabertooth
|
||||
{ MAKE_CONTROLLER_ID( 0x1949, 0x041a ), k_eControllerType_XBox360Controller, "Amazon Luna Gamepad" }, // Amazon Luna Gamepad
|
||||
{ MAKE_CONTROLLER_ID( 0x1bad, 0x0002 ), k_eControllerType_XBox360Controller, NULL }, // Harmonix Rock Band Guitar
|
||||
{ MAKE_CONTROLLER_ID( 0x1bad, 0x0003 ), k_eControllerType_XBox360Controller, NULL }, // Harmonix Rock Band Drumkit
|
||||
{ MAKE_CONTROLLER_ID( 0x1bad, 0xf016 ), k_eControllerType_XBox360Controller, NULL }, // Mad Catz Xbox 360 Controller
|
||||
@@ -397,9 +399,10 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x1532, 0x0a00 ), k_eControllerType_XBoxOneController, NULL }, // Razer Atrox Arcade Stick
|
||||
{ MAKE_CONTROLLER_ID( 0x1532, 0x0a03 ), k_eControllerType_XBoxOneController, NULL }, // Razer Wildcat
|
||||
{ MAKE_CONTROLLER_ID( 0x1532, 0x0a14 ), k_eControllerType_XBoxOneController, NULL }, // Razer Wolverine Ultimate
|
||||
{ MAKE_CONTROLLER_ID( 0x20d6, 0x2001 ), k_eControllerType_XBoxOneController, "PowerA Xbox One Series X Controller" }, // PowerA Xbox One Series X Wired Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x541a ), k_eControllerType_XBoxOneController, NULL }, // PowerA Xbox One Mini Wired Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x542a ), k_eControllerType_XBoxOneController, NULL }, // Xbox ONE spectra
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x543a ), k_eControllerType_XBoxOneController, "PowerA XBox One Controller" }, // PowerA Xbox ONE liquid metal controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x543a ), k_eControllerType_XBoxOneController, "PowerA Xbox One Controller" }, // PowerA Xbox ONE liquid metal controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x551a ), k_eControllerType_XBoxOneController, NULL }, // PowerA FUSION Pro Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x561a ), k_eControllerType_XBoxOneController, NULL }, // PowerA FUSION Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x24c6, 0x581a ), k_eControllerType_XBoxOneController, NULL }, // BDA XB1 Classic Controller
|
||||
@@ -450,7 +453,6 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x2f24, 0x91 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x1430, 0x719 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0xf0d, 0xed ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x3eb, 0xff02 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0xf0d, 0xc0 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0xe6f, 0x152 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
{ MAKE_CONTROLLER_ID( 0xe6f, 0x2a7 ), k_eControllerType_XBoxOneController, NULL }, // Unknown Controller
|
||||
@@ -522,11 +524,9 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x05ac, 0x0001 ), k_eControllerType_AppleController, NULL }, // MFI Extended Gamepad (generic entry for iOS/tvOS)
|
||||
{ MAKE_CONTROLLER_ID( 0x05ac, 0x0002 ), k_eControllerType_AppleController, NULL }, // MFI Standard Gamepad (generic entry for iOS/tvOS)
|
||||
|
||||
// We currently don't support using a pair of Switch Joy-Con's as a single
|
||||
// controller and we don't want to support using them individually for the
|
||||
// time being, so these should be disabled until one of the above is true
|
||||
// { MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft, NULL }, // Nintendo Switch Joy-Con (Left)
|
||||
// { MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight, NULL }, // Nintendo Switch Joy-Con (Right)
|
||||
// We now support Joy-Cons if SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS is set to "1", but they won't be combined into one controller.
|
||||
{ MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft, NULL }, // Nintendo Switch Joy-Con (Left)
|
||||
{ MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight, NULL }, // Nintendo Switch Joy-Con (Right)
|
||||
|
||||
// This same controller ID is spoofed by many 3rd-party Switch controllers.
|
||||
// The ones we currently know of are:
|
||||
@@ -554,7 +554,7 @@ static const ControllerDescription_t arrControllers[] = {
|
||||
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0184 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Faceoff Wired Deluxe+ Audio Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x0f0d, 0x00aa ), k_eControllerType_SwitchInputOnlyController, NULL }, // HORI Real Arcade Pro V Hayabusa in Switch Mode
|
||||
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0188 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Afterglow Wired Deluxe+ Audio Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0187 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Rockcandy Wirec Controller
|
||||
{ MAKE_CONTROLLER_ID( 0x0e6f, 0x0187 ), k_eControllerType_SwitchInputOnlyController, NULL }, // PDP Rockcandy Wired Controller
|
||||
|
||||
// Valve products - don't add to public list
|
||||
{ MAKE_CONTROLLER_ID( 0x0000, 0x11fb ), k_eControllerType_MobileTouch, NULL }, // Streaming mobile touch virtual controls
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -152,14 +152,17 @@ FreeDevice(recDevice *removeDevice)
|
||||
/* save next device prior to disposing of this device */
|
||||
pDeviceNext = removeDevice->pNext;
|
||||
|
||||
if ( gpDeviceList == removeDevice ) {
|
||||
if (gpDeviceList == removeDevice) {
|
||||
gpDeviceList = pDeviceNext;
|
||||
} else if (gpDeviceList) {
|
||||
recDevice *device = gpDeviceList;
|
||||
while (device->pNext != removeDevice) {
|
||||
device = device->pNext;
|
||||
recDevice *device;
|
||||
|
||||
for (device = gpDeviceList; device; device = device->pNext) {
|
||||
if (device->pNext == removeDevice) {
|
||||
device->pNext = pDeviceNext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
device->pNext = pDeviceNext;
|
||||
}
|
||||
removeDevice->pNext = NULL;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -32,13 +32,18 @@
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
#include "../../hidapi/SDL_hidapi.h"
|
||||
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
|
||||
/* Define this if you want to log all packets from the controller */
|
||||
/*#define DEBUG_GAMECUBE_PROTOCOL*/
|
||||
|
||||
#define MAX_CONTROLLERS 4
|
||||
|
||||
typedef struct {
|
||||
SDL_bool pc_mode;
|
||||
SDL_JoystickID joysticks[MAX_CONTROLLERS];
|
||||
Uint8 wireless[MAX_CONTROLLERS];
|
||||
Uint8 min_axis[MAX_CONTROLLERS*SDL_CONTROLLER_AXIS_MAX];
|
||||
@@ -57,6 +62,10 @@ HIDAPI_DriverGameCube_IsSupportedDevice(const char *name, SDL_GameControllerType
|
||||
/* Nintendo Co., Ltd. Wii U GameCube Controller Adapter */
|
||||
return SDL_TRUE;
|
||||
}
|
||||
if (vendor_id == USB_VENDOR_SHENZHEN && product_id == USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER) {
|
||||
/* EVORETRO GameCube Controller Adapter */
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -77,25 +86,6 @@ ResetAxisRange(SDL_DriverGameCube_Context *ctx, int joystick_index)
|
||||
ctx->min_axis[joystick_index*SDL_CONTROLLER_AXIS_MAX+SDL_CONTROLLER_AXIS_TRIGGERRIGHT] = 40;
|
||||
}
|
||||
|
||||
static float fsel(float fComparand, float fValGE, float fLT)
|
||||
{
|
||||
return fComparand >= 0 ? fValGE : fLT;
|
||||
}
|
||||
|
||||
static float RemapVal(float val, float A, float B, float C, float D)
|
||||
{
|
||||
if (A == B) {
|
||||
return fsel(val - B , D , C);
|
||||
}
|
||||
if (val < A) {
|
||||
val = A;
|
||||
}
|
||||
if (val > B) {
|
||||
val = B;
|
||||
}
|
||||
return C + (D - C) * (val - A) / (B - A);
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_GameControllerButtonReportingHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)userdata;
|
||||
@@ -129,6 +119,10 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
Uint8 initMagic = 0x13;
|
||||
Uint8 rumbleMagic = 0x11;
|
||||
|
||||
#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
|
||||
SDL_EnableGameCubeAdaptors();
|
||||
#endif
|
||||
|
||||
ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
SDL_OutOfMemory();
|
||||
@@ -149,40 +143,54 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
ctx->joysticks[3] = -1;
|
||||
ctx->rumble[0] = rumbleMagic;
|
||||
|
||||
/* This is all that's needed to initialize the device. Really! */
|
||||
if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
|
||||
SDL_SetError("Couldn't initialize WUP-028");
|
||||
goto error;
|
||||
if (device->vendor_id != USB_VENDOR_NINTENDO) {
|
||||
ctx->pc_mode = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Wait for the adapter to initialize */
|
||||
SDL_Delay(10);
|
||||
|
||||
/* Add all the applicable joysticks */
|
||||
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
if (size < 37 || packet[0] != 0x21) {
|
||||
continue; /* Nothing to do yet...? */
|
||||
if (ctx->pc_mode) {
|
||||
for (i = 0; i < MAX_CONTROLLERS; ++i) {
|
||||
ResetAxisRange(ctx, i);
|
||||
HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
|
||||
}
|
||||
} else {
|
||||
/* This is all that's needed to initialize the device. Really! */
|
||||
if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
|
||||
SDL_SetError("Couldn't initialize WUP-028");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Go through all 4 slots */
|
||||
curSlot = packet + 1;
|
||||
for (i = 0; i < MAX_CONTROLLERS; i += 1, curSlot += 9) {
|
||||
ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
|
||||
/* Wait for the adapter to initialize */
|
||||
SDL_Delay(10);
|
||||
|
||||
/* Only allow rumble if the adapter's second USB cable is connected */
|
||||
ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
|
||||
/* Add all the applicable joysticks */
|
||||
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
#ifdef DEBUG_GAMECUBE_PROTOCOL
|
||||
HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
|
||||
#endif
|
||||
if (size < 37 || packet[0] != 0x21) {
|
||||
continue; /* Nothing to do yet...? */
|
||||
}
|
||||
|
||||
if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
|
||||
if (ctx->joysticks[i] == -1) {
|
||||
ResetAxisRange(ctx, i);
|
||||
HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
|
||||
/* Go through all 4 slots */
|
||||
curSlot = packet + 1;
|
||||
for (i = 0; i < MAX_CONTROLLERS; i += 1, curSlot += 9) {
|
||||
ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
|
||||
|
||||
/* Only allow rumble if the adapter's second USB cable is connected */
|
||||
ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
|
||||
|
||||
if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
|
||||
if (ctx->joysticks[i] == -1) {
|
||||
ResetAxisRange(ctx, i);
|
||||
HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
|
||||
}
|
||||
} else {
|
||||
if (ctx->joysticks[i] != -1) {
|
||||
HIDAPI_JoystickDisconnected(device, ctx->joysticks[i]);
|
||||
ctx->joysticks[i] = -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (ctx->joysticks[i] != -1) {
|
||||
HIDAPI_JoystickDisconnected(device, ctx->joysticks[i]);
|
||||
ctx->joysticks[i] = -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,14 +201,19 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_TRUE;
|
||||
|
||||
error:
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -223,90 +236,167 @@ HIDAPI_DriverGameCube_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, Uint8 *packet, int size)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
Uint8 i, v;
|
||||
Sint16 axis_value;
|
||||
|
||||
if (size != 10) {
|
||||
return; /* How do we handle this packet? */
|
||||
}
|
||||
|
||||
i = packet[0] - 1;
|
||||
if (i >= MAX_CONTROLLERS) {
|
||||
return; /* How do we handle this packet? */
|
||||
}
|
||||
|
||||
joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
|
||||
if (!joystick) {
|
||||
/* Hasn't been opened yet, skip */
|
||||
return;
|
||||
}
|
||||
|
||||
#define READ_BUTTON(off, flag, button) \
|
||||
SDL_PrivateJoystickButton( \
|
||||
joystick, \
|
||||
RemapButton(ctx, button), \
|
||||
(packet[off] & flag) ? SDL_PRESSED : SDL_RELEASED \
|
||||
);
|
||||
READ_BUTTON(1, 0x02, 0) /* A */
|
||||
READ_BUTTON(1, 0x04, 1) /* B */
|
||||
READ_BUTTON(1, 0x01, 2) /* X */
|
||||
READ_BUTTON(1, 0x08, 3) /* Y */
|
||||
READ_BUTTON(2, 0x80, 4) /* DPAD_LEFT */
|
||||
READ_BUTTON(2, 0x20, 5) /* DPAD_RIGHT */
|
||||
READ_BUTTON(2, 0x40, 6) /* DPAD_DOWN */
|
||||
READ_BUTTON(2, 0x10, 7) /* DPAD_UP */
|
||||
READ_BUTTON(2, 0x02, 8) /* START */
|
||||
READ_BUTTON(1, 0x80, 9) /* RIGHTSHOULDER */
|
||||
/* These two buttons are for the bottoms of the analog triggers.
|
||||
* More than likely, you're going to want to read the axes instead!
|
||||
* -flibit
|
||||
*/
|
||||
READ_BUTTON(1, 0x20, 10) /* TRIGGERRIGHT */
|
||||
READ_BUTTON(1, 0x10, 11) /* TRIGGERLEFT */
|
||||
#undef READ_BUTTON
|
||||
|
||||
#define READ_AXIS(off, axis, invert) \
|
||||
v = invert ? (0xff - packet[off]) : packet[off]; \
|
||||
if (v < ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = v; \
|
||||
if (v > ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = v; \
|
||||
axis_value = (Sint16)HIDAPI_RemapVal(v, ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
|
||||
SDL_PrivateJoystickAxis( \
|
||||
joystick, \
|
||||
axis, axis_value \
|
||||
);
|
||||
READ_AXIS(3, SDL_CONTROLLER_AXIS_LEFTX, 0)
|
||||
READ_AXIS(4, SDL_CONTROLLER_AXIS_LEFTY, 0)
|
||||
READ_AXIS(6, SDL_CONTROLLER_AXIS_RIGHTX, 1)
|
||||
READ_AXIS(5, SDL_CONTROLLER_AXIS_RIGHTY, 1)
|
||||
READ_AXIS(7, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0)
|
||||
READ_AXIS(8, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0)
|
||||
#undef READ_AXIS
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverGameCube_HandleNintendoPacket(SDL_HIDAPI_Device *device, SDL_DriverGameCube_Context *ctx, Uint8 *packet, int size)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
Uint8 *curSlot;
|
||||
Uint8 i;
|
||||
Sint16 axis_value;
|
||||
|
||||
if (size < 37 || packet[0] != 0x21) {
|
||||
return; /* Nothing to do right now...? */
|
||||
}
|
||||
|
||||
/* Go through all 4 slots */
|
||||
curSlot = packet + 1;
|
||||
for (i = 0; i < MAX_CONTROLLERS; i += 1, curSlot += 9) {
|
||||
ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
|
||||
|
||||
/* Only allow rumble if the adapter's second USB cable is connected */
|
||||
ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
|
||||
|
||||
if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
|
||||
if (ctx->joysticks[i] == -1) {
|
||||
ResetAxisRange(ctx, i);
|
||||
HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
|
||||
}
|
||||
joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
|
||||
|
||||
/* Hasn't been opened yet, skip */
|
||||
if (joystick == NULL) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (ctx->joysticks[i] != -1) {
|
||||
HIDAPI_JoystickDisconnected(device, ctx->joysticks[i]);
|
||||
ctx->joysticks[i] = -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
#define READ_BUTTON(off, flag, button) \
|
||||
SDL_PrivateJoystickButton( \
|
||||
joystick, \
|
||||
RemapButton(ctx, button), \
|
||||
(curSlot[off] & flag) ? SDL_PRESSED : SDL_RELEASED \
|
||||
);
|
||||
READ_BUTTON(1, 0x01, 0) /* A */
|
||||
READ_BUTTON(1, 0x04, 1) /* B */
|
||||
READ_BUTTON(1, 0x02, 2) /* X */
|
||||
READ_BUTTON(1, 0x08, 3) /* Y */
|
||||
READ_BUTTON(1, 0x10, 4) /* DPAD_LEFT */
|
||||
READ_BUTTON(1, 0x20, 5) /* DPAD_RIGHT */
|
||||
READ_BUTTON(1, 0x40, 6) /* DPAD_DOWN */
|
||||
READ_BUTTON(1, 0x80, 7) /* DPAD_UP */
|
||||
READ_BUTTON(2, 0x01, 8) /* START */
|
||||
READ_BUTTON(2, 0x02, 9) /* RIGHTSHOULDER */
|
||||
/* These two buttons are for the bottoms of the analog triggers.
|
||||
* More than likely, you're going to want to read the axes instead!
|
||||
* -flibit
|
||||
*/
|
||||
READ_BUTTON(2, 0x04, 10) /* TRIGGERRIGHT */
|
||||
READ_BUTTON(2, 0x08, 11) /* TRIGGERLEFT */
|
||||
#undef READ_BUTTON
|
||||
|
||||
#define READ_AXIS(off, axis) \
|
||||
if (curSlot[off] < ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = curSlot[off]; \
|
||||
if (curSlot[off] > ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = curSlot[off]; \
|
||||
axis_value = (Sint16)HIDAPI_RemapVal(curSlot[off], ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], SDL_MIN_SINT16, SDL_MAX_SINT16); \
|
||||
SDL_PrivateJoystickAxis( \
|
||||
joystick, \
|
||||
axis, axis_value \
|
||||
);
|
||||
READ_AXIS(3, SDL_CONTROLLER_AXIS_LEFTX)
|
||||
READ_AXIS(4, SDL_CONTROLLER_AXIS_LEFTY)
|
||||
READ_AXIS(5, SDL_CONTROLLER_AXIS_RIGHTX)
|
||||
READ_AXIS(6, SDL_CONTROLLER_AXIS_RIGHTY)
|
||||
READ_AXIS(7, SDL_CONTROLLER_AXIS_TRIGGERLEFT)
|
||||
READ_AXIS(8, SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
|
||||
#undef READ_AXIS
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context;
|
||||
SDL_Joystick *joystick;
|
||||
Uint8 packet[37];
|
||||
Uint8 *curSlot;
|
||||
Uint8 i;
|
||||
Sint16 axis_value;
|
||||
Uint8 packet[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
|
||||
/* Read input packet */
|
||||
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
if (size < 37 || packet[0] != 0x21) {
|
||||
continue; /* Nothing to do right now...? */
|
||||
}
|
||||
|
||||
/* Go through all 4 slots */
|
||||
curSlot = packet + 1;
|
||||
for (i = 0; i < MAX_CONTROLLERS; i += 1, curSlot += 9) {
|
||||
ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
|
||||
|
||||
/* Only allow rumble if the adapter's second USB cable is connected */
|
||||
ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
|
||||
|
||||
if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
|
||||
if (ctx->joysticks[i] == -1) {
|
||||
ResetAxisRange(ctx, i);
|
||||
HIDAPI_JoystickConnected(device, &ctx->joysticks[i]);
|
||||
}
|
||||
joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
|
||||
|
||||
/* Hasn't been opened yet, skip */
|
||||
if (joystick == NULL) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (ctx->joysticks[i] != -1) {
|
||||
HIDAPI_JoystickDisconnected(device, ctx->joysticks[i]);
|
||||
ctx->joysticks[i] = -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
#define READ_BUTTON(off, flag, button) \
|
||||
SDL_PrivateJoystickButton( \
|
||||
joystick, \
|
||||
RemapButton(ctx, button), \
|
||||
(curSlot[off] & flag) ? SDL_PRESSED : SDL_RELEASED \
|
||||
);
|
||||
READ_BUTTON(1, 0x01, 0) /* A */
|
||||
READ_BUTTON(1, 0x04, 1) /* B */
|
||||
READ_BUTTON(1, 0x02, 2) /* X */
|
||||
READ_BUTTON(1, 0x08, 3) /* Y */
|
||||
READ_BUTTON(1, 0x10, 4) /* DPAD_LEFT */
|
||||
READ_BUTTON(1, 0x20, 5) /* DPAD_RIGHT */
|
||||
READ_BUTTON(1, 0x40, 6) /* DPAD_DOWN */
|
||||
READ_BUTTON(1, 0x80, 7) /* DPAD_UP */
|
||||
READ_BUTTON(2, 0x01, 8) /* START */
|
||||
READ_BUTTON(2, 0x02, 9) /* RIGHTSHOULDER */
|
||||
/* These two buttons are for the bottoms of the analog triggers.
|
||||
* More than likely, you're going to want to read the axes instead!
|
||||
* -flibit
|
||||
*/
|
||||
READ_BUTTON(2, 0x04, 10) /* TRIGGERRIGHT */
|
||||
READ_BUTTON(2, 0x08, 11) /* TRIGGERLEFT */
|
||||
#undef READ_BUTTON
|
||||
|
||||
#define READ_AXIS(off, axis) \
|
||||
if (axis < SDL_CONTROLLER_AXIS_TRIGGERLEFT) \
|
||||
if (curSlot[off] < ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = curSlot[off]; \
|
||||
if (curSlot[off] > ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis]) ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis] = curSlot[off]; \
|
||||
axis_value = (Sint16)(RemapVal(curSlot[off], ctx->min_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], ctx->max_axis[i*SDL_CONTROLLER_AXIS_MAX+axis], SDL_MIN_SINT16, SDL_MAX_SINT16)); \
|
||||
SDL_PrivateJoystickAxis( \
|
||||
joystick, \
|
||||
axis, axis_value \
|
||||
);
|
||||
READ_AXIS(3, SDL_CONTROLLER_AXIS_LEFTX)
|
||||
READ_AXIS(4, SDL_CONTROLLER_AXIS_LEFTY)
|
||||
READ_AXIS(5, SDL_CONTROLLER_AXIS_RIGHTX)
|
||||
READ_AXIS(6, SDL_CONTROLLER_AXIS_RIGHTY)
|
||||
READ_AXIS(7, SDL_CONTROLLER_AXIS_TRIGGERLEFT)
|
||||
READ_AXIS(8, SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
|
||||
#undef READ_AXIS
|
||||
#ifdef DEBUG_GAMECUBE_PROTOCOL
|
||||
//HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
|
||||
#endif
|
||||
if (ctx->pc_mode) {
|
||||
HIDAPI_DriverGameCube_HandleJoystickPacket(device, ctx, packet, size);
|
||||
} else {
|
||||
HIDAPI_DriverGameCube_HandleNintendoPacket(device, ctx, packet, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +431,11 @@ HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *jo
|
||||
{
|
||||
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context;
|
||||
Uint8 i, val;
|
||||
|
||||
if (ctx->pc_mode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_CONTROLLERS; i += 1) {
|
||||
if (joystick->instance_id == ctx->joysticks[i]) {
|
||||
if (ctx->wireless[i]) {
|
||||
@@ -404,14 +499,18 @@ HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context;
|
||||
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS,
|
||||
SDL_GameControllerButtonReportingHintChanged, ctx);
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
|
||||
|
153
externals/SDL/src/joystick/hidapi/SDL_hidapi_ps4.c
vendored
153
externals/SDL/src/joystick/hidapi/SDL_hidapi_ps4.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "../../SDL_hints_c.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
@@ -45,6 +46,7 @@
|
||||
|
||||
#define GYRO_RES_PER_DEGREE 1024.0f
|
||||
#define ACCEL_RES_PER_G 8192.0f
|
||||
#define BLUETOOTH_DISCONNECT_TIMEOUT_MS 500
|
||||
|
||||
#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8))
|
||||
|
||||
@@ -119,14 +121,18 @@ typedef struct {
|
||||
} IMUCalibrationData;
|
||||
|
||||
typedef struct {
|
||||
SDL_HIDAPI_Device *device;
|
||||
SDL_Joystick *joystick;
|
||||
SDL_bool is_dongle;
|
||||
SDL_bool is_bluetooth;
|
||||
SDL_bool official_controller;
|
||||
SDL_bool audio_supported;
|
||||
SDL_bool effects_supported;
|
||||
SDL_bool enhanced_mode;
|
||||
SDL_bool report_sensors;
|
||||
SDL_bool hardware_calibration;
|
||||
IMUCalibrationData calibration[6];
|
||||
Uint32 last_packet;
|
||||
int player_index;
|
||||
Uint8 rumble_left;
|
||||
Uint8 rumble_right;
|
||||
@@ -387,6 +393,10 @@ HIDAPI_DriverPS4_UpdateEffects(SDL_HIDAPI_Device *device)
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
SDL_zero(data);
|
||||
|
||||
if (ctx->is_bluetooth) {
|
||||
@@ -432,6 +442,46 @@ HIDAPI_DriverPS4_UpdateEffects(SDL_HIDAPI_Device *device)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS4_TickleBluetooth(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
/* This is just a dummy packet that should have no effect, since we don't set the CRC */
|
||||
Uint8 data[78];
|
||||
|
||||
SDL_zero(data);
|
||||
|
||||
data[0] = k_EPS4ReportIdBluetoothEffects;
|
||||
data[1] = 0xC0; /* Magic value HID + CRC */
|
||||
|
||||
SDL_HIDAPI_SendRumble(device, data, sizeof(data));
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS4_SetEnhancedMode(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
ctx->enhanced_mode = SDL_TRUE;
|
||||
|
||||
SDL_PrivateJoystickAddTouchpad(joystick, 2);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
|
||||
|
||||
HIDAPI_DriverPS4_UpdateEffects(device);
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_PS4RumbleHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)userdata;
|
||||
|
||||
/* This is a one-way trip, you can't switch the controller back to simple report mode */
|
||||
if (SDL_GetStringBoolean(hint, SDL_FALSE)) {
|
||||
HIDAPI_DriverPS4_SetEnhancedMode(ctx->device, ctx->joystick);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS4_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
|
||||
{
|
||||
@@ -451,12 +501,16 @@ static SDL_bool
|
||||
HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS4_Context *ctx;
|
||||
SDL_bool enhanced_mode = SDL_FALSE;
|
||||
|
||||
ctx = (SDL_DriverPS4_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
SDL_OutOfMemory();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
ctx->device = device;
|
||||
ctx->joystick = joystick;
|
||||
ctx->last_packet = SDL_GetTicks();
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
@@ -471,6 +525,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
if (ctx->is_dongle) {
|
||||
ctx->is_bluetooth = SDL_FALSE;
|
||||
ctx->official_controller = SDL_TRUE;
|
||||
enhanced_mode = SDL_TRUE;
|
||||
} else if (device->vendor_id == USB_VENDOR_SONY) {
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
@@ -484,13 +539,30 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
joystick->serial = SDL_strdup(serial);
|
||||
ctx->is_bluetooth = SDL_FALSE;
|
||||
enhanced_mode = SDL_TRUE;
|
||||
} else {
|
||||
ctx->is_bluetooth = SDL_TRUE;
|
||||
|
||||
/* Read a report to see if we're in enhanced mode */
|
||||
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
#ifdef DEBUG_PS4_PROTOCOL
|
||||
if (size > 0) {
|
||||
HIDAPI_DumpPacket("PS4 first packet: size = %d", data, size);
|
||||
} else {
|
||||
SDL_Log("PS4 first packet: size = %d\n", size);
|
||||
}
|
||||
#endif
|
||||
if (size > 0 &&
|
||||
data[0] >= k_EPS4ReportIdBluetoothState1 &&
|
||||
data[0] <= k_EPS4ReportIdBluetoothState9) {
|
||||
enhanced_mode = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
ctx->official_controller = SDL_TRUE;
|
||||
} else {
|
||||
/* Third party controllers appear to all be wired */
|
||||
ctx->is_bluetooth = SDL_FALSE;
|
||||
enhanced_mode = SDL_TRUE;
|
||||
}
|
||||
#ifdef DEBUG_PS4
|
||||
SDL_Log("PS4 dongle = %s, bluetooth = %s\n", ctx->is_dongle ? "TRUE" : "FALSE", ctx->is_bluetooth ? "TRUE" : "FALSE");
|
||||
@@ -503,28 +575,42 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
if (HIDAPI_DriverPS4_CanRumble(device->vendor_id, device->product_id)) {
|
||||
if (ctx->is_bluetooth) {
|
||||
ctx->effects_supported = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, SDL_FALSE);
|
||||
} else {
|
||||
ctx->effects_supported = SDL_TRUE;
|
||||
ctx->effects_supported = SDL_TRUE;
|
||||
}
|
||||
|
||||
if (!joystick->serial && device->serial && SDL_strlen(device->serial) == 12) {
|
||||
int i, j;
|
||||
char serial[18];
|
||||
|
||||
j = -1;
|
||||
for (i = 0; i < 12; i += 2) {
|
||||
j += 1;
|
||||
SDL_memcpy(&serial[j], &device->serial[i], 2);
|
||||
j += 2;
|
||||
serial[j] = '-';
|
||||
}
|
||||
serial[j] = '\0';
|
||||
|
||||
joystick->serial = SDL_strdup(serial);
|
||||
}
|
||||
|
||||
/* Initialize player index (needed for setting LEDs) */
|
||||
ctx->player_index = SDL_JoystickGetPlayerIndex(joystick);
|
||||
|
||||
/* Initialize LED and effect state */
|
||||
HIDAPI_DriverPS4_UpdateEffects(device);
|
||||
|
||||
/* Initialize the joystick capabilities */
|
||||
/* Initialize the joystick capabilities
|
||||
*
|
||||
* We can't dynamically add the touchpad button, so always report it here
|
||||
*/
|
||||
joystick->nbuttons = 16;
|
||||
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
|
||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
||||
|
||||
SDL_PrivateJoystickAddTouchpad(joystick, 2);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
|
||||
joystick->epowerlevel = ctx->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
|
||||
|
||||
if (enhanced_mode) {
|
||||
HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
|
||||
} else {
|
||||
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE,
|
||||
SDL_PS4RumbleHintChanged, ctx);
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -569,6 +655,10 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
{
|
||||
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
HIDAPI_DriverPS4_LoadCalibrationData(device);
|
||||
}
|
||||
@@ -729,8 +819,9 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
|
||||
SDL_Joystick *joystick = NULL;
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
Uint8 data[USB_PACKET_LENGTH*2];
|
||||
int size;
|
||||
int packet_count = 0;
|
||||
|
||||
if (device->num_joysticks > 0) {
|
||||
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
|
||||
@@ -743,6 +834,9 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
#ifdef DEBUG_PS4_PROTOCOL
|
||||
HIDAPI_DumpPacket("PS4 packet: size = %d", data, size);
|
||||
#endif
|
||||
++packet_count;
|
||||
ctx->last_packet = SDL_GetTicks();
|
||||
|
||||
switch (data[0]) {
|
||||
case k_EPS4ReportIdUsbState:
|
||||
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t *)&data[1]);
|
||||
@@ -756,6 +850,10 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
case k_EPS4ReportIdBluetoothState7:
|
||||
case k_EPS4ReportIdBluetoothState8:
|
||||
case k_EPS4ReportIdBluetoothState9:
|
||||
if (!ctx->enhanced_mode) {
|
||||
/* This is the extended report, we can enable effects now */
|
||||
HIDAPI_DriverPS4_SetEnhancedMode(device, joystick);
|
||||
}
|
||||
/* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID is present */
|
||||
if (data[1] & 0x80) {
|
||||
HIDAPI_DriverPS4_HandleStatePacket(joystick, device->dev, ctx, (PS4StatePacket_t*)&data[3]);
|
||||
@@ -769,6 +867,14 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->is_bluetooth && packet_count == 0) {
|
||||
/* Check to see if it looks like the device disconnected */
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->last_packet + BLUETOOTH_DISCONNECT_TIMEOUT_MS)) {
|
||||
/* Send an empty output report to tickle the Bluetooth stack */
|
||||
HIDAPI_DriverPS4_TickleBluetooth(device);
|
||||
}
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
/* Read error, device is disconnected */
|
||||
HIDAPI_JoystickDisconnected(device, joystick->instance_id);
|
||||
@@ -779,11 +885,20 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE,
|
||||
SDL_PS4RumbleHintChanged, ctx);
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
287
externals/SDL/src/joystick/hidapi/SDL_hidapi_ps5.c
vendored
287
externals/SDL/src/joystick/hidapi/SDL_hidapi_ps5.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "../../SDL_hints_c.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
@@ -129,13 +130,12 @@ typedef struct
|
||||
} DS5EffectsState_t;
|
||||
|
||||
typedef enum {
|
||||
k_EDS5EffectNone,
|
||||
k_EDS5EffectRumbleStart,
|
||||
k_EDS5EffectRumble,
|
||||
k_EDS5EffectLEDReset,
|
||||
k_EDS5EffectLED,
|
||||
k_EDS5EffectPadLights,
|
||||
k_EDS5EffectMicLight,
|
||||
k_EDS5EffectRumbleStart = (1 << 0),
|
||||
k_EDS5EffectRumble = (1 << 1),
|
||||
k_EDS5EffectLEDReset = (1 << 2),
|
||||
k_EDS5EffectLED = (1 << 3),
|
||||
k_EDS5EffectPadLights = (1 << 4),
|
||||
k_EDS5EffectMicLight = (1 << 5)
|
||||
} EDS5Effect;
|
||||
|
||||
typedef enum {
|
||||
@@ -150,12 +150,16 @@ typedef struct {
|
||||
} IMUCalibrationData;
|
||||
|
||||
typedef struct {
|
||||
SDL_HIDAPI_Device *device;
|
||||
SDL_Joystick *joystick;
|
||||
SDL_bool is_bluetooth;
|
||||
SDL_bool enhanced_mode;
|
||||
SDL_bool report_sensors;
|
||||
SDL_bool hardware_calibration;
|
||||
IMUCalibrationData calibration[6];
|
||||
Uint32 last_packet;
|
||||
int player_index;
|
||||
SDL_bool player_lights;
|
||||
Uint8 rumble_left;
|
||||
Uint8 rumble_right;
|
||||
SDL_bool color_set;
|
||||
@@ -204,9 +208,9 @@ SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
{ 0x40, 0x00, 0x00 }, /* Red */
|
||||
{ 0x00, 0x40, 0x00 }, /* Green */
|
||||
{ 0x20, 0x00, 0x20 }, /* Pink */
|
||||
{ 0x02, 0x01, 0x00 }, /* Orange */
|
||||
{ 0x00, 0x01, 0x01 }, /* Teal */
|
||||
{ 0x01, 0x01, 0x01 } /* White */
|
||||
{ 0x20, 0x10, 0x00 }, /* Orange */
|
||||
{ 0x00, 0x10, 0x10 }, /* Teal */
|
||||
{ 0x10, 0x10, 0x10 } /* White */
|
||||
};
|
||||
|
||||
if (player_index >= 0) {
|
||||
@@ -220,6 +224,24 @@ SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
effects->ucLedBlue = colors[player_index][2];
|
||||
}
|
||||
|
||||
static void
|
||||
SetLightsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
{
|
||||
static const Uint8 lights[] = {
|
||||
0x04,
|
||||
0x0A,
|
||||
0x15,
|
||||
0x1B
|
||||
};
|
||||
|
||||
if (player_index >= 0 && player_index < SDL_arraysize(lights)) {
|
||||
/* Bitmask, 0x1F enables all lights, 0x20 changes instantly instead of fade */
|
||||
effects->ucPadLights = lights[player_index] | 0x20;
|
||||
} else {
|
||||
effects->ucPadLights = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
@@ -350,7 +372,7 @@ HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, int index, Sin
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
DS5EffectsState_t *effects;
|
||||
@@ -360,6 +382,9 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
int *pending_size;
|
||||
int maximum_size;
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
SDL_zero(data);
|
||||
|
||||
@@ -378,7 +403,8 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
effects = (DS5EffectsState_t *)&data[offset];
|
||||
|
||||
/* Make sure the Bluetooth connection sequence has completed before sending LED color change */
|
||||
if (effect == k_EDS5EffectLED && ctx->is_bluetooth) {
|
||||
if (ctx->is_bluetooth &&
|
||||
(effect_mask & (k_EDS5EffectLED | k_EDS5EffectPadLights)) != 0) {
|
||||
if (ctx->led_reset_state != k_EDS5LEDResetStateComplete) {
|
||||
ctx->led_reset_state = k_EDS5LEDResetStatePending;
|
||||
return 0;
|
||||
@@ -396,17 +422,16 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
/* Leaving emulated rumble bits off will restore audio haptics */
|
||||
}
|
||||
|
||||
switch (effect) {
|
||||
case k_EDS5EffectRumbleStart:
|
||||
if ((effect_mask & k_EDS5EffectRumbleStart) != 0) {
|
||||
effects->ucEnableBits1 |= 0x02; /* Disable audio haptics */
|
||||
break;
|
||||
case k_EDS5EffectRumble:
|
||||
}
|
||||
if ((effect_mask & k_EDS5EffectRumble) != 0) {
|
||||
/* Already handled above */
|
||||
break;
|
||||
case k_EDS5EffectLEDReset:
|
||||
}
|
||||
if ((effect_mask & k_EDS5EffectLEDReset) != 0) {
|
||||
effects->ucEnableBits2 |= 0x08; /* Reset LED state */
|
||||
break;
|
||||
case k_EDS5EffectLED:
|
||||
}
|
||||
if ((effect_mask & k_EDS5EffectLED) != 0) {
|
||||
effects->ucEnableBits2 |= 0x04; /* Enable LED color */
|
||||
|
||||
/* Populate the LED state with the appropriate color from our lookup table */
|
||||
@@ -417,19 +442,20 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
} else {
|
||||
SetLedsForPlayerIndex(effects, ctx->player_index);
|
||||
}
|
||||
break;
|
||||
case k_EDS5EffectPadLights:
|
||||
}
|
||||
if ((effect_mask & k_EDS5EffectPadLights) != 0) {
|
||||
effects->ucEnableBits2 |= 0x10; /* Enable touchpad lights */
|
||||
|
||||
effects->ucPadLights = 0x00; /* Bitmask, 0x1F enables all lights, 0x20 changes instantly instead of fade */
|
||||
break;
|
||||
case k_EDS5EffectMicLight:
|
||||
if (ctx->player_lights) {
|
||||
SetLightsForPlayerIndex(effects, ctx->player_index);
|
||||
} else {
|
||||
effects->ucPadLights = 0x00;
|
||||
}
|
||||
}
|
||||
if ((effect_mask & k_EDS5EffectMicLight) != 0) {
|
||||
effects->ucEnableBits2 |= 0x01; /* Enable microphone light */
|
||||
|
||||
effects->ucMicLightMode = 0; /* Bitmask, 0x00 = off, 0x01 = solid, 0x02 = pulse */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctx->is_bluetooth) {
|
||||
@@ -461,17 +487,6 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, EDS5Effect effect)
|
||||
return SDL_HIDAPI_SendRumbleAndUnlock(device, data, report_size);
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_SetBluetooth(SDL_HIDAPI_Device *device, SDL_bool is_bluetooth)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
if (ctx->is_bluetooth != is_bluetooth) {
|
||||
ctx->is_bluetooth = is_bluetooth;
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
@@ -479,17 +494,73 @@ HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
|
||||
const PS5StatePacket_t *packet = &ctx->last_state.state;
|
||||
|
||||
/* Check the timer to make sure the Bluetooth connection LED animation is complete */
|
||||
const Uint32 connection_complete = 10000000;
|
||||
const Uint32 connection_complete = 10200000;
|
||||
Uint32 timer = ((Uint32)packet->rgucTimer1[0] << 0) |
|
||||
((Uint32)packet->rgucTimer1[1] << 8) |
|
||||
((Uint32)packet->rgucTimer1[2] << 16) |
|
||||
((Uint32)packet->rgucTimer1[3] << 24);
|
||||
if (timer >= connection_complete) {
|
||||
if (SDL_TICKS_PASSED(timer, connection_complete)) {
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLEDReset);
|
||||
|
||||
ctx->led_reset_state = k_EDS5LEDResetStateComplete;
|
||||
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, (k_EDS5EffectLED | k_EDS5EffectPadLights));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_TickleBluetooth(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
/* This is just a dummy packet that should have no effect, since we don't set the CRC */
|
||||
Uint8 data[78];
|
||||
|
||||
SDL_zero(data);
|
||||
|
||||
data[0] = k_EPS5ReportIdBluetoothEffects;
|
||||
data[1] = 0x02; /* Magic value */
|
||||
|
||||
SDL_HIDAPI_SendRumble(device, data, sizeof(data));
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_SetEnhancedMode(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
ctx->enhanced_mode = SDL_TRUE;
|
||||
|
||||
SDL_PrivateJoystickAddTouchpad(joystick, 2);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
|
||||
|
||||
/* Switch into enhanced report mode */
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, 0);
|
||||
|
||||
/* Update the light effects */
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, (k_EDS5EffectLED | k_EDS5EffectPadLights));
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_PS5RumbleHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)userdata;
|
||||
|
||||
/* This is a one-way trip, you can't switch the controller back to simple report mode */
|
||||
if (SDL_GetStringBoolean(hint, SDL_FALSE)) {
|
||||
HIDAPI_DriverPS5_SetEnhancedMode(ctx->device, ctx->joystick);
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL SDL_PS5PlayerLEDHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)userdata;
|
||||
SDL_bool player_lights = SDL_GetStringBoolean(hint, SDL_TRUE);
|
||||
|
||||
if (player_lights != ctx->player_lights) {
|
||||
ctx->player_lights = player_lights;
|
||||
|
||||
HIDAPI_DriverPS5_UpdateEffects(ctx->device, k_EDS5EffectPadLights);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,20 +576,24 @@ HIDAPI_DriverPS5_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID
|
||||
ctx->player_index = player_index;
|
||||
|
||||
/* This will set the new LED state based on the new player index */
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, (k_EDS5EffectLED | k_EDS5EffectPadLights));
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx;
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
Uint8 data[USB_PACKET_LENGTH*2];
|
||||
int size;
|
||||
SDL_bool enhanced_mode = SDL_FALSE;
|
||||
|
||||
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
SDL_OutOfMemory();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
ctx->device = device;
|
||||
ctx->joystick = joystick;
|
||||
ctx->last_packet = SDL_GetTicks();
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
@@ -529,31 +604,84 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
}
|
||||
device->context = ctx;
|
||||
|
||||
/* Read the serial number (Bluetooth address in reverse byte order)
|
||||
This will also enable enhanced reports over Bluetooth
|
||||
*/
|
||||
if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdSerialNumber, data, sizeof(data)) >= 7) {
|
||||
/* Read a report to see what mode we're in */
|
||||
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
#ifdef DEBUG_PS5_PROTOCOL
|
||||
if (size > 0) {
|
||||
HIDAPI_DumpPacket("PS5 first packet: size = %d", data, size);
|
||||
} else {
|
||||
SDL_Log("PS5 first packet: size = %d\n", size);
|
||||
}
|
||||
#endif
|
||||
if (size == 64) {
|
||||
/* Connected over USB */
|
||||
ctx->is_bluetooth = SDL_FALSE;
|
||||
enhanced_mode = SDL_TRUE;
|
||||
} else if (size > 0 && data[0] == k_EPS5ReportIdBluetoothEffects) {
|
||||
/* Connected over Bluetooth, using enhanced reports */
|
||||
ctx->is_bluetooth = SDL_TRUE;
|
||||
enhanced_mode = SDL_TRUE;
|
||||
} else {
|
||||
/* Connected over Bluetooth, using simple reports (DirectInput enabled) */
|
||||
ctx->is_bluetooth = SDL_TRUE;
|
||||
|
||||
/* Games written prior the introduction of PS5 controller support in SDL will not be aware of
|
||||
SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, but they did know SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE.
|
||||
To support apps that only knew about the PS4 hint, we'll use the PS4 hint as the default.
|
||||
*/
|
||||
enhanced_mode = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE,
|
||||
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, SDL_FALSE));
|
||||
}
|
||||
|
||||
if (enhanced_mode) {
|
||||
/* Read the serial number (Bluetooth address in reverse byte order)
|
||||
This will also enable enhanced reports over Bluetooth
|
||||
*/
|
||||
if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdSerialNumber, data, sizeof(data)) >= 7) {
|
||||
char serial[18];
|
||||
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
joystick->serial = SDL_strdup(serial);
|
||||
}
|
||||
}
|
||||
|
||||
if (!joystick->serial && device->serial && SDL_strlen(device->serial) == 12) {
|
||||
int i, j;
|
||||
char serial[18];
|
||||
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
data[6], data[5], data[4], data[3], data[2], data[1]);
|
||||
j = -1;
|
||||
for (i = 0; i < 12; i += 2) {
|
||||
j += 1;
|
||||
SDL_memcpy(&serial[j], &device->serial[i], 2);
|
||||
j += 2;
|
||||
serial[j] = '-';
|
||||
}
|
||||
serial[j] = '\0';
|
||||
|
||||
joystick->serial = SDL_strdup(serial);
|
||||
}
|
||||
|
||||
/* Initialize player index (needed for setting LEDs) */
|
||||
ctx->player_index = SDL_JoystickGetPlayerIndex(joystick);
|
||||
ctx->player_lights = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED, SDL_TRUE);
|
||||
|
||||
/* Initialize LED and effect state */
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectLED);
|
||||
|
||||
/* Initialize the joystick capabilities */
|
||||
/* Initialize the joystick capabilities
|
||||
*
|
||||
* We can't dynamically add the touchpad button, so always report it here
|
||||
*/
|
||||
joystick->nbuttons = 17;
|
||||
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
|
||||
joystick->epowerlevel = ctx->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
|
||||
|
||||
SDL_PrivateJoystickAddTouchpad(joystick, 2);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
|
||||
|
||||
if (enhanced_mode) {
|
||||
HIDAPI_DriverPS5_SetEnhancedMode(device, joystick);
|
||||
} else {
|
||||
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE,
|
||||
SDL_PS5RumbleHintChanged, ctx);
|
||||
}
|
||||
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED,
|
||||
SDL_PS5PlayerLEDHintChanged, ctx);
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -602,6 +730,10 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
{
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
if (!ctx->enhanced_mode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
HIDAPI_DriverPS5_LoadCalibrationData(device);
|
||||
}
|
||||
@@ -783,8 +915,8 @@ HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_
|
||||
Uint8 data = packet->rgucButtonsAndHat[2];
|
||||
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, 15, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, 16, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, 15, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, 16, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
axis = ((int)packet->ucTriggerLeft * 257) - 32768;
|
||||
@@ -869,20 +1001,21 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
|
||||
switch (data[0]) {
|
||||
case k_EPS5ReportIdState:
|
||||
if (size == 10) {
|
||||
HIDAPI_DriverPS5_SetBluetooth(device, SDL_TRUE); /* Simple state packet over Bluetooth */
|
||||
if (size == 10 || size == 78) {
|
||||
HIDAPI_DriverPS5_HandleSimpleStatePacket(joystick, device->dev, ctx, (PS5SimpleStatePacket_t *)&data[1]);
|
||||
} else {
|
||||
HIDAPI_DriverPS5_SetBluetooth(device, SDL_FALSE);
|
||||
HIDAPI_DriverPS5_HandleStatePacket(joystick, device->dev, ctx, (PS5StatePacket_t *)&data[1]);
|
||||
}
|
||||
break;
|
||||
case k_EPS5ReportIdBluetoothState:
|
||||
HIDAPI_DriverPS5_SetBluetooth(device, SDL_TRUE);
|
||||
HIDAPI_DriverPS5_HandleStatePacket(joystick, device->dev, ctx, (PS5StatePacket_t *)&data[2]);
|
||||
if (!ctx->enhanced_mode) {
|
||||
/* This is the extended report, we can enable effects now */
|
||||
HIDAPI_DriverPS5_SetEnhancedMode(device, joystick);
|
||||
}
|
||||
if (ctx->led_reset_state == k_EDS5LEDResetStatePending) {
|
||||
HIDAPI_DriverPS5_CheckPendingLEDReset(device);
|
||||
}
|
||||
HIDAPI_DriverPS5_HandleStatePacket(joystick, device->dev, ctx, (PS5StatePacket_t *)&data[2]);
|
||||
break;
|
||||
default:
|
||||
#ifdef DEBUG_JOYSTICK
|
||||
@@ -896,7 +1029,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
/* Check to see if it looks like the device disconnected */
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->last_packet + BLUETOOTH_DISCONNECT_TIMEOUT_MS)) {
|
||||
/* Send an empty output report to tickle the Bluetooth stack */
|
||||
HIDAPI_DriverPS5_UpdateEffects(device, k_EDS5EffectNone);
|
||||
HIDAPI_DriverPS5_TickleBluetooth(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -910,11 +1043,23 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE,
|
||||
SDL_PS5RumbleHintChanged, ctx);
|
||||
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED,
|
||||
SDL_PS5PlayerLEDHintChanged, ctx);
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -25,6 +25,7 @@
|
||||
/* Handle rumble on a separate thread so it doesn't block the application */
|
||||
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
#include "../../thread/SDL_systhread.h"
|
||||
@@ -76,11 +77,17 @@ static int SDL_HIDAPI_RumbleThread(void *data)
|
||||
if (request) {
|
||||
SDL_LockMutex(request->device->dev_lock);
|
||||
if (request->device->dev) {
|
||||
hid_write( request->device->dev, request->data, request->size );
|
||||
#ifdef DEBUG_RUMBLE
|
||||
HIDAPI_DumpPacket("Rumble packet: size = %d", request->data, request->size);
|
||||
#endif
|
||||
hid_write(request->device->dev, request->data, request->size);
|
||||
}
|
||||
SDL_UnlockMutex(request->device->dev_lock);
|
||||
(void)SDL_AtomicDecRef(&request->device->rumble_pending);
|
||||
SDL_free(request);
|
||||
|
||||
/* Make sure we're not starving report reads when there's lots of rumble */
|
||||
SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
326
externals/SDL/src/joystick/hidapi/SDL_hidapi_stadia.c
vendored
Executable file
326
externals/SDL/src/joystick/hidapi/SDL_hidapi_stadia.c
vendored
Executable file
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_STADIA
|
||||
|
||||
/* Define this if you want to log all packets from the controller */
|
||||
/*#define DEBUG_STADIA_PROTOCOL*/
|
||||
|
||||
enum
|
||||
{
|
||||
SDL_CONTROLLER_BUTTON_STADIA_SHARE = 15,
|
||||
SDL_CONTROLLER_BUTTON_STADIA_GOOGLE_ASSISTANT,
|
||||
SDL_CONTROLLER_NUM_STADIA_BUTTONS,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
Uint8 last_state[USB_PACKET_LENGTH];
|
||||
} SDL_DriverStadia_Context;
|
||||
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverStadia_IsSupportedDevice(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
if (vendor_id == USB_VENDOR_GOOGLE && product_id == USB_PRODUCT_GOOGLE_STADIA_CONTROLLER) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
HIDAPI_DriverStadia_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
return "Google Stadia Controller";
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverStadia_InitDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
return HIDAPI_JoystickConnected(device, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverStadia_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverStadia_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_DriverStadia_Context *ctx;
|
||||
|
||||
ctx = (SDL_DriverStadia_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
SDL_OutOfMemory();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
SDL_free(ctx);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
device->context = ctx;
|
||||
|
||||
/* Initialize the joystick capabilities */
|
||||
joystick->nbuttons = SDL_CONTROLLER_NUM_STADIA_BUTTONS;
|
||||
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
|
||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverStadia_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
Uint8 rumble_packet[] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
rumble_packet[1] = (low_frequency_rumble & 0xFF);
|
||||
rumble_packet[2] = (low_frequency_rumble >> 8);
|
||||
rumble_packet[3] = (high_frequency_rumble & 0xFF);
|
||||
rumble_packet[4] = (high_frequency_rumble >> 8);
|
||||
|
||||
if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
|
||||
return SDL_SetError("Couldn't send rumble packet");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverStadia_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverStadia_HasJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverStadia_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
HIDAPI_DriverStadia_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverStadia_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverStadia_Context *ctx, Uint8 *data, int size)
|
||||
{
|
||||
Sint16 axis;
|
||||
|
||||
// The format is the same but the original FW will send 10 bytes and January '21 FW update will send 11
|
||||
if (size < 10 || data[0] != 0x03) {
|
||||
/* We don't know how to handle this report */
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->last_state[1] != data[1]) {
|
||||
SDL_bool dpad_up = SDL_FALSE;
|
||||
SDL_bool dpad_down = SDL_FALSE;
|
||||
SDL_bool dpad_left = SDL_FALSE;
|
||||
SDL_bool dpad_right = SDL_FALSE;
|
||||
|
||||
switch (data[1]) {
|
||||
case 0:
|
||||
dpad_up = SDL_TRUE;
|
||||
break;
|
||||
case 1:
|
||||
dpad_up = SDL_TRUE;
|
||||
dpad_right = SDL_TRUE;
|
||||
break;
|
||||
case 2:
|
||||
dpad_right = SDL_TRUE;
|
||||
break;
|
||||
case 3:
|
||||
dpad_right = SDL_TRUE;
|
||||
dpad_down = SDL_TRUE;
|
||||
break;
|
||||
case 4:
|
||||
dpad_down = SDL_TRUE;
|
||||
break;
|
||||
case 5:
|
||||
dpad_left = SDL_TRUE;
|
||||
dpad_down = SDL_TRUE;
|
||||
break;
|
||||
case 6:
|
||||
dpad_left = SDL_TRUE;
|
||||
break;
|
||||
case 7:
|
||||
dpad_up = SDL_TRUE;
|
||||
dpad_left = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_DOWN, dpad_down);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_UP, dpad_up);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, dpad_right);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_LEFT, dpad_left);
|
||||
}
|
||||
|
||||
if (ctx->last_state[2] != data[2]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_BACK, (data[2] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data[2] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_START, (data[2] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_RIGHTSTICK, (data[2] & 0x80) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_STADIA_SHARE, (data[2] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_STADIA_GOOGLE_ASSISTANT, (data[2] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
if (ctx->last_state[3] != data[3]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_A, (data[3] & 0x40) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_B, (data[3] & 0x20) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_X, (data[3] & 0x10) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_Y, (data[3] & 0x08) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, (data[3] & 0x04) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, (data[3] & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_LEFTSTICK, (data[3] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
#define READ_STICK_AXIS(offset) \
|
||||
(data[offset] == 0x80 ? 0 : \
|
||||
(Sint16)HIDAPI_RemapVal((float)((int)data[offset] - 0x80), 0x01 - 0x80, 0xff - 0x80, SDL_MIN_SINT16, SDL_MAX_SINT16))
|
||||
{
|
||||
axis = READ_STICK_AXIS(4);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTX, axis);
|
||||
axis = READ_STICK_AXIS(5);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTY, axis);
|
||||
axis = READ_STICK_AXIS(6);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTX, axis);
|
||||
axis = READ_STICK_AXIS(7);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
||||
}
|
||||
#undef READ_STICK_AXIS
|
||||
|
||||
#define READ_TRIGGER_AXIS(offset) \
|
||||
(Sint16)(((int)data[offset] * 257) - 32768)
|
||||
{
|
||||
axis = READ_TRIGGER_AXIS(8);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, axis);
|
||||
axis = READ_TRIGGER_AXIS(9);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, axis);
|
||||
}
|
||||
#undef READ_TRIGGER_AXIS
|
||||
|
||||
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverStadia_Context *ctx = (SDL_DriverStadia_Context *)device->context;
|
||||
SDL_Joystick *joystick = NULL;
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size = 0;
|
||||
|
||||
if (device->num_joysticks > 0) {
|
||||
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
|
||||
}
|
||||
if (!joystick) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_STADIA_PROTOCOL
|
||||
HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
|
||||
#endif
|
||||
HIDAPI_DriverStadia_HandleStatePacket(joystick, ctx, data, size);
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
/* Read error, device is disconnected */
|
||||
HIDAPI_JoystickDisconnected(device, joystick->instance_id);
|
||||
}
|
||||
return (size >= 0);
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverStadia_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverStadia_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
}
|
||||
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia =
|
||||
{
|
||||
SDL_HINT_JOYSTICK_HIDAPI_STADIA,
|
||||
SDL_TRUE,
|
||||
HIDAPI_DriverStadia_IsSupportedDevice,
|
||||
HIDAPI_DriverStadia_GetDeviceName,
|
||||
HIDAPI_DriverStadia_InitDevice,
|
||||
HIDAPI_DriverStadia_GetDevicePlayerIndex,
|
||||
HIDAPI_DriverStadia_SetDevicePlayerIndex,
|
||||
HIDAPI_DriverStadia_UpdateDevice,
|
||||
HIDAPI_DriverStadia_OpenJoystick,
|
||||
HIDAPI_DriverStadia_RumbleJoystick,
|
||||
HIDAPI_DriverStadia_RumbleJoystickTriggers,
|
||||
HIDAPI_DriverStadia_HasJoystickLED,
|
||||
HIDAPI_DriverStadia_SetJoystickLED,
|
||||
HIDAPI_DriverStadia_SetJoystickSensorsEnabled,
|
||||
HIDAPI_DriverStadia_CloseJoystick,
|
||||
HIDAPI_DriverStadia_FreeDevice,
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI_STADIA */
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -1016,14 +1016,18 @@ HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
|
||||
return SDL_TRUE;
|
||||
|
||||
error:
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -1170,12 +1174,17 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_DriverSteam_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
CloseSteamController(device->dev);
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
CloseSteamController(device->dev);
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -44,13 +44,24 @@
|
||||
/* Define this to get log output for rumble logic */
|
||||
/*#define DEBUG_RUMBLE*/
|
||||
|
||||
/* How often you can write rumble commands to the controller in Bluetooth mode
|
||||
If you send commands more frequently than this, you can turn off the controller.
|
||||
/* The initialization sequence doesn't appear to work correctly on Windows unless
|
||||
the reads and writes are on the same thread.
|
||||
|
||||
... and now I can't reproduce this, so I'm leaving it in, but disabled for now.
|
||||
*/
|
||||
#define RUMBLE_WRITE_FREQUENCY_MS 25
|
||||
/*#define SWITCH_SYNCHRONOUS_WRITES*/
|
||||
|
||||
/* How often you can write rumble commands to the controller.
|
||||
If you send commands more frequently than this, you can turn off the controller
|
||||
in Bluetooth mode, or the motors can miss the command in USB mode.
|
||||
*/
|
||||
#define RUMBLE_WRITE_FREQUENCY_MS 30
|
||||
|
||||
/* How often you have to refresh a long duration rumble to keep the motors running */
|
||||
#define RUMBLE_REFRESH_FREQUENCY_MS 40
|
||||
#define RUMBLE_REFRESH_FREQUENCY_MS 50
|
||||
|
||||
#define SWITCH_GYRO_SCALE 14.2842f
|
||||
#define SWITCH_ACCEL_SCALE 4096.f
|
||||
|
||||
typedef enum {
|
||||
k_eSwitchInputReportIDs_SubcommandReply = 0x21,
|
||||
@@ -79,6 +90,7 @@ typedef enum {
|
||||
} ESwitchSubcommandIDs;
|
||||
|
||||
typedef enum {
|
||||
k_eSwitchProprietaryCommandIDs_Status = 0x01,
|
||||
k_eSwitchProprietaryCommandIDs_Handshake = 0x02,
|
||||
k_eSwitchProprietaryCommandIDs_HighSpeed = 0x03,
|
||||
k_eSwitchProprietaryCommandIDs_ForceUSB = 0x04,
|
||||
@@ -87,6 +99,7 @@ typedef enum {
|
||||
} ESwitchProprietaryCommandIDs;
|
||||
|
||||
typedef enum {
|
||||
k_eSwitchDeviceInfoControllerType_Unknown = 0x0,
|
||||
k_eSwitchDeviceInfoControllerType_JoyConLeft = 0x1,
|
||||
k_eSwitchDeviceInfoControllerType_JoyConRight = 0x2,
|
||||
k_eSwitchDeviceInfoControllerType_ProController = 0x3,
|
||||
@@ -176,6 +189,16 @@ typedef struct
|
||||
};
|
||||
} SwitchSubcommandInputPacket_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucPacketType;
|
||||
Uint8 ucCommandID;
|
||||
Uint8 ucFiller;
|
||||
|
||||
Uint8 ucDeviceType;
|
||||
Uint8 rgucMACAddress[6];
|
||||
} SwitchProprietaryStatusPacket_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Uint8 rgucData[4];
|
||||
@@ -212,6 +235,8 @@ typedef struct {
|
||||
SDL_bool m_bUsingBluetooth;
|
||||
SDL_bool m_bIsGameCube;
|
||||
SDL_bool m_bUseButtonLabels;
|
||||
ESwitchDeviceInfoControllerType m_eControllerType;
|
||||
Uint8 m_rgucMACAddress[6];
|
||||
Uint8 m_nCommandNumber;
|
||||
SwitchCommonOutputPacket_t m_RumblePacket;
|
||||
Uint8 m_rgucReadBuffer[k_unSwitchMaxOutputPacketLength];
|
||||
@@ -220,6 +245,8 @@ typedef struct {
|
||||
SDL_bool m_bRumblePending;
|
||||
SDL_bool m_bRumbleZeroPending;
|
||||
Uint32 m_unRumblePending;
|
||||
SDL_bool m_bHasSensors;
|
||||
SDL_bool m_bReportSensors;
|
||||
|
||||
SwitchInputOnlyControllerStatePacket_t m_lastInputOnlyState;
|
||||
SwitchSimpleStatePacket_t m_lastSimpleState;
|
||||
@@ -285,7 +312,7 @@ HIDAPI_DriverSwitch_IsSupportedDevice(const char *name, SDL_GameControllerType t
|
||||
controller to continually attempt to reconnect is to filter it out by manufactuer/product string.
|
||||
Note that the controller does have a different product string when connected over Bluetooth.
|
||||
*/
|
||||
if (SDL_strcmp( name, "HORI Wireless Switch Pad" ) == 0) {
|
||||
if (SDL_strcmp(name, "HORI Wireless Switch Pad") == 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return (type == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO) ? SDL_TRUE : SDL_FALSE;
|
||||
@@ -295,6 +322,16 @@ static const char *
|
||||
HIDAPI_DriverSwitch_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
/* Give a user friendly name for this controller */
|
||||
if (vendor_id == USB_VENDOR_NINTENDO) {
|
||||
if (product_id == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_LEFT) {
|
||||
return "Nintendo Switch Joy-Con Left";
|
||||
}
|
||||
|
||||
if (product_id == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_RIGHT) {
|
||||
return "Nintendo Switch Joy-Con Right";
|
||||
}
|
||||
}
|
||||
|
||||
return "Nintendo Switch Pro Controller";
|
||||
}
|
||||
|
||||
@@ -310,11 +347,15 @@ static int ReadInput(SDL_DriverSwitch_Context *ctx)
|
||||
|
||||
static int WriteOutput(SDL_DriverSwitch_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
#ifdef SWITCH_SYNCHRONOUS_WRITES
|
||||
return hid_write(ctx->device->dev, data, size);
|
||||
#else
|
||||
/* Use the rumble thread for general asynchronous writes */
|
||||
if (SDL_HIDAPI_LockRumble() < 0) {
|
||||
return -1;
|
||||
}
|
||||
return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size);
|
||||
#endif /* SWITCH_SYNCHRONOUS_WRITES */
|
||||
}
|
||||
|
||||
static SwitchSubcommandInputPacket_t *ReadSubcommandReply(SDL_DriverSwitch_Context *ctx, ESwitchSubcommandIDs expectedID)
|
||||
@@ -432,6 +473,7 @@ static SDL_bool WriteProprietary(SDL_DriverSwitch_Context *ctx, ESwitchProprieta
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_zero(packet);
|
||||
packet.ucPacketType = k_eSwitchOutputReportIDs_Proprietary;
|
||||
packet.ucProprietaryID = ucCommand;
|
||||
if (pBuf) {
|
||||
@@ -493,6 +535,40 @@ static SDL_bool WriteRumble(SDL_DriverSwitch_Context *ctx)
|
||||
return WritePacket(ctx, (Uint8 *)&ctx->m_RumblePacket, sizeof(ctx->m_RumblePacket));
|
||||
}
|
||||
|
||||
static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
|
||||
{
|
||||
SwitchSubcommandInputPacket_t *reply = NULL;
|
||||
|
||||
ctx->m_bUsingBluetooth = SDL_FALSE;
|
||||
|
||||
if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
|
||||
SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
|
||||
size_t i;
|
||||
|
||||
ctx->m_eControllerType = (ESwitchDeviceInfoControllerType)status->ucDeviceType;
|
||||
for (i = 0; i < sizeof (ctx->m_rgucMACAddress); ++i)
|
||||
ctx->m_rgucMACAddress[i] = status->rgucMACAddress[ sizeof(ctx->m_rgucMACAddress) - i - 1 ];
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
ctx->m_bUsingBluetooth = SDL_TRUE;
|
||||
|
||||
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
|
||||
// Byte 2: Controller ID (1=LJC, 2=RJC, 3=Pro)
|
||||
ctx->m_eControllerType = (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType;
|
||||
|
||||
// Bytes 4-9: MAC address (big-endian)
|
||||
memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
ctx->m_bUsingBluetooth = SDL_FALSE;
|
||||
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool BTrySetupUSB(SDL_DriverSwitch_Context *ctx)
|
||||
{
|
||||
/* We have to send a connection handshake to the controller when communicating over USB
|
||||
@@ -510,6 +586,9 @@ static SDL_bool BTrySetupUSB(SDL_DriverSwitch_Context *ctx)
|
||||
if (!WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Handshake, NULL, 0, SDL_TRUE)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_ForceUSB, NULL, 0, SDL_FALSE)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -550,6 +629,12 @@ static SDL_bool SetSlotLED(SDL_DriverSwitch_Context *ctx, Uint8 slot)
|
||||
return WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SetPlayerLights, &led_data, sizeof(led_data), NULL);
|
||||
}
|
||||
|
||||
static SDL_bool SetIMUEnabled(SDL_DriverSwitch_Context* ctx, SDL_bool enabled)
|
||||
{
|
||||
Uint8 imu_data = enabled ? 1 : 0;
|
||||
return WriteSubcommand(ctx, k_eSwitchSubcommandIDs_EnableIMU, &imu_data, sizeof(imu_data), NULL);
|
||||
}
|
||||
|
||||
static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_mode)
|
||||
{
|
||||
Uint8 *pStickCal;
|
||||
@@ -621,19 +706,6 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static float fsel(float fComparand, float fValGE, float fLT)
|
||||
{
|
||||
return fComparand >= 0 ? fValGE : fLT;
|
||||
}
|
||||
|
||||
static float RemapVal(float val, float A, float B, float C, float D)
|
||||
{
|
||||
if (A == B) {
|
||||
return fsel(val - B , D , C);
|
||||
}
|
||||
return C + (D - C) * (val - A) / (B - A);
|
||||
}
|
||||
|
||||
static Sint16 ApplyStickCalibrationCentered(SDL_DriverSwitch_Context *ctx, int nStick, int nAxis, Sint16 sRawValue, Sint16 sCenter)
|
||||
{
|
||||
sRawValue -= sCenter;
|
||||
@@ -646,9 +718,9 @@ static Sint16 ApplyStickCalibrationCentered(SDL_DriverSwitch_Context *ctx, int n
|
||||
}
|
||||
|
||||
if (sRawValue > 0) {
|
||||
return (Sint16)(RemapVal(sRawValue, 0, ctx->m_StickExtents[nStick].axis[nAxis].sMax, 0, SDL_MAX_SINT16));
|
||||
return (Sint16)HIDAPI_RemapVal(sRawValue, 0, ctx->m_StickExtents[nStick].axis[nAxis].sMax, 0, SDL_MAX_SINT16);
|
||||
} else {
|
||||
return (Sint16)(RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, 0, SDL_MIN_SINT16, 0));
|
||||
return (Sint16)HIDAPI_RemapVal(sRawValue, ctx->m_StickExtents[nStick].axis[nAxis].sMin, 0, SDL_MIN_SINT16, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,9 +812,16 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
|
||||
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
|
||||
|
||||
/* Try setting up USB mode, and if that fails we're using Bluetooth */
|
||||
if (!BTrySetupUSB(ctx)) {
|
||||
ctx->m_bUsingBluetooth = SDL_TRUE;
|
||||
if (!BReadDeviceInfo(ctx)) {
|
||||
SDL_SetError("Couldn't read device info");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!ctx->m_bUsingBluetooth) {
|
||||
if (!BTrySetupUSB(ctx)) {
|
||||
SDL_SetError("Couldn't setup USB mode");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine the desired input mode (needed before loading stick calibration) */
|
||||
@@ -758,9 +837,17 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
* level and we only care about battery level over bluetooth anyway.
|
||||
*/
|
||||
if (device->vendor_id == USB_VENDOR_NINTENDO &&
|
||||
device->product_id == USB_PRODUCT_NINTENDO_SWITCH_PRO) {
|
||||
(device->product_id == USB_PRODUCT_NINTENDO_SWITCH_PRO ||
|
||||
device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_LEFT ||
|
||||
device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_RIGHT)) {
|
||||
input_mode = k_eSwitchInputReportIDs_FullControllerState;
|
||||
}
|
||||
|
||||
if (input_mode == k_eSwitchInputReportIDs_FullControllerState) {
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO);
|
||||
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL);
|
||||
ctx->m_bHasSensors = SDL_TRUE;
|
||||
}
|
||||
|
||||
if (!LoadStickCalibration(ctx, input_mode)) {
|
||||
SDL_SetError("Couldn't load stick calibration");
|
||||
@@ -789,9 +876,27 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
|
||||
/* Set the LED state */
|
||||
if (ctx->m_bHasHomeLED) {
|
||||
SetHomeLED(ctx, 100);
|
||||
if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, SDL_TRUE)) {
|
||||
SetHomeLED(ctx, 100);
|
||||
} else {
|
||||
SetHomeLED(ctx, 0);
|
||||
}
|
||||
}
|
||||
SetSlotLED(ctx, (joystick->instance_id % 4));
|
||||
|
||||
/* Set the serial number */
|
||||
{
|
||||
char serial[18];
|
||||
|
||||
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
|
||||
ctx->m_rgucMACAddress[0],
|
||||
ctx->m_rgucMACAddress[1],
|
||||
ctx->m_rgucMACAddress[2],
|
||||
ctx->m_rgucMACAddress[3],
|
||||
ctx->m_rgucMACAddress[4],
|
||||
ctx->m_rgucMACAddress[5]);
|
||||
joystick->serial = SDL_strdup(serial);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsGameCubeFormFactor(device->vendor_id, device->product_id)) {
|
||||
@@ -803,21 +908,30 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
SDL_GameControllerButtonReportingHintChanged, ctx);
|
||||
|
||||
/* Initialize the joystick capabilities */
|
||||
joystick->nbuttons = 16;
|
||||
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
|
||||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
|
||||
joystick->nbuttons = 20;
|
||||
} else {
|
||||
joystick->nbuttons = 16;
|
||||
}
|
||||
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
|
||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
|
||||
|
||||
return SDL_TRUE;
|
||||
|
||||
error:
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -859,7 +973,7 @@ HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context *ctx, Uint16
|
||||
static int
|
||||
HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx)
|
||||
{
|
||||
if ((SDL_GetTicks() - ctx->m_unRumbleSent) < RUMBLE_WRITE_FREQUENCY_MS) {
|
||||
if (!SDL_TICKS_PASSED(SDL_GetTicks(), ctx->m_unRumbleSent + RUMBLE_WRITE_FREQUENCY_MS)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -868,7 +982,7 @@ HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx)
|
||||
Uint16 high_frequency_rumble = (Uint16)ctx->m_unRumblePending;
|
||||
|
||||
#ifdef DEBUG_RUMBLE
|
||||
SDL_Log("Sent pending rumble %d/%d\n", low_frequency_rumble, high_frequency_rumble);
|
||||
SDL_Log("Sent pending rumble %d/%d, %d ms after previous rumble\n", low_frequency_rumble, high_frequency_rumble, SDL_GetTicks() - ctx->m_unRumbleSent);
|
||||
#endif
|
||||
ctx->m_bRumblePending = SDL_FALSE;
|
||||
ctx->m_unRumblePending = 0;
|
||||
@@ -880,7 +994,7 @@ HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx)
|
||||
ctx->m_bRumbleZeroPending = SDL_FALSE;
|
||||
|
||||
#ifdef DEBUG_RUMBLE
|
||||
SDL_Log("Sent pending zero rumble\n");
|
||||
SDL_Log("Sent pending zero rumble, %d ms after previous rumble\n", SDL_GetTicks() - ctx->m_unRumbleSent);
|
||||
#endif
|
||||
return HIDAPI_DriverSwitch_ActuallyRumbleJoystick(ctx, 0, 0);
|
||||
}
|
||||
@@ -899,7 +1013,7 @@ HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->m_bUsingBluetooth && (SDL_GetTicks() - ctx->m_unRumbleSent) < RUMBLE_WRITE_FREQUENCY_MS) {
|
||||
if (!SDL_TICKS_PASSED(SDL_GetTicks(), ctx->m_unRumbleSent + RUMBLE_WRITE_FREQUENCY_MS)) {
|
||||
if (low_frequency_rumble || high_frequency_rumble) {
|
||||
Uint32 unRumblePending = ((Uint32)low_frequency_rumble << 16) | high_frequency_rumble;
|
||||
|
||||
@@ -945,7 +1059,30 @@ HIDAPI_DriverSwitch_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joys
|
||||
static int
|
||||
HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
SDL_DriverSwitch_Context* ctx = (SDL_DriverSwitch_Context*)device->context;
|
||||
|
||||
if (!ctx->m_bHasSensors) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
SetIMUEnabled(ctx, enabled);
|
||||
ctx->m_bReportSensors = enabled;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static float
|
||||
HIDAPI_DriverSwitch_ScaleGyro(Sint16 value)
|
||||
{
|
||||
float result = (value / SWITCH_GYRO_SCALE) * (float)M_PI / 180.0f;
|
||||
return result;
|
||||
}
|
||||
|
||||
static float
|
||||
HIDAPI_DriverSwitch_ScaleAccel(Sint16 value)
|
||||
{
|
||||
float result = (value / SWITCH_ACCEL_SCALE) * SDL_STANDARD_GRAVITY;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void HandleInputOnlyControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SwitchInputOnlyControllerStatePacket_t *packet)
|
||||
@@ -1023,22 +1160,22 @@ static void HandleInputOnlyControllerState(SDL_Joystick *joystick, SDL_DriverSwi
|
||||
}
|
||||
|
||||
if (packet->rgucJoystickLeft[0] != ctx->m_lastInputOnlyState.rgucJoystickLeft[0]) {
|
||||
axis = (Sint16)(RemapVal(packet->rgucJoystickLeft[0], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16));
|
||||
axis = (Sint16)HIDAPI_RemapVal(packet->rgucJoystickLeft[0], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTX, axis);
|
||||
}
|
||||
|
||||
if (packet->rgucJoystickLeft[1] != ctx->m_lastInputOnlyState.rgucJoystickLeft[1]) {
|
||||
axis = (Sint16)(RemapVal(packet->rgucJoystickLeft[1], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16));
|
||||
axis = (Sint16)HIDAPI_RemapVal(packet->rgucJoystickLeft[1], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_LEFTY, axis);
|
||||
}
|
||||
|
||||
if (packet->rgucJoystickRight[0] != ctx->m_lastInputOnlyState.rgucJoystickRight[0]) {
|
||||
axis = (Sint16)(RemapVal(packet->rgucJoystickRight[0], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16));
|
||||
axis = (Sint16)HIDAPI_RemapVal(packet->rgucJoystickRight[0], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTX, axis);
|
||||
}
|
||||
|
||||
if (packet->rgucJoystickRight[1] != ctx->m_lastInputOnlyState.rgucJoystickRight[1]) {
|
||||
axis = (Sint16)(RemapVal(packet->rgucJoystickRight[1], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16));
|
||||
axis = (Sint16)HIDAPI_RemapVal(packet->rgucJoystickRight[1], SDL_MIN_UINT8, SDL_MAX_UINT8, SDL_MIN_SINT16, SDL_MAX_SINT16);
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
|
||||
}
|
||||
|
||||
@@ -1146,6 +1283,10 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
|
||||
SDL_PrivateJoystickButton(joystick, RemapButton(ctx, SDL_CONTROLLER_BUTTON_B), (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, RemapButton(ctx, SDL_CONTROLLER_BUTTON_X), (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, RemapButton(ctx, SDL_CONTROLLER_BUTTON_Y), (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_PADDLE1, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_PADDLE3, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
|
||||
axis = (data & 0x80) ? 32767 : -32768;
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, axis);
|
||||
@@ -1168,6 +1309,10 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_UP, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, (data & 0x04) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_DPAD_LEFT, (data & 0x08) ? SDL_PRESSED : SDL_RELEASED);
|
||||
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_PADDLE4, (data & 0x10) ? SDL_PRESSED : SDL_RELEASED);
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_PADDLE2, (data & 0x20) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, (data & 0x40) ? SDL_PRESSED : SDL_RELEASED);
|
||||
axis = (data & 0x80) ? 32767 : -32768;
|
||||
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_TRIGGERLEFT, axis);
|
||||
@@ -1210,6 +1355,54 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->m_bReportSensors) {
|
||||
float data[3];
|
||||
|
||||
/* Note the order of components has been shuffled to match PlayStation controllers,
|
||||
* since that's our de facto standard from already supporting those controllers, and
|
||||
* users will want consistent axis mappings across devices.
|
||||
*/
|
||||
data[0] = HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[0].sGyroY);
|
||||
data[1] = HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[0].sGyroZ);
|
||||
data[2] = HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[0].sGyroX);
|
||||
data[0] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[1].sGyroY);
|
||||
data[1] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[1].sGyroZ);
|
||||
data[2] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[1].sGyroX);
|
||||
data[0] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[2].sGyroY);
|
||||
data[1] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[2].sGyroZ);
|
||||
data[2] += HIDAPI_DriverSwitch_ScaleGyro(packet->imuState[2].sGyroX);
|
||||
data[0] /= -3.f;
|
||||
data[1] /= 3.f;
|
||||
data[2] /= -3.f;
|
||||
/* Right Joy-Con flips some axes, so let's flip them back for consistency */
|
||||
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
|
||||
data[0] = -data[0];
|
||||
data[1] = -data[1];
|
||||
}
|
||||
|
||||
SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, data, 3);
|
||||
|
||||
data[0] = HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[0].sAccelY);
|
||||
data[1] = HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[0].sAccelZ);
|
||||
data[2] = HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[0].sAccelX);
|
||||
data[0] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[1].sAccelY);
|
||||
data[1] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[1].sAccelZ);
|
||||
data[2] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[1].sAccelX);
|
||||
data[0] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[2].sAccelY);
|
||||
data[1] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[2].sAccelZ);
|
||||
data[2] += HIDAPI_DriverSwitch_ScaleAccel(packet->imuState[2].sAccelX);
|
||||
data[0] /= -3.f;
|
||||
data[1] /= 3.f;
|
||||
data[2] /= -3.f;
|
||||
/* Right Joy-Con flips some axes, so let's flip them back for consistency */
|
||||
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
|
||||
data[0] = -data[0];
|
||||
data[1] = -data[1];
|
||||
}
|
||||
|
||||
SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, data, 3);
|
||||
}
|
||||
|
||||
ctx->m_lastFullState = *packet;
|
||||
}
|
||||
|
||||
@@ -1252,7 +1445,7 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
} else if (ctx->m_bRumbleActive &&
|
||||
SDL_TICKS_PASSED(SDL_GetTicks(), ctx->m_unRumbleSent + RUMBLE_REFRESH_FREQUENCY_MS)) {
|
||||
#ifdef DEBUG_RUMBLE
|
||||
SDL_Log("Sent continuing rumble\n");
|
||||
SDL_Log("Sent continuing rumble, %d ms after previous rumble\n", SDL_GetTicks() - ctx->m_unRumbleSent);
|
||||
#endif
|
||||
WriteRumble(ctx);
|
||||
}
|
||||
@@ -1277,11 +1470,15 @@ HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS,
|
||||
SDL_GameControllerButtonReportingHintChanged, ctx);
|
||||
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -42,22 +42,6 @@ typedef struct {
|
||||
Uint8 last_state[USB_PACKET_LENGTH];
|
||||
} SDL_DriverXbox360_Context;
|
||||
|
||||
#if defined(__MACOSX__)
|
||||
static SDL_bool
|
||||
IsBluetoothXboxOneController(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
/* Check to see if it's the Xbox One S or Xbox One Elite Series 2 in Bluetooth mode */
|
||||
if (vendor_id == USB_VENDOR_MICROSOFT) {
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_S_REV2_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLUETOOTH) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverXbox360_IsSupportedDevice(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
@@ -89,7 +73,7 @@ HIDAPI_DriverXbox360_IsSupportedDevice(const char *name, SDL_GameControllerType
|
||||
|
||||
Bluetooth Xbox One controllers are handled by the SDL Xbox One driver
|
||||
*/
|
||||
if (IsBluetoothXboxOneController(vendor_id, product_id)) {
|
||||
if (SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return (type == SDL_CONTROLLER_TYPE_XBOX360 || type == SDL_CONTROLLER_TYPE_XBOXONE) ? SDL_TRUE : SDL_FALSE;
|
||||
@@ -106,9 +90,11 @@ HIDAPI_DriverXbox360_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
|
||||
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
|
||||
{
|
||||
Uint8 mode = 0x02 + slot;
|
||||
const Uint8 led_packet[] = { 0x01, 0x03, mode };
|
||||
const SDL_bool blink = SDL_FALSE;
|
||||
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
|
||||
Uint8 led_packet[] = { 0x01, 0x03, 0x00 };
|
||||
|
||||
led_packet[2] = mode;
|
||||
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -133,7 +119,9 @@ HIDAPI_DriverXbox360_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joystic
|
||||
if (!device->dev) {
|
||||
return;
|
||||
}
|
||||
SetSlotLED(device->dev, (player_index % 4));
|
||||
if (player_index >= 0) {
|
||||
SetSlotLED(device->dev, (player_index % 4));
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
@@ -174,7 +162,7 @@ static int
|
||||
HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
#ifdef __MACOSX__
|
||||
if (IsBluetoothXboxOneController(device->vendor_id, device->product_id)) {
|
||||
if (SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id)) {
|
||||
Uint8 rumble_packet[] = { 0x03, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00 };
|
||||
|
||||
rumble_packet[4] = (low_frequency_rumble >> 8);
|
||||
@@ -321,13 +309,17 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_DriverXbox360_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -49,7 +49,7 @@ HIDAPI_DriverXbox360W_IsSupportedDevice(const char *name, SDL_GameControllerType
|
||||
{
|
||||
const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
|
||||
|
||||
if ((vendor_id == USB_VENDOR_MICROSOFT && (product_id == 0x0291 || product_id == 0x02a9 || product_id == 0x0719)) ||
|
||||
if ((vendor_id == USB_VENDOR_MICROSOFT && (product_id == 0x0291 || product_id == 0x02a9 || product_id == 0x0719) && interface_protocol == 0) ||
|
||||
(type == SDL_CONTROLLER_TYPE_XBOX360 && interface_protocol == XB360W_IFACE_PROTOCOL)) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
@@ -64,9 +64,11 @@ HIDAPI_DriverXbox360W_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
|
||||
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
|
||||
{
|
||||
Uint8 mode = 0x02 + slot;
|
||||
const Uint8 led_packet[] = { 0x00, 0x00, 0x08, (0x40 + (mode % 0x0e)), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
const SDL_bool blink = SDL_FALSE;
|
||||
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
|
||||
Uint8 led_packet[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
led_packet[3] = 0x40 + (mode % 0x0e);
|
||||
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -131,7 +133,9 @@ HIDAPI_DriverXbox360W_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
if (!device->dev) {
|
||||
return;
|
||||
}
|
||||
SetSlotLED(device->dev, (player_index % 4));
|
||||
if (player_index >= 0) {
|
||||
SetSlotLED(device->dev, (player_index % 4));
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
@@ -309,11 +313,15 @@ HIDAPI_DriverXbox360W_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy
|
||||
static void
|
||||
HIDAPI_DriverXbox360W_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W =
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -129,22 +129,6 @@ typedef struct {
|
||||
Uint8 right_trigger_rumble;
|
||||
} SDL_DriverXboxOne_Context;
|
||||
|
||||
|
||||
static SDL_bool
|
||||
IsBluetoothXboxOneController(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
/* Check to see if it's the Xbox One S or Xbox One Elite Series 2 in Bluetooth mode */
|
||||
if (vendor_id == USB_VENDOR_MICROSOFT) {
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_S_REV1_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_S_REV2_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2_BLUETOOTH ||
|
||||
product_id == USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
ControllerHasPaddles(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
@@ -154,7 +138,8 @@ ControllerHasPaddles(Uint16 vendor_id, Uint16 product_id)
|
||||
static SDL_bool
|
||||
ControllerHasTriggerRumble(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
return SDL_IsJoystickXboxOneElite(vendor_id, product_id);
|
||||
// All the Microsoft Xbox One controllers have trigger rumble
|
||||
return (vendor_id == USB_VENDOR_MICROSOFT);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
@@ -179,7 +164,11 @@ SendAckIfNeeded(SDL_HIDAPI_Device *device, Uint8 *data, int size)
|
||||
/* The Windows driver is taking care of acks */
|
||||
#else
|
||||
if ((data[1] & 0x30) == 0x30) {
|
||||
Uint8 ack_packet[] = { 0x01, 0x20, data[2], 0x09, 0x00, data[0], 0x20, data[3], 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
Uint8 ack_packet[] = { 0x01, 0x20, 0x00, 0x09, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
ack_packet[2] = data[2];
|
||||
ack_packet[5] = data[0];
|
||||
ack_packet[7] = data[3];
|
||||
|
||||
/* The initial ack needs 0x80 added to the response, for some reason */
|
||||
if (data[0] == 0x04 && data[1] == 0xF0) {
|
||||
@@ -289,7 +278,7 @@ HIDAPI_DriverXboxOne_IsSupportedDevice(const char *name, SDL_GameControllerType
|
||||
#endif
|
||||
#ifdef __MACOSX__
|
||||
/* Wired Xbox One controllers are handled by the 360Controller driver */
|
||||
if (!IsBluetoothXboxOneController(vendor_id, product_id)) {
|
||||
if (!SDL_IsJoystickBluetoothXboxOne(vendor_id, product_id)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
#endif
|
||||
@@ -343,7 +332,7 @@ HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
|
||||
ctx->vendor_id = device->vendor_id;
|
||||
ctx->product_id = device->product_id;
|
||||
ctx->bluetooth = IsBluetoothXboxOneController(device->vendor_id, device->product_id);
|
||||
ctx->bluetooth = SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id);
|
||||
ctx->start_time = SDL_GetTicks();
|
||||
ctx->sequence = 1;
|
||||
ctx->has_paddles = ControllerHasPaddles(ctx->vendor_id, ctx->product_id);
|
||||
@@ -488,14 +477,18 @@ HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXboxOne
|
||||
}
|
||||
|
||||
if (ctx->has_share_button) {
|
||||
/* Version 1 of the firmware for Xbox One Series X */
|
||||
if (ctx->last_state[18] != data[18]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[18] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
|
||||
/* Version 2 of the firmware for Xbox One Series X */
|
||||
if (ctx->last_state[22] != data[22]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[22] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
/* Xbox Series X firmware version 5.0, report is 36 bytes, share button is in byte 18
|
||||
* Xbox Series X firmware version 5.1, report is 44 bytes, share button is in byte 18
|
||||
* Xbox Series X firmware version 5.5, report is 48 bytes, share button is in byte 22
|
||||
*/
|
||||
if (size < 48) {
|
||||
if (ctx->last_state[18] != data[18]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[18] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
} else {
|
||||
if (ctx->last_state[22] != data[22]) {
|
||||
SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_MISC1, (data[22] & 0x01) ? SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +519,7 @@ HIDAPI_DriverXboxOne_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverXboxOne
|
||||
button4_bit = 0x04;
|
||||
|
||||
/* The mapped controller state is at offset 4, the raw state is at offset 18, compare them to see if the paddles are mapped */
|
||||
paddles_mapped = (SDL_memcmp(&data[4], &data[18], 14) != 0);
|
||||
paddles_mapped = (SDL_memcmp(&data[4], &data[18], 2) != 0);
|
||||
|
||||
} else /* if (size == 38) */ {
|
||||
/* XBox One Elite Series 2 */
|
||||
@@ -1054,11 +1047,15 @@ HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_DriverXboxOne_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
SDL_free(device->context);
|
||||
device->context = NULL;
|
||||
}
|
||||
SDL_UnlockMutex(device->dev_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_log.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
@@ -51,6 +52,24 @@
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#ifdef HAVE_INOTIFY
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <fcntl.h>
|
||||
#include <limits.h> /* For the definition of NAME_MAX */
|
||||
#include <sys/inotify.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
typedef enum
|
||||
{
|
||||
ENUMERATION_UNSET,
|
||||
ENUMERATION_LIBUDEV,
|
||||
ENUMERATION_FALLBACK
|
||||
} LinuxEnumerationMethod;
|
||||
|
||||
static LinuxEnumerationMethod linux_enumeration_method = ENUMERATION_UNSET;
|
||||
#endif
|
||||
|
||||
struct joystick_hwdata
|
||||
@@ -59,12 +78,18 @@ struct joystick_hwdata
|
||||
};
|
||||
|
||||
static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
&SDL_HIDAPI_DriverGameCube,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_PS4
|
||||
&SDL_HIDAPI_DriverPS4,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_PS5
|
||||
&SDL_HIDAPI_DriverPS5,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_STADIA
|
||||
&SDL_HIDAPI_DriverStadia,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_STEAM
|
||||
&SDL_HIDAPI_DriverSteam,
|
||||
#endif
|
||||
@@ -78,9 +103,6 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
|
||||
&SDL_HIDAPI_DriverXboxOne,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
&SDL_HIDAPI_DriverGameCube,
|
||||
#endif
|
||||
};
|
||||
static int SDL_HIDAPI_numdrivers = 0;
|
||||
static SDL_SpinLock SDL_HIDAPI_spinlock;
|
||||
@@ -89,6 +111,10 @@ static int SDL_HIDAPI_numjoysticks = 0;
|
||||
static SDL_bool initialized = SDL_FALSE;
|
||||
static SDL_bool shutting_down = SDL_FALSE;
|
||||
|
||||
#if defined(HAVE_INOTIFY)
|
||||
static int inotify_fd = -1;
|
||||
#endif
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
static const SDL_UDEV_Symbols * usyms = NULL;
|
||||
#endif
|
||||
@@ -181,6 +207,46 @@ static void CallbackIOServiceFunc(void *context, io_iterator_t portIterator)
|
||||
}
|
||||
#endif /* __MACOSX__ */
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
#ifdef HAVE_INOTIFY_INIT1
|
||||
static int SDL_inotify_init1(void) {
|
||||
return inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
}
|
||||
#else
|
||||
static int SDL_inotify_init1(void) {
|
||||
int fd = inotify_init();
|
||||
if (fd < 0) return -1;
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
return fd;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
StrHasPrefix(const char *string, const char *prefix)
|
||||
{
|
||||
return (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0);
|
||||
}
|
||||
|
||||
static int
|
||||
StrIsInteger(const char *string)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (*string == '\0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (p = string; *p != '\0'; p++) {
|
||||
if (*p < '0' || *p > '9') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
HIDAPI_InitializeDiscovery()
|
||||
{
|
||||
@@ -270,24 +336,55 @@ HIDAPI_InitializeDiscovery()
|
||||
#endif // __MACOSX__
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
SDL_HIDAPI_discovery.m_pUdev = NULL;
|
||||
SDL_HIDAPI_discovery.m_pUdevMonitor = NULL;
|
||||
SDL_HIDAPI_discovery.m_nUdevFd = -1;
|
||||
if (linux_enumeration_method == ENUMERATION_LIBUDEV) {
|
||||
SDL_HIDAPI_discovery.m_pUdev = NULL;
|
||||
SDL_HIDAPI_discovery.m_pUdevMonitor = NULL;
|
||||
SDL_HIDAPI_discovery.m_nUdevFd = -1;
|
||||
|
||||
usyms = SDL_UDEV_GetUdevSyms();
|
||||
if (usyms) {
|
||||
SDL_HIDAPI_discovery.m_pUdev = usyms->udev_new();
|
||||
}
|
||||
if (SDL_HIDAPI_discovery.m_pUdev) {
|
||||
SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev");
|
||||
if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
|
||||
usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
|
||||
usyms = SDL_UDEV_GetUdevSyms();
|
||||
if (usyms) {
|
||||
SDL_HIDAPI_discovery.m_pUdev = usyms->udev_new();
|
||||
}
|
||||
if (SDL_HIDAPI_discovery.m_pUdev) {
|
||||
SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev");
|
||||
if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
|
||||
usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
{
|
||||
#if defined(HAVE_INOTIFY)
|
||||
inotify_fd = SDL_inotify_init1();
|
||||
|
||||
if (inotify_fd < 0) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
|
||||
"Unable to initialize inotify, falling back to polling: %s",
|
||||
strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
/* We need to watch for attribute changes in addition to
|
||||
* creation, because when a device is first created, it has
|
||||
* permissions that we can't read. When udev chmods it to
|
||||
* something that we maybe *can* read, we'll get an
|
||||
* IN_ATTRIB event to tell us. */
|
||||
if (inotify_add_watch(inotify_fd, "/dev",
|
||||
IN_CREATE | IN_DELETE | IN_MOVE | IN_ATTRIB) < 0) {
|
||||
close(inotify_fd);
|
||||
inotify_fd = -1;
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
|
||||
"Unable to add inotify watch, falling back to polling: %s",
|
||||
strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
|
||||
#endif /* HAVE_INOTIFY */
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -328,31 +425,78 @@ HIDAPI_UpdateDiscovery()
|
||||
#endif
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
if (SDL_HIDAPI_discovery.m_nUdevFd >= 0) {
|
||||
/* Drain all notification events.
|
||||
* We don't expect a lot of device notifications so just
|
||||
* do a new discovery on any kind or number of notifications.
|
||||
* This could be made more restrictive if necessary.
|
||||
*/
|
||||
for (;;) {
|
||||
struct pollfd PollUdev;
|
||||
struct udev_device *pUdevDevice;
|
||||
if (linux_enumeration_method == ENUMERATION_LIBUDEV) {
|
||||
if (SDL_HIDAPI_discovery.m_nUdevFd >= 0) {
|
||||
/* Drain all notification events.
|
||||
* We don't expect a lot of device notifications so just
|
||||
* do a new discovery on any kind or number of notifications.
|
||||
* This could be made more restrictive if necessary.
|
||||
*/
|
||||
for (;;) {
|
||||
struct pollfd PollUdev;
|
||||
struct udev_device *pUdevDevice;
|
||||
|
||||
PollUdev.fd = SDL_HIDAPI_discovery.m_nUdevFd;
|
||||
PollUdev.events = POLLIN;
|
||||
if (poll(&PollUdev, 1, 0) != 1) {
|
||||
break;
|
||||
}
|
||||
PollUdev.fd = SDL_HIDAPI_discovery.m_nUdevFd;
|
||||
PollUdev.events = POLLIN;
|
||||
if (poll(&PollUdev, 1, 0) != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
|
||||
|
||||
pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
if (pUdevDevice) {
|
||||
usyms->udev_device_unref(pUdevDevice);
|
||||
pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
if (pUdevDevice) {
|
||||
const char *action = NULL;
|
||||
action = usyms->udev_device_get_action(pUdevDevice);
|
||||
if (!action || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
|
||||
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
|
||||
}
|
||||
usyms->udev_device_unref(pUdevDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
{
|
||||
#if defined(HAVE_INOTIFY)
|
||||
if (inotify_fd >= 0) {
|
||||
union
|
||||
{
|
||||
struct inotify_event event;
|
||||
char storage[4096];
|
||||
char enough_for_inotify[sizeof (struct inotify_event) + NAME_MAX + 1];
|
||||
} buf;
|
||||
ssize_t bytes;
|
||||
size_t remain = 0;
|
||||
size_t len;
|
||||
|
||||
bytes = read(inotify_fd, &buf, sizeof (buf));
|
||||
|
||||
if (bytes > 0) {
|
||||
remain = (size_t) bytes;
|
||||
}
|
||||
|
||||
while (remain > 0) {
|
||||
if (buf.event.len > 0 &&
|
||||
!SDL_HIDAPI_discovery.m_bHaveDevicesChanged) {
|
||||
if (StrHasPrefix(buf.event.name, "hidraw") &&
|
||||
StrIsInteger(buf.event.name + strlen ("hidraw"))) {
|
||||
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
|
||||
/* We found an hidraw change. We still continue to
|
||||
* drain the inotify fd to avoid leaving old
|
||||
* notifications in the queue. */
|
||||
}
|
||||
}
|
||||
|
||||
len = sizeof (struct inotify_event) + buf.event.len;
|
||||
remain -= len;
|
||||
|
||||
if (remain != 0) {
|
||||
memmove(&buf.storage[0], &buf.storage[len], remain);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_INOTIFY */
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -376,7 +520,8 @@ HIDAPI_ShutdownDiscovery()
|
||||
#endif
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
if (usyms) {
|
||||
if (linux_enumeration_method == ENUMERATION_LIBUDEV &&
|
||||
usyms) {
|
||||
if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
|
||||
usyms->udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor);
|
||||
}
|
||||
@@ -410,6 +555,12 @@ HIDAPI_DumpPacket(const char *prefix, Uint8 *data, int size)
|
||||
SDL_free(buffer);
|
||||
}
|
||||
|
||||
float
|
||||
HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max)
|
||||
{
|
||||
return output_min + (output_max - output_min) * (val - val_min) / (val_max - val_min);
|
||||
}
|
||||
|
||||
static void HIDAPI_JoystickDetect(void);
|
||||
static void HIDAPI_JoystickClose(SDL_Joystick * joystick);
|
||||
|
||||
@@ -437,8 +588,14 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
|
||||
const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
|
||||
int i;
|
||||
SDL_GameControllerType type;
|
||||
SDL_JoystickGUID check_guid;
|
||||
|
||||
if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) {
|
||||
/* Make sure we have a generic GUID here, otherwise if we pass a HIDAPI
|
||||
guid, this call will create a game controller mapping for the device.
|
||||
*/
|
||||
check_guid = device->guid;
|
||||
check_guid.data[14] = 0;
|
||||
if (SDL_ShouldIgnoreJoystick(device->name, check_guid)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -585,6 +742,28 @@ HIDAPI_JoystickInit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
if (linux_enumeration_method == ENUMERATION_UNSET) {
|
||||
if (SDL_getenv("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV") != NULL) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"udev disabled by SDL_HIDAPI_JOYSTICK_DISABLE_UDEV");
|
||||
linux_enumeration_method = ENUMERATION_FALLBACK;
|
||||
} else if (access("/.flatpak-info", F_OK) == 0
|
||||
|| access("/run/host/container-manager", F_OK) == 0) {
|
||||
/* Explicitly check `/.flatpak-info` because, for old versions of
|
||||
* Flatpak, this was the only available way to tell if we were in
|
||||
* a Flatpak container. */
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Container detected, disabling HIDAPI udev integration");
|
||||
linux_enumeration_method = ENUMERATION_FALLBACK;
|
||||
} else {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Using udev for HIDAPI joystick device discovery");
|
||||
linux_enumeration_method = ENUMERATION_LIBUDEV;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
|
||||
/* The hidapi framwork is weak-linked on Apple platforms */
|
||||
int HID_API_EXPORT HID_API_CALL hid_init(void) __attribute__((weak_import));
|
||||
@@ -883,12 +1062,13 @@ HIDAPI_UpdateDeviceList(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove any devices that weren't seen */
|
||||
/* Remove any devices that weren't seen or have been disconnected due to read errors */
|
||||
device = SDL_HIDAPI_devices;
|
||||
while (device) {
|
||||
SDL_HIDAPI_Device *next = device->next;
|
||||
|
||||
if (!device->seen) {
|
||||
if (!device->seen ||
|
||||
(device->driver && device->num_joysticks == 0 && !device->dev)) {
|
||||
HIDAPI_DelDevice(device);
|
||||
}
|
||||
device = next;
|
||||
@@ -1239,6 +1419,13 @@ HIDAPI_JoystickQuit(void)
|
||||
|
||||
SDL_HIDAPI_QuitRumble();
|
||||
|
||||
#if defined(HAVE_INOTIFY)
|
||||
if (inotify_fd >= 0) {
|
||||
close(inotify_fd);
|
||||
inotify_fd = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
while (SDL_HIDAPI_devices) {
|
||||
HIDAPI_DelDevice(SDL_HIDAPI_devices);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -31,12 +31,13 @@
|
||||
#include "../usb_ids.h"
|
||||
|
||||
/* This is the full set of HIDAPI drivers available */
|
||||
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
#define SDL_JOYSTICK_HIDAPI_PS4
|
||||
#define SDL_JOYSTICK_HIDAPI_PS5
|
||||
#define SDL_JOYSTICK_HIDAPI_STADIA
|
||||
#define SDL_JOYSTICK_HIDAPI_SWITCH
|
||||
#define SDL_JOYSTICK_HIDAPI_XBOX360
|
||||
#define SDL_JOYSTICK_HIDAPI_XBOXONE
|
||||
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
|
||||
/* Very basic Steam Controller support on mobile devices */
|
||||
@@ -105,14 +106,15 @@ typedef struct _SDL_HIDAPI_DeviceDriver
|
||||
|
||||
|
||||
/* HIDAPI device support */
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
|
||||
|
||||
/* Return true if a HID device is present and supported as a joystick */
|
||||
extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
|
||||
@@ -123,6 +125,8 @@ extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickI
|
||||
|
||||
extern void HIDAPI_DumpPacket(const char *prefix, Uint8 *data, int size);
|
||||
|
||||
extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max);
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 2020 Valve Corporation
|
||||
Copyright (C) 2021 Valve Corporation
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -89,6 +89,7 @@ static id disconnectObserver = nil;
|
||||
#define ENABLE_MFI_RUMBLE
|
||||
#define ENABLE_MFI_LIGHT
|
||||
#define ENABLE_MFI_SENSORS
|
||||
#define ENABLE_MFI_SYSTEM_GESTURE_STATE
|
||||
#define ENABLE_PHYSICAL_INPUT_PROFILE
|
||||
#endif
|
||||
|
||||
@@ -153,8 +154,9 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
|
||||
GCExtendedGamepad *gamepad = controller.extendedGamepad;
|
||||
BOOL is_xbox = [controller.vendorName containsString: @"Xbox"];
|
||||
BOOL is_ps4 = [controller.vendorName containsString: @"DUALSHOCK"];
|
||||
BOOL is_ps5 = [controller.vendorName containsString: @"DualSense"];
|
||||
#if TARGET_OS_TV
|
||||
BOOL is_MFi = (!is_xbox && !is_ps4);
|
||||
BOOL is_MFi = (!is_xbox && !is_ps4 && !is_ps5);
|
||||
#endif
|
||||
int nbuttons = 0;
|
||||
|
||||
@@ -250,6 +252,10 @@ IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controlle
|
||||
} else {
|
||||
subtype = 0;
|
||||
}
|
||||
} else if (is_ps5) {
|
||||
vendor = USB_VENDOR_SONY;
|
||||
product = USB_PRODUCT_SONY_DS5;
|
||||
subtype = 0;
|
||||
} else {
|
||||
vendor = USB_VENDOR_APPLE;
|
||||
product = 1;
|
||||
@@ -656,6 +662,18 @@ IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
}
|
||||
#endif /* ENABLE_MFI_SENSORS */
|
||||
|
||||
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
|
||||
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
|
||||
GCController *controller = joystick->hwdata->controller;
|
||||
if (controller.extendedGamepad) {
|
||||
GCExtendedGamepad *gamepad = controller.extendedGamepad;
|
||||
if ([gamepad.buttonOptions isBoundToSystemGesture]) {
|
||||
gamepad.buttonOptions.preferredSystemGestureState = GCSystemGestureStateDisabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_MFI_SYSTEM_GESTURE_STATE */
|
||||
|
||||
#endif /* SDL_JOYSTICK_MFI */
|
||||
}
|
||||
}
|
||||
@@ -1331,7 +1349,18 @@ IOS_JoystickClose(SDL_Joystick *joystick)
|
||||
GCController *controller = device->controller;
|
||||
controller.controllerPausedHandler = nil;
|
||||
controller.playerIndex = -1;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
|
||||
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
|
||||
GCController *controller = joystick->hwdata->controller;
|
||||
if (controller.extendedGamepad) {
|
||||
GCExtendedGamepad *gamepad = controller.extendedGamepad;
|
||||
gamepad.buttonOptions.preferredSystemGestureState = GCSystemGestureStateEnabled;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_MFI_SYSTEM_GESTURE_STATE */
|
||||
|
||||
#endif /* SDL_JOYSTICK_MFI */
|
||||
}
|
||||
}
|
||||
if (device->remote) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -56,18 +56,6 @@
|
||||
#ifndef SYN_DROPPED
|
||||
#define SYN_DROPPED 3
|
||||
#endif
|
||||
#ifndef BTN_SOUTH
|
||||
#define BTN_SOUTH 0x130
|
||||
#endif
|
||||
#ifndef BTN_EAST
|
||||
#define BTN_EAST 0x131
|
||||
#endif
|
||||
#ifndef BTN_NORTH
|
||||
#define BTN_NORTH 0x133
|
||||
#endif
|
||||
#ifndef BTN_WEST
|
||||
#define BTN_WEST 0x134
|
||||
#endif
|
||||
#ifndef BTN_DPAD_UP
|
||||
#define BTN_DPAD_UP 0x220
|
||||
#endif
|
||||
@@ -113,6 +101,8 @@ typedef struct SDL_joylist_item
|
||||
|
||||
/* Steam Controller support */
|
||||
SDL_bool m_bSteamController;
|
||||
|
||||
SDL_GamepadMapping *mapping;
|
||||
} SDL_joylist_item;
|
||||
|
||||
static SDL_joylist_item *SDL_joylist = NULL;
|
||||
@@ -376,6 +366,9 @@ MaybeRemoveDevice(const char *path)
|
||||
|
||||
SDL_PrivateJoystickRemoved(item->device_instance);
|
||||
|
||||
if (item->mapping) {
|
||||
SDL_free(item->mapping);
|
||||
}
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
@@ -658,7 +651,10 @@ LINUX_JoystickInit(void)
|
||||
enumeration_method = ENUMERATION_FALLBACK;
|
||||
}
|
||||
else if (access("/.flatpak-info", F_OK) == 0
|
||||
|| access("/run/pressure-vessel", F_OK) == 0) {
|
||||
|| access("/run/host/container-manager", F_OK) == 0) {
|
||||
/* Explicitly check `/.flatpak-info` because, for old versions of
|
||||
* Flatpak, this was the only available way to tell if we were in
|
||||
* a Flatpak container. */
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Container detected, disabling udev integration");
|
||||
enumeration_method = ENUMERATION_FALLBACK;
|
||||
@@ -1400,6 +1396,12 @@ static SDL_bool
|
||||
LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
SDL_joylist_item *item = JoystickByDevIndex(device_index);
|
||||
|
||||
if (item->mapping) {
|
||||
SDL_memcpy(out, item->mapping, sizeof(*out));
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
|
||||
if (joystick == NULL) {
|
||||
@@ -1422,24 +1424,24 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
|
||||
/* We have a gamepad, start filling out the mappings */
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_SOUTH]) {
|
||||
if (joystick->hwdata->has_key[BTN_A]) {
|
||||
out->a.kind = EMappingKind_Button;
|
||||
out->a.target = joystick->hwdata->key_map[BTN_SOUTH];
|
||||
out->a.target = joystick->hwdata->key_map[BTN_A];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_EAST]) {
|
||||
if (joystick->hwdata->has_key[BTN_B]) {
|
||||
out->b.kind = EMappingKind_Button;
|
||||
out->b.target = joystick->hwdata->key_map[BTN_EAST];
|
||||
out->b.target = joystick->hwdata->key_map[BTN_B];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_NORTH]) {
|
||||
out->y.kind = EMappingKind_Button;
|
||||
out->y.target = joystick->hwdata->key_map[BTN_NORTH];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_WEST]) {
|
||||
if (joystick->hwdata->has_key[BTN_X]) {
|
||||
out->x.kind = EMappingKind_Button;
|
||||
out->x.target = joystick->hwdata->key_map[BTN_WEST];
|
||||
out->x.target = joystick->hwdata->key_map[BTN_X];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_Y]) {
|
||||
out->y.kind = EMappingKind_Button;
|
||||
out->y.target = joystick->hwdata->key_map[BTN_Y];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_SELECT]) {
|
||||
@@ -1503,11 +1505,17 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
if (joystick->hwdata->has_key[BTN_TL2]) {
|
||||
out->lefttrigger.kind = EMappingKind_Button;
|
||||
out->lefttrigger.target = joystick->hwdata->key_map[BTN_TL2];
|
||||
} else if (joystick->hwdata->has_abs[ABS_Z]) {
|
||||
out->lefttrigger.kind = EMappingKind_Axis;
|
||||
out->lefttrigger.target = joystick->hwdata->abs_map[ABS_Z];
|
||||
}
|
||||
|
||||
if (joystick->hwdata->has_key[BTN_TR2]) {
|
||||
out->righttrigger.kind = EMappingKind_Button;
|
||||
out->righttrigger.target = joystick->hwdata->key_map[BTN_TR2];
|
||||
} else if (joystick->hwdata->has_abs[ABS_RZ]) {
|
||||
out->righttrigger.kind = EMappingKind_Axis;
|
||||
out->righttrigger.target = joystick->hwdata->abs_map[ABS_RZ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1563,6 +1571,12 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
LINUX_JoystickClose(joystick);
|
||||
SDL_free(joystick);
|
||||
|
||||
/* Cache the mapping for later */
|
||||
item->mapping = (SDL_GamepadMapping *)SDL_malloc(sizeof(*item->mapping));
|
||||
if (item->mapping) {
|
||||
SDL_memcpy(item->mapping, out, sizeof(*out));
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -74,6 +74,7 @@ struct joystick_hwdata
|
||||
|
||||
/* Steam Controller support */
|
||||
SDL_bool m_bSteamController;
|
||||
|
||||
/* 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) */
|
||||
int hats_indices[4];
|
||||
SDL_bool has_hat[4];
|
||||
|
787
externals/SDL/src/joystick/os2/SDL_os2joystick.c
vendored
Executable file
787
externals/SDL/src/joystick/os2/SDL_os2joystick.c
vendored
Executable file
@@ -0,0 +1,787 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_OS2
|
||||
|
||||
/* OS/2 Joystick driver, contributed by Daniel Caetano */
|
||||
|
||||
#define INCL_DOSDEVICES
|
||||
#define INCL_DOSDEVIOCTL
|
||||
#define INCL_DOSMEMMGR
|
||||
#include <os2.h>
|
||||
|
||||
/*****************************************************************
|
||||
* OS/2 Joystick driver defs. Based on docs at edm2.com and in old
|
||||
* drivers available at hobbes.nmsu.edu and www.os2site.com
|
||||
*****************************************************************/
|
||||
|
||||
#define GAME_GET_VERSION 0x01
|
||||
#define GAME_GET_PARMS 0x02
|
||||
#define GAME_GET_CALIB 0x04
|
||||
#define GAME_GET_STATUS 0x10
|
||||
|
||||
#define IOCTL_CAT_USER 0x80
|
||||
#define GAME_PORT_GET 0x20
|
||||
#define GAME_PORT_RESET 0x60
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct {
|
||||
USHORT uJs_AxCnt, uJs_AyCnt; /* A joystick X/Y pos */
|
||||
USHORT uJs_BxCnt, uJs_ByCnt; /* B joystick X/Y pos */
|
||||
USHORT usJs_ButtonA1Cnt, usJs_ButtonA2Cnt;/* A1/A2 press cnts */
|
||||
USHORT usJs_ButtonB1Cnt, usJs_ButtonB2Cnt;/* B1/B2 press cnts */
|
||||
UCHAR ucJs_JoyStickMask; /* mask of connected joystick pots */
|
||||
UCHAR ucJs_ButtonStatus; /* bits of switches down */
|
||||
ULONG ulJs_Ticks; /* total clock ticks (60 Hz) */
|
||||
} GAME_PORT_STRUCT;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
USHORT useA, useB;
|
||||
USHORT mode;
|
||||
USHORT format;
|
||||
USHORT sampDiv;
|
||||
USHORT scale;
|
||||
USHORT res1, res2;
|
||||
} GAME_PARM_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
SHORT x, y;
|
||||
} GAME_2DPOS_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
SHORT lower, centre, upper;
|
||||
} GAME_3POS_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
GAME_3POS_STRUCT Ax, Ay, Bx, By;
|
||||
} GAME_CALIB_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
GAME_2DPOS_STRUCT A, B;
|
||||
USHORT butMask;
|
||||
} GAME_DATA_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
GAME_DATA_STRUCT curdata;
|
||||
USHORT b1cnt, b2cnt, b3cnt, b4cnt;
|
||||
} GAME_STATUS_STRUCT;
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_events.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
|
||||
static HFILE hJoyPort = NULLHANDLE; /* Joystick GAME$ Port Address */
|
||||
#define MAX_JOYSTICKS 2 /* Maximum of two joysticks */
|
||||
#define MAX_AXES 4 /* each joystick can have up to 4 axes */
|
||||
#define MAX_BUTTONS 8 /* 8 buttons */
|
||||
#define MAX_HATS 0 /* 0 hats - OS/2 doesn't support it */
|
||||
#define MAX_BALLS 0 /* and 0 balls - OS/2 doesn't support it */
|
||||
#define MAX_JOYNAME 128 /* Joystick name may have 128 characters */
|
||||
/* Calc Button Flag for buttons A to D */
|
||||
#define JOY_BUTTON_FLAG(n) (1<<n)
|
||||
|
||||
/* Joystick data... hold information about detected devices */
|
||||
typedef struct SYS_JoyData_s
|
||||
{
|
||||
Sint8 id; /* Device ID */
|
||||
char szDeviceName[MAX_JOYNAME]; /* Device Name */
|
||||
char axes; /* Number of axes */
|
||||
char buttons; /* Number of buttons */
|
||||
char hats; /* Number of buttons */
|
||||
char balls; /* Number of buttons */
|
||||
int axes_min[MAX_AXES]; /* minimum callibration value for axes */
|
||||
int axes_med[MAX_AXES]; /* medium callibration value for axes */
|
||||
int axes_max[MAX_AXES]; /* maximum callibration value for axes */
|
||||
int buttoncalc[4]; /* Used for buttons 5, 6, 7 and 8. */
|
||||
} SYS_JoyData_t, *SYS_JoyData_p;
|
||||
|
||||
static SYS_JoyData_t SYS_JoyData[MAX_JOYSTICKS];
|
||||
|
||||
/* Structure used to convert data from OS/2 driver format to SDL format */
|
||||
struct _transaxes
|
||||
{
|
||||
int offset; /* Center Offset */
|
||||
float scale1; /* Center to left/up Scale */
|
||||
float scale2; /* Center to right/down Scale */
|
||||
};
|
||||
|
||||
struct joystick_hwdata
|
||||
{
|
||||
Sint8 id;
|
||||
struct _transaxes transaxes[MAX_AXES];
|
||||
};
|
||||
|
||||
/* Structure used to get values from Joystick Environment Variable */
|
||||
struct _joycfg
|
||||
{
|
||||
char name[MAX_JOYNAME];
|
||||
unsigned int axes;
|
||||
unsigned int buttons;
|
||||
unsigned int hats;
|
||||
unsigned int balls;
|
||||
};
|
||||
|
||||
/* OS/2 Implementation Function Prototypes */
|
||||
static int joyPortOpen(HFILE * hGame);
|
||||
static void joyPortClose(HFILE * hGame);
|
||||
static int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars);
|
||||
static int joyGetEnv(struct _joycfg * joydata);
|
||||
|
||||
|
||||
static int numjoysticks = 0;
|
||||
|
||||
/************************************************************************/
|
||||
/* Function to scan the system for joysticks. */
|
||||
/* Joystick 0 should be the system default joystick. */
|
||||
/* It should return 0, or -1 on an unrecoverable fatal error. */
|
||||
/************************************************************************/
|
||||
static int OS2_JoystickInit(void)
|
||||
{
|
||||
APIRET rc; /* Generic OS/2 return code */
|
||||
GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */
|
||||
GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */
|
||||
GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */
|
||||
ULONG ulDataLen; /* Size of data */
|
||||
ULONG ulLastTick; /* Tick Counter for timing operations */
|
||||
Uint8 maxdevs; /* Maximum number of devices */
|
||||
Uint8 numdevs; /* Number of present devices */
|
||||
Uint8 maxbut; /* Maximum number of buttons... */
|
||||
Uint8 i; /* Temporary Count Vars */
|
||||
Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */
|
||||
struct _joycfg joycfg; /* Joy Configuration from envvar */
|
||||
|
||||
/* Open GAME$ port */
|
||||
if (joyPortOpen(&hJoyPort) < 0) return 0; /* Cannot open... report no joystick */
|
||||
/* Get Max Number of Devices */
|
||||
ulDataLen = sizeof(stGameParms);
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS,
|
||||
NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */
|
||||
if (rc != 0)
|
||||
{
|
||||
joyPortClose(&hJoyPort);
|
||||
return SDL_SetError("Could not read joystick port.");
|
||||
}
|
||||
if (stGameParms.useA != 0) maxdevs++;
|
||||
if (stGameParms.useB != 0) maxdevs++;
|
||||
if (maxdevs > MAX_JOYSTICKS) maxdevs = MAX_JOYSTICKS;
|
||||
|
||||
/* Defines min/max axes values (callibration) */
|
||||
ulDataLen = sizeof(stGameCalib);
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB,
|
||||
NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen);
|
||||
if (rc != 0)
|
||||
{
|
||||
joyPortClose(&hJoyPort);
|
||||
return SDL_SetError("Could not read callibration data.");
|
||||
}
|
||||
|
||||
/* Determine how many joysticks are active */
|
||||
numdevs = 0; /* Points no device */
|
||||
ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */
|
||||
ulDataLen = sizeof(ucNewJoystickMask);
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET,
|
||||
&ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, NULL);
|
||||
if (rc == 0)
|
||||
{
|
||||
ulDataLen = sizeof(stJoyStatus);
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
|
||||
NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
|
||||
if (rc != 0)
|
||||
{
|
||||
joyPortClose(&hJoyPort);
|
||||
return SDL_SetError("Could not call joystick port.");
|
||||
}
|
||||
ulLastTick = stJoyStatus.ulJs_Ticks;
|
||||
while (stJoyStatus.ulJs_Ticks == ulLastTick)
|
||||
{
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
|
||||
NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
|
||||
}
|
||||
if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) numdevs++;
|
||||
if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) numdevs++;
|
||||
}
|
||||
|
||||
if (numdevs > maxdevs) numdevs = maxdevs;
|
||||
|
||||
/* If *any* joystick was detected... Let's configure SDL for them */
|
||||
if (numdevs > 0)
|
||||
{
|
||||
/* Verify if it is a "user defined" joystick */
|
||||
if (joyGetEnv(&joycfg))
|
||||
{
|
||||
GAME_3POS_STRUCT * axis[4];
|
||||
axis[0] = &stGameCalib.Ax;
|
||||
axis[1] = &stGameCalib.Ay;
|
||||
axis[2] = &stGameCalib.Bx;
|
||||
axis[3] = &stGameCalib.By;
|
||||
|
||||
/* Say it has one device only (user defined is always one device only) */
|
||||
numdevs = 1;
|
||||
|
||||
/* Define Device 0 as... */
|
||||
SYS_JoyData[0].id = 0;
|
||||
|
||||
/* Define Number of Axes... up to 4 */
|
||||
if (joycfg.axes>MAX_AXES) joycfg.axes = MAX_AXES;
|
||||
SYS_JoyData[0].axes = joycfg.axes;
|
||||
|
||||
/* Define number of buttons... 8 if 2 axes, 6 if 3 axes and 4 if 4 axes */
|
||||
maxbut = MAX_BUTTONS;
|
||||
if (joycfg.axes>2) maxbut -= ((joycfg.axes - 2)<<1); /* MAX_BUTTONS - 2*(axes-2) */
|
||||
if (joycfg.buttons > maxbut) joycfg.buttons = maxbut;
|
||||
SYS_JoyData[0].buttons = joycfg.buttons;
|
||||
|
||||
/* Define number of hats */
|
||||
if (joycfg.hats > MAX_HATS) joycfg.hats = MAX_HATS;
|
||||
SYS_JoyData[0].hats = joycfg.hats;
|
||||
|
||||
/* Define number of balls */
|
||||
if (joycfg.balls > MAX_BALLS) joycfg.balls = MAX_BALLS;
|
||||
SYS_JoyData[0].balls = joycfg.balls;
|
||||
|
||||
/* Initialize Axes Callibration Values */
|
||||
for (i=0; i<joycfg.axes; i++)
|
||||
{
|
||||
SYS_JoyData[0].axes_min[i] = axis[i]->lower;
|
||||
SYS_JoyData[0].axes_med[i] = axis[i]->centre;
|
||||
SYS_JoyData[0].axes_max[i] = axis[i]->upper;
|
||||
}
|
||||
/* Initialize Buttons 5 to 8 structures */
|
||||
if (joycfg.buttons>=5) SYS_JoyData[0].buttoncalc[0] = ((axis[2]->lower+axis[3]->centre)>>1);
|
||||
if (joycfg.buttons>=6) SYS_JoyData[0].buttoncalc[1] = ((axis[3]->lower+axis[3]->centre)>>1);
|
||||
if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2] = ((axis[2]->upper+axis[3]->centre)>>1);
|
||||
if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3] = ((axis[3]->upper+axis[3]->centre)>>1);
|
||||
/* Intialize Joystick Name */
|
||||
SDL_strlcpy (SYS_JoyData[0].szDeviceName,joycfg.name, SDL_arraysize(SYS_JoyData[0].szDeviceName));
|
||||
}
|
||||
/* Default Init ... autoconfig */
|
||||
else
|
||||
{
|
||||
/* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */
|
||||
if (numdevs == 2)
|
||||
{
|
||||
/* Define Device 0 as 4 axes, 4 buttons */
|
||||
SYS_JoyData[0].id=0;
|
||||
SYS_JoyData[0].axes = 4;
|
||||
SYS_JoyData[0].buttons = 4;
|
||||
SYS_JoyData[0].hats = 0;
|
||||
SYS_JoyData[0].balls = 0;
|
||||
SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
|
||||
SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
|
||||
SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
|
||||
SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
|
||||
SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
|
||||
SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
|
||||
SYS_JoyData[0].axes_min[2] = stGameCalib.Bx.lower;
|
||||
SYS_JoyData[0].axes_med[2] = stGameCalib.Bx.centre;
|
||||
SYS_JoyData[0].axes_max[2] = stGameCalib.Bx.upper;
|
||||
SYS_JoyData[0].axes_min[3] = stGameCalib.By.lower;
|
||||
SYS_JoyData[0].axes_med[3] = stGameCalib.By.centre;
|
||||
SYS_JoyData[0].axes_max[3] = stGameCalib.By.upper;
|
||||
/* Define Device 1 as 2 axes, 2 buttons */
|
||||
SYS_JoyData[1].id=1;
|
||||
SYS_JoyData[1].axes = 2;
|
||||
SYS_JoyData[1].buttons = 2;
|
||||
SYS_JoyData[1].hats = 0;
|
||||
SYS_JoyData[1].balls = 0;
|
||||
SYS_JoyData[1].axes_min[0] = stGameCalib.Bx.lower;
|
||||
SYS_JoyData[1].axes_med[0] = stGameCalib.Bx.centre;
|
||||
SYS_JoyData[1].axes_max[0] = stGameCalib.Bx.upper;
|
||||
SYS_JoyData[1].axes_min[1] = stGameCalib.By.lower;
|
||||
SYS_JoyData[1].axes_med[1] = stGameCalib.By.centre;
|
||||
SYS_JoyData[1].axes_max[1] = stGameCalib.By.upper;
|
||||
}
|
||||
/* One joystick only? */
|
||||
else
|
||||
{
|
||||
/* If it is joystick A... */
|
||||
if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0)
|
||||
{
|
||||
/* Define Device 0 as 2 axes, 4 buttons */
|
||||
SYS_JoyData[0].id=0;
|
||||
SYS_JoyData[0].axes = 2;
|
||||
SYS_JoyData[0].buttons = 4;
|
||||
SYS_JoyData[0].hats = 0;
|
||||
SYS_JoyData[0].balls = 0;
|
||||
SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
|
||||
SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
|
||||
SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
|
||||
SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
|
||||
SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
|
||||
SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
|
||||
}
|
||||
/* If not, it is joystick B */
|
||||
else
|
||||
{
|
||||
/* Define Device 1 as 2 axes, 2 buttons */
|
||||
SYS_JoyData[0].id=1;
|
||||
SYS_JoyData[0].axes = 2;
|
||||
SYS_JoyData[0].buttons = 2;
|
||||
SYS_JoyData[0].hats = 0;
|
||||
SYS_JoyData[0].balls = 0;
|
||||
SYS_JoyData[0].axes_min[0] = stGameCalib.Bx.lower;
|
||||
SYS_JoyData[0].axes_med[0] = stGameCalib.Bx.centre;
|
||||
SYS_JoyData[0].axes_max[0] = stGameCalib.Bx.upper;
|
||||
SYS_JoyData[0].axes_min[1] = stGameCalib.By.lower;
|
||||
SYS_JoyData[0].axes_med[1] = stGameCalib.By.centre;
|
||||
SYS_JoyData[0].axes_max[1] = stGameCalib.By.upper;
|
||||
}
|
||||
}
|
||||
|
||||
/* Hack to define Joystick Port Names */
|
||||
if (numdevs > maxdevs) numdevs = maxdevs;
|
||||
|
||||
for (i = 0; i < numdevs; i++)
|
||||
{
|
||||
SDL_snprintf(SYS_JoyData[i].szDeviceName,
|
||||
SDL_arraysize(SYS_JoyData[i].szDeviceName),
|
||||
"Default Joystick %c", 'A'+SYS_JoyData[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Return the number of devices found */
|
||||
numjoysticks = numdevs;
|
||||
return numdevs;
|
||||
}
|
||||
|
||||
static int OS2_NumJoysticks(void)
|
||||
{
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
static void OS2_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
/***********************************************************/
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
/***********************************************************/
|
||||
static const char *OS2_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
/* No need to verify if device exists, already done in upper layer */
|
||||
return SYS_JoyData[device_index].szDeviceName;
|
||||
}
|
||||
|
||||
static int OS2_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void OS2_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_JoystickGUID OS2_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = OS2_JoystickGetDeviceName(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
static SDL_JoystickID OS2_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Function to open a joystick for use. */
|
||||
/* The joystick to open is specified by the device index. */
|
||||
/* This should fill the nbuttons and naxes fields of the joystick structure. */
|
||||
/* It returns 0, or -1 if there is an error. */
|
||||
/******************************************************************************/
|
||||
static int OS2_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
int index; /* Index shortcut for index in joystick structure */
|
||||
int i; /* Generic Counter */
|
||||
|
||||
/* allocate memory for system specific hardware data */
|
||||
joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
|
||||
if (joystick->hwdata == NULL)
|
||||
{
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
/* Reset Hardware Data */
|
||||
SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
|
||||
|
||||
/* ShortCut Pointer */
|
||||
index = device_index;
|
||||
joystick->instance_id = device_index;
|
||||
|
||||
/* Define offsets and scales for all axes */
|
||||
joystick->hwdata->id = SYS_JoyData[index].id;
|
||||
for (i = 0; i < MAX_AXES; ++i)
|
||||
{
|
||||
if ((i < 2) || i < SYS_JoyData[index].axes)
|
||||
{
|
||||
joystick->hwdata->transaxes[i].offset = ((SDL_JOYSTICK_AXIS_MAX + SDL_JOYSTICK_AXIS_MIN)>>1) - SYS_JoyData[index].axes_med[i];
|
||||
joystick->hwdata->transaxes[i].scale1 = (float)abs((SDL_JOYSTICK_AXIS_MIN/SYS_JoyData[index].axes_min[i]));
|
||||
joystick->hwdata->transaxes[i].scale2 = (float)abs((SDL_JOYSTICK_AXIS_MAX/SYS_JoyData[index].axes_max[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
joystick->hwdata->transaxes[i].offset = 0;
|
||||
joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */
|
||||
joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */
|
||||
}
|
||||
}
|
||||
|
||||
/* fill nbuttons, naxes, and nhats fields */
|
||||
joystick->nbuttons = SYS_JoyData[index].buttons;
|
||||
joystick->naxes = SYS_JoyData[index].axes;
|
||||
|
||||
/* joystick->nhats = SYS_JoyData[index].hats; */
|
||||
joystick->nhats = 0; /* No support for hats at this time */
|
||||
|
||||
/* joystick->nballs = SYS_JoyData[index].balls; */
|
||||
joystick->nballs = 0; /* No support for balls at this time */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int OS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int OS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool OS2_JoystickHasLED(SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int OS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int OS2_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/* Function to update the state of a joystick - called as a device poll. */
|
||||
/* This function shouldn't update the joystick structure directly, */
|
||||
/* but instead should call SDL_PrivateJoystick*() to deliver events */
|
||||
/* and update joystick device state. */
|
||||
/***************************************************************************/
|
||||
static void OS2_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
APIRET rc; /* Generic OS/2 return code */
|
||||
int index; /* index shortcurt to joystick index */
|
||||
int i; /* Generic counter */
|
||||
int normbut; /* Number of buttons reported by joystick */
|
||||
int corr; /* Correction for button names */
|
||||
Sint16 value; /* Values used to update axis values */
|
||||
struct _transaxes *transaxes; /* Shortcut for Correction structure */
|
||||
Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */
|
||||
ULONG ulDataLen; /* Size of data */
|
||||
GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */
|
||||
|
||||
ulDataLen = sizeof(stGameStatus);
|
||||
rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS,
|
||||
NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen);
|
||||
if (rc != 0)
|
||||
{
|
||||
SDL_SetError("Could not read joystick status.");
|
||||
return; /* Could not read data */
|
||||
}
|
||||
|
||||
/* Shortcut pointer */
|
||||
index = joystick->instance_id;
|
||||
|
||||
/* joystick motion events */
|
||||
|
||||
if (SYS_JoyData[index].id == 0)
|
||||
{
|
||||
pos[0] = stGameStatus.curdata.A.x;
|
||||
pos[1] = stGameStatus.curdata.A.y;
|
||||
if (SYS_JoyData[index].axes >= 3) pos[2] = stGameStatus.curdata.B.x;
|
||||
else pos[2] = 0;
|
||||
if (SYS_JoyData[index].axes >= 4) pos[3] = stGameStatus.curdata.B.y;
|
||||
else pos[3] = 0;
|
||||
/* OS/2 basic drivers do not support more than 4 axes joysticks */
|
||||
}
|
||||
else if (SYS_JoyData[index].id == 1)
|
||||
{
|
||||
pos[0] = stGameStatus.curdata.B.x;
|
||||
pos[1] = stGameStatus.curdata.B.y;
|
||||
pos[2] = 0;
|
||||
pos[3] = 0;
|
||||
}
|
||||
|
||||
/* Corrects the movements using the callibration */
|
||||
transaxes = joystick->hwdata->transaxes;
|
||||
for (i = 0; i < joystick->naxes; i++)
|
||||
{
|
||||
value = pos[i] + transaxes[i].offset;
|
||||
if (value < 0)
|
||||
{
|
||||
value *= transaxes[i].scale1;
|
||||
if (value > 0) value = SDL_JOYSTICK_AXIS_MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
value *= transaxes[i].scale2;
|
||||
if (value < 0) value = SDL_JOYSTICK_AXIS_MAX;
|
||||
}
|
||||
SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value);
|
||||
}
|
||||
|
||||
/* joystick button A to D events */
|
||||
if (SYS_JoyData[index].id == 1) corr = 2;
|
||||
else corr = 0;
|
||||
normbut = 4; /* Number of normal buttons */
|
||||
if (joystick->nbuttons<normbut) normbut = joystick->nbuttons;
|
||||
for (i = corr; (i-corr) < normbut; ++i)
|
||||
{
|
||||
/*
|
||||
Button A: 1110 0000
|
||||
Button B: 1101 0000
|
||||
Button C: 1011 0000
|
||||
Button D: 0111 0000
|
||||
*/
|
||||
if ((~stGameStatus.curdata.butMask)>>4 & JOY_BUTTON_FLAG(i))
|
||||
{
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_PRESSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_RELEASED);
|
||||
}
|
||||
}
|
||||
|
||||
/* Joystick button E to H buttons */
|
||||
/*
|
||||
Button E: Axis 2 X Left
|
||||
Button F: Axis 2 Y Up
|
||||
Button G: Axis 2 X Right
|
||||
Button H: Axis 2 Y Down
|
||||
*/
|
||||
if (joystick->nbuttons >= 5)
|
||||
{
|
||||
if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_PRESSED);
|
||||
else SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_RELEASED);
|
||||
}
|
||||
if (joystick->nbuttons >= 6)
|
||||
{
|
||||
if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_PRESSED);
|
||||
else SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_RELEASED);
|
||||
}
|
||||
if (joystick->nbuttons >= 7)
|
||||
{
|
||||
if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_PRESSED);
|
||||
else SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_RELEASED);
|
||||
}
|
||||
if (joystick->nbuttons >= 8)
|
||||
{
|
||||
if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_PRESSED);
|
||||
else SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_RELEASED);
|
||||
}
|
||||
|
||||
/* joystick hat events */
|
||||
/* Not Supported under OS/2 */
|
||||
/* joystick ball events */
|
||||
/* Not Supported under OS/2 */
|
||||
}
|
||||
|
||||
/******************************************/
|
||||
/* Function to close a joystick after use */
|
||||
/******************************************/
|
||||
static void OS2_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
/* free system specific hardware data */
|
||||
SDL_free(joystick->hwdata);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
/********************************************************************/
|
||||
static void OS2_JoystickQuit(void)
|
||||
{
|
||||
joyPortClose(&hJoyPort);
|
||||
}
|
||||
|
||||
static SDL_bool OS2_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/************************/
|
||||
/* OS/2 Implementations */
|
||||
/************************/
|
||||
|
||||
/*****************************************/
|
||||
/* Open Joystick Port, if not opened yet */
|
||||
/*****************************************/
|
||||
static int joyPortOpen(HFILE * hGame)
|
||||
{
|
||||
APIRET rc; /* Generic Return Code */
|
||||
ULONG ulAction; /* ? */
|
||||
ULONG ulVersion; /* Version of joystick driver */
|
||||
ULONG ulDataLen; /* Size of version data */
|
||||
|
||||
/* Verifies if joyport is not already open... */
|
||||
if (*hGame != NULLHANDLE) return 0;
|
||||
|
||||
/* Open GAME$ for read */
|
||||
rc = DosOpen("GAME$ ", hGame, &ulAction, 0, FILE_READONLY,
|
||||
FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);
|
||||
if (rc != 0)
|
||||
{
|
||||
return SDL_SetError("Could not open Joystick Port.");
|
||||
}
|
||||
|
||||
/* Get Joystick Driver Version... must be 2.0 or higher */
|
||||
ulVersion = 0;
|
||||
ulDataLen = sizeof(ulVersion);
|
||||
rc = DosDevIOCtl(*hGame, IOCTL_CAT_USER, GAME_GET_VERSION,
|
||||
NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen);
|
||||
if (rc != 0)
|
||||
{
|
||||
joyPortClose(hGame);
|
||||
return SDL_SetError("Could not get Joystick Driver version.");
|
||||
}
|
||||
if (ulVersion < 0x20)
|
||||
{
|
||||
joyPortClose(hGame);
|
||||
return SDL_SetError("Driver too old. At least IBM driver version 2.0 required.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************/
|
||||
/* Close JoyPort, if opened */
|
||||
/****************************/
|
||||
static void joyPortClose(HFILE * hGame)
|
||||
{
|
||||
if (*hGame != NULLHANDLE) DosClose(*hGame);
|
||||
*hGame = NULLHANDLE;
|
||||
}
|
||||
|
||||
/***************************/
|
||||
/* Get SDL Joystick EnvVar */
|
||||
/***************************/
|
||||
static int joyGetEnv(struct _joycfg * joydata)
|
||||
{
|
||||
char *joyenv; /* Pointer to tested character */
|
||||
char tempnumber[5]; /* Temporary place to put numeric texts */
|
||||
|
||||
joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
|
||||
if (joyenv == NULL) return 0;
|
||||
|
||||
/* Joystick Environment is defined! */
|
||||
while (*joyenv == ' ' && *joyenv != 0) joyenv++; /* jump spaces... */
|
||||
|
||||
/* If the string name starts with '... get if fully */
|
||||
if (*joyenv == '\'') joyenv += joyGetData(++joyenv,joydata->name,'\'',sizeof(joydata->name));
|
||||
|
||||
/* If not, get it until the next space */
|
||||
else if (*joyenv == '\"') joyenv+=joyGetData(++joyenv,joydata->name,'\"',sizeof(joydata->name));
|
||||
else joyenv += joyGetData(joyenv,joydata->name,' ',sizeof(joydata->name));
|
||||
|
||||
/* Now get the number of axes */
|
||||
while (*joyenv == ' ' && *joyenv != 0) joyenv++; /* jump spaces... */
|
||||
joyenv += joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
|
||||
joydata->axes = atoi(tempnumber);
|
||||
|
||||
/* Now get the number of buttons */
|
||||
while (*joyenv == ' ' && *joyenv != 0) joyenv++; /* jump spaces... */
|
||||
joyenv += joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
|
||||
joydata->buttons = atoi(tempnumber);
|
||||
|
||||
/* Now get the number of hats */
|
||||
while (*joyenv == ' ' && *joyenv != 0) joyenv++; /* jump spaces... */
|
||||
joyenv += joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
|
||||
joydata->hats = atoi(tempnumber);
|
||||
|
||||
/* Now get the number of balls */
|
||||
while (*joyenv==' ' && *joyenv != 0) joyenv++; /* jump spaces... */
|
||||
joyenv += joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
|
||||
joydata->balls = atoi(tempnumber);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* Get a text from in the string starting in joyenv until it finds */
|
||||
/* the stopchar or maxchars is reached. The result is placed in name. */
|
||||
/************************************************************************/
|
||||
static int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars)
|
||||
{
|
||||
char *nameptr; /* Pointer to the selected character */
|
||||
int chcnt = 0; /* Count how many characters where copied */
|
||||
|
||||
nameptr = name;
|
||||
while (*joyenv!=stopchar && *joyenv!=0)
|
||||
{
|
||||
if (nameptr < (name + (maxchars-1)))
|
||||
{
|
||||
*nameptr = *joyenv; /* Only copy if smaller than maximum */
|
||||
nameptr++;
|
||||
}
|
||||
chcnt++;
|
||||
joyenv++;
|
||||
}
|
||||
if (*joyenv == stopchar)
|
||||
{
|
||||
joyenv++; /* Jump stopchar */
|
||||
chcnt++;
|
||||
}
|
||||
*nameptr = 0; /* Mark last byte */
|
||||
return chcnt;
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_OS2_JoystickDriver =
|
||||
{
|
||||
OS2_JoystickInit,
|
||||
OS2_NumJoysticks,
|
||||
OS2_JoystickDetect,
|
||||
OS2_JoystickGetDeviceName,
|
||||
OS2_JoystickGetDevicePlayerIndex,
|
||||
OS2_JoystickSetDevicePlayerIndex,
|
||||
OS2_JoystickGetDeviceGUID,
|
||||
OS2_JoystickGetDeviceInstanceID,
|
||||
OS2_JoystickOpen,
|
||||
OS2_JoystickRumble,
|
||||
OS2_JoystickRumbleTriggers,
|
||||
OS2_JoystickHasLED,
|
||||
OS2_JoystickSetLED,
|
||||
OS2_JoystickSetSensorsEnabled,
|
||||
OS2_JoystickUpdate,
|
||||
OS2_JoystickClose,
|
||||
OS2_JoystickQuit,
|
||||
OS2_JoystickGetGamepadMapping
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_OS2 */
|
122
externals/SDL/src/joystick/psp/SDL_sysjoystick.c
vendored
122
externals/SDL/src/joystick/psp/SDL_sysjoystick.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -103,7 +103,7 @@ int JoystickUpdate(void *data)
|
||||
* Joystick 0 should be the system default joystick.
|
||||
* It should return number of joysticks, or -1 on an unrecoverable fatal error.
|
||||
*/
|
||||
int SDL_SYS_JoystickInit(void)
|
||||
static int PSP_JoystickInit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -132,35 +132,55 @@ int SDL_SYS_JoystickInit(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SDL_SYS_NumJoysticks(void)
|
||||
static int PSP_NumJoysticks(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SDL_SYS_JoystickDetect(void)
|
||||
static void PSP_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
||||
static const char *PSP_JoystickName(int idx)
|
||||
{
|
||||
if (idx == 0) return "PSP controller";
|
||||
SDL_SetError("No joystick available with that index");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
static const char *PSP_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
return "PSP builtin joypad";
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
static int PSP_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char *SDL_SYS_JoystickName(int index)
|
||||
static void
|
||||
PSP_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
if (index == 0)
|
||||
return "PSP controller";
|
||||
}
|
||||
|
||||
SDL_SetError("No joystick available with that index");
|
||||
return(NULL);
|
||||
static SDL_JoystickGUID PSP_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = PSP_JoystickGetDeviceName(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
static SDL_JoystickID PSP_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
}
|
||||
|
||||
/* Function to open a joystick for use.
|
||||
@@ -168,7 +188,7 @@ const char *SDL_SYS_JoystickName(int index)
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
static int PSP_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
joystick->nbuttons = 14;
|
||||
joystick->naxes = 2;
|
||||
@@ -177,12 +197,40 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool PSP_JoystickHasLED(SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int PSP_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
/* Function to update the state of a joystick - called as a device poll.
|
||||
* This function shouldn't update the joystick structure directly,
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
static void PSP_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
int i;
|
||||
enum PspCtrlButtons buttons;
|
||||
@@ -225,12 +273,12 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
|
||||
static void PSP_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void SDL_SYS_JoystickQuit(void)
|
||||
static void PSP_JoystickQuit(void)
|
||||
{
|
||||
/* Cleanup Threads and Semaphore. */
|
||||
running = 0;
|
||||
@@ -238,25 +286,33 @@ void SDL_SYS_JoystickQuit(void)
|
||||
SDL_DestroySemaphore(pad_sem);
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
|
||||
static SDL_bool
|
||||
PSP_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
return guid;
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
|
||||
SDL_JoystickDriver SDL_PSP_JoystickDriver =
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = joystick->name;
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
return guid;
|
||||
}
|
||||
PSP_JoystickInit,
|
||||
PSP_NumJoysticks,
|
||||
PSP_JoystickDetect,
|
||||
PSP_JoystickGetDeviceName,
|
||||
PSP_JoystickGetDevicePlayerIndex,
|
||||
PSP_JoystickSetDevicePlayerIndex,
|
||||
PSP_JoystickGetDeviceGUID,
|
||||
PSP_JoystickGetDeviceInstanceID,
|
||||
PSP_JoystickOpen,
|
||||
PSP_JoystickRumble,
|
||||
PSP_JoystickRumbleTriggers,
|
||||
PSP_JoystickHasLED,
|
||||
PSP_JoystickSetLED,
|
||||
PSP_JoystickSetSensorsEnabled,
|
||||
PSP_JoystickUpdate,
|
||||
PSP_JoystickClose,
|
||||
PSP_JoystickQuit,
|
||||
PSP_JoystickGetGamepadMapping
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_PSP */
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
12
externals/SDL/src/joystick/usb_ids.h
vendored
12
externals/SDL/src/joystick/usb_ids.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -25,18 +25,25 @@
|
||||
/* Definitions of useful USB VID/PID values */
|
||||
|
||||
#define USB_VENDOR_APPLE 0x05ac
|
||||
#define USB_VENDOR_GOOGLE 0x18d1
|
||||
#define USB_VENDOR_HYPERKIN 0x2e24
|
||||
#define USB_VENDOR_MICROSOFT 0x045e
|
||||
#define USB_VENDOR_NINTENDO 0x057e
|
||||
#define USB_VENDOR_NVIDIA 0x0955
|
||||
#define USB_VENDOR_PDP 0x0e6f
|
||||
#define USB_VENDOR_POWERA_ALT 0x20d6
|
||||
#define USB_VENDOR_POWERA 0x24c6
|
||||
#define USB_VENDOR_SONY 0x054c
|
||||
#define USB_VENDOR_RAZER 0x1532
|
||||
#define USB_VENDOR_SHENZHEN 0x0079
|
||||
#define USB_VENDOR_SONY 0x054c
|
||||
#define USB_VENDOR_VALVE 0x28de
|
||||
|
||||
#define USB_PRODUCT_GOOGLE_STADIA_CONTROLLER 0x9400
|
||||
#define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER 0x1846
|
||||
#define USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER 0x0337
|
||||
#define USB_PRODUCT_NINTENDO_SWITCH_PRO 0x2009
|
||||
#define USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_LEFT 0x2006
|
||||
#define USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_RIGHT 0x2007
|
||||
#define USB_PRODUCT_RAZER_PANTHERA 0x0401
|
||||
#define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008
|
||||
#define USB_PRODUCT_RAZER_ATROX 0x0a00
|
||||
@@ -52,6 +59,7 @@
|
||||
#define USB_PRODUCT_XBOX_ONE_S_REV2_BLUETOOTH 0x02fd
|
||||
#define USB_PRODUCT_XBOX_ONE_SERIES_X 0x0b12
|
||||
#define USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH 0x0b13
|
||||
#define USB_PRODUCT_XBOX_ONE_SERIES_X_POWERA 0x2001
|
||||
#define USB_PRODUCT_XBOX_ONE_RAW_INPUT_CONTROLLER 0x02ff
|
||||
#define USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER 0x02fe /* Made up product ID for XInput */
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -445,6 +445,6 @@ SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver =
|
||||
VIRTUAL_JoystickGetGamepadMapping
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_VIRTUAL || SDL_JOYSTICK_DISABLED */
|
||||
#endif /* SDL_JOYSTICK_VIRTUAL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
417
externals/SDL/src/joystick/vita/SDL_sysjoystick.c
vendored
Executable file
417
externals/SDL/src/joystick/vita/SDL_sysjoystick.c
vendored
Executable file
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_JOYSTICK_VITA
|
||||
|
||||
/* This is the PSVita implementation of the SDL joystick API */
|
||||
#include <psp2/types.h>
|
||||
#include <psp2/ctrl.h>
|
||||
#include <psp2/kernel/threadmgr.h>
|
||||
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_timer.h"
|
||||
|
||||
/* Current pad state */
|
||||
static SceCtrlData pad0 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .lt = 0, .rt = 0, .buttons = 0 };
|
||||
static SceCtrlData pad1 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .lt = 0, .rt = 0, .buttons = 0 };
|
||||
static SceCtrlData pad2 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .lt = 0, .rt = 0, .buttons = 0 };
|
||||
static SceCtrlData pad3 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .lt = 0, .rt = 0, .buttons = 0 };
|
||||
|
||||
static int port_map[4]= { 0, 2, 3, 4 }; //index: SDL joy number, entry: Vita port number
|
||||
static int ext_port_map[4]= { 1, 2, 3, 4 }; //index: SDL joy number, entry: Vita port number. For external controllers
|
||||
|
||||
static int SDL_numjoysticks = 1;
|
||||
|
||||
static const unsigned int button_map[] = {
|
||||
SCE_CTRL_TRIANGLE,
|
||||
SCE_CTRL_CIRCLE,
|
||||
SCE_CTRL_CROSS,
|
||||
SCE_CTRL_SQUARE,
|
||||
SCE_CTRL_LTRIGGER,
|
||||
SCE_CTRL_RTRIGGER,
|
||||
SCE_CTRL_DOWN,
|
||||
SCE_CTRL_LEFT,
|
||||
SCE_CTRL_UP,
|
||||
SCE_CTRL_RIGHT,
|
||||
SCE_CTRL_SELECT,
|
||||
SCE_CTRL_START
|
||||
};
|
||||
|
||||
static const unsigned int ext_button_map[] = {
|
||||
SCE_CTRL_TRIANGLE,
|
||||
SCE_CTRL_CIRCLE,
|
||||
SCE_CTRL_CROSS,
|
||||
SCE_CTRL_SQUARE,
|
||||
SCE_CTRL_L1,
|
||||
SCE_CTRL_R1,
|
||||
SCE_CTRL_DOWN,
|
||||
SCE_CTRL_LEFT,
|
||||
SCE_CTRL_UP,
|
||||
SCE_CTRL_RIGHT,
|
||||
SCE_CTRL_SELECT,
|
||||
SCE_CTRL_START,
|
||||
SCE_CTRL_L2,
|
||||
SCE_CTRL_R2,
|
||||
SCE_CTRL_L3,
|
||||
SCE_CTRL_R3
|
||||
};
|
||||
|
||||
static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} point;
|
||||
|
||||
/* 4 points define the bezier-curve. */
|
||||
/* The Vita has a good amount of analog travel, so use a linear curve */
|
||||
static point a = { 0, 0 };
|
||||
static point b = { 0, 0 };
|
||||
static point c = { 128, 32767 };
|
||||
static point d = { 128, 32767 };
|
||||
|
||||
/* simple linear interpolation between two points */
|
||||
static SDL_INLINE void lerp (point *dest, point *first, point *second, float t)
|
||||
{
|
||||
dest->x = first->x + (second->x - first->x) * t;
|
||||
dest->y = first->y + (second->y - first->y) * t;
|
||||
}
|
||||
|
||||
/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
|
||||
static int calc_bezier_y(float t)
|
||||
{
|
||||
point ab, bc, cd, abbc, bccd, dest;
|
||||
lerp (&ab, &a, &b, t); /* point between a and b */
|
||||
lerp (&bc, &b, &c, t); /* point between b and c */
|
||||
lerp (&cd, &c, &d, t); /* point between c and d */
|
||||
lerp (&abbc, &ab, &bc, t); /* point between ab and bc */
|
||||
lerp (&bccd, &bc, &cd, t); /* point between bc and cd */
|
||||
lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */
|
||||
return dest.y;
|
||||
}
|
||||
|
||||
/* Function to scan the system for joysticks.
|
||||
* Joystick 0 should be the system default joystick.
|
||||
* It should return number of joysticks, or -1 on an unrecoverable fatal error.
|
||||
*/
|
||||
int VITA_JoystickInit(void)
|
||||
{
|
||||
int i;
|
||||
SceCtrlPortInfo myPortInfo;
|
||||
|
||||
/* Setup input */
|
||||
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
|
||||
sceCtrlSetSamplingModeExt(SCE_CTRL_MODE_ANALOG_WIDE);
|
||||
|
||||
/* Create an accurate map from analog inputs (0 to 255)
|
||||
to SDL joystick positions (-32768 to 32767) */
|
||||
for (i = 0; i < 128; i++)
|
||||
{
|
||||
float t = (float)i/127.0f;
|
||||
analog_map[i+128] = calc_bezier_y(t);
|
||||
analog_map[127-i] = -1 * analog_map[i+128];
|
||||
}
|
||||
|
||||
// Assume we have at least one controller, even when nothing is paired
|
||||
// This way the user can jump in, pair a controller
|
||||
// and control things immediately even if it is paired
|
||||
// after the app has already started.
|
||||
|
||||
SDL_numjoysticks = 1;
|
||||
|
||||
// How many additional paired controllers are there?
|
||||
sceCtrlGetControllerPortInfo(&myPortInfo);
|
||||
|
||||
// On Vita TV, port 0 and 1 are the same controller
|
||||
// and that is the first one, so start at port 2
|
||||
for (i=2; i<=4; i++)
|
||||
{
|
||||
if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED)
|
||||
{
|
||||
SDL_numjoysticks++;
|
||||
}
|
||||
}
|
||||
return SDL_numjoysticks;
|
||||
}
|
||||
|
||||
int VITA_JoystickGetCount()
|
||||
{
|
||||
return SDL_numjoysticks;
|
||||
}
|
||||
|
||||
void VITA_JoystickDetect()
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
SDL_JoystickID VITA_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
}
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char *VITA_JoystickGetDeviceName(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
return "PSVita Controller";
|
||||
|
||||
if (index == 1)
|
||||
return "PSVita Controller";
|
||||
|
||||
if (index == 2)
|
||||
return "PSVita Controller";
|
||||
|
||||
if (index == 3)
|
||||
return "PSVita Controller";
|
||||
|
||||
SDL_SetError("No joystick available with that index");
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
VITA_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
VITA_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to open a joystick for use.
|
||||
The joystick to open is specified by the device index.
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
joystick->nbuttons = SDL_arraysize(ext_button_map);
|
||||
joystick->naxes = 6;
|
||||
joystick->nhats = 0;
|
||||
joystick->instance_id = device_index;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function to update the state of a joystick - called as a device poll.
|
||||
* This function shouldn't update the joystick structure directly,
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
static void VITA_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
int i;
|
||||
unsigned int buttons;
|
||||
unsigned int changed;
|
||||
unsigned char lx, ly, rx, ry, lt, rt;
|
||||
static unsigned int old_buttons[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_lx[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_ly[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_rx[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_ry[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_lt[] = { 0, 0, 0, 0 };
|
||||
static unsigned char old_rt[] = { 0, 0, 0, 0 };
|
||||
SceCtrlData *pad = NULL;
|
||||
SDL_bool fallback = SDL_FALSE;
|
||||
|
||||
int index = (int) SDL_JoystickInstanceID(joystick);
|
||||
|
||||
if (index == 0) pad = &pad0;
|
||||
else if (index == 1) pad = &pad1;
|
||||
else if (index == 2) pad = &pad2;
|
||||
else if (index == 3) pad = &pad3;
|
||||
else return;
|
||||
|
||||
if (index == 0) {
|
||||
if (sceCtrlPeekBufferPositiveExt2(ext_port_map[index], pad, 1) < 0) {
|
||||
// on vita fallback to port 0
|
||||
sceCtrlPeekBufferPositive(port_map[index], pad, 1);
|
||||
fallback = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
sceCtrlPeekBufferPositiveExt2(ext_port_map[index], pad, 1);
|
||||
}
|
||||
|
||||
buttons = pad->buttons;
|
||||
|
||||
lx = pad->lx;
|
||||
ly = pad->ly;
|
||||
rx = pad->rx;
|
||||
ry = pad->ry;
|
||||
lt = pad->lt;
|
||||
rt = pad->rt;
|
||||
|
||||
// Axes
|
||||
|
||||
if (old_lx[index] != lx) {
|
||||
SDL_PrivateJoystickAxis(joystick, 0, analog_map[lx]);
|
||||
old_lx[index] = lx;
|
||||
}
|
||||
if (old_ly[index] != ly) {
|
||||
SDL_PrivateJoystickAxis(joystick, 1, analog_map[ly]);
|
||||
old_ly[index] = ly;
|
||||
}
|
||||
if (old_rx[index] != rx) {
|
||||
SDL_PrivateJoystickAxis(joystick, 2, analog_map[rx]);
|
||||
old_rx[index] = rx;
|
||||
}
|
||||
if (old_ry[index] != ry) {
|
||||
SDL_PrivateJoystickAxis(joystick, 3, analog_map[ry]);
|
||||
old_ry[index] = ry;
|
||||
}
|
||||
|
||||
if (old_lt[index] != lt) {
|
||||
SDL_PrivateJoystickAxis(joystick, 4, analog_map[lt]);
|
||||
old_lt[index] = lt;
|
||||
}
|
||||
if (old_rt[index] != rt) {
|
||||
SDL_PrivateJoystickAxis(joystick, 5, analog_map[rt]);
|
||||
old_rt[index] = rt;
|
||||
}
|
||||
|
||||
// Buttons
|
||||
changed = old_buttons[index] ^ buttons;
|
||||
old_buttons[index] = buttons;
|
||||
|
||||
if (changed) {
|
||||
if (fallback) {
|
||||
for (i = 0; i < SDL_arraysize(button_map); i++) {
|
||||
if (changed & button_map[i]) {
|
||||
SDL_PrivateJoystickButton(
|
||||
joystick, i,
|
||||
(buttons & button_map[i]) ?
|
||||
SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < SDL_arraysize(ext_button_map); i++) {
|
||||
if (changed & ext_button_map[i]) {
|
||||
SDL_PrivateJoystickButton(
|
||||
joystick, i,
|
||||
(buttons & ext_button_map[i]) ?
|
||||
SDL_PRESSED : SDL_RELEASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
void VITA_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void VITA_JoystickQuit(void)
|
||||
{
|
||||
}
|
||||
|
||||
SDL_JoystickGUID VITA_JoystickGetDeviceGUID( int device_index )
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = VITA_JoystickGetDeviceName( device_index );
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
return guid;
|
||||
}
|
||||
|
||||
static int
|
||||
VITA_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
int index = (int) SDL_JoystickInstanceID(joystick);
|
||||
SceCtrlActuator act;
|
||||
SDL_zero(act);
|
||||
|
||||
act.small = high_frequency_rumble / 256;
|
||||
act.large = low_frequency_rumble / 256;
|
||||
sceCtrlSetActuator(ext_port_map[index], &act);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
VITA_JoystickRumbleTriggers(SDL_Joystick * joystick, Uint16 left, Uint16 right)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
VITA_JoystickHasLED(SDL_Joystick * joystick)
|
||||
{
|
||||
// always return true for now
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
VITA_JoystickSetLED(SDL_Joystick * joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
int index = (int) SDL_JoystickInstanceID(joystick);
|
||||
sceCtrlSetLightBar(ext_port_map[index], red, green, blue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
VITA_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_VITA_JoystickDriver =
|
||||
{
|
||||
VITA_JoystickInit,
|
||||
VITA_JoystickGetCount,
|
||||
VITA_JoystickDetect,
|
||||
VITA_JoystickGetDeviceName,
|
||||
VITA_JoystickGetDevicePlayerIndex,
|
||||
VITA_JoystickSetDevicePlayerIndex,
|
||||
VITA_JoystickGetDeviceGUID,
|
||||
VITA_JoystickGetDeviceInstanceID,
|
||||
|
||||
VITA_JoystickOpen,
|
||||
|
||||
VITA_JoystickRumble,
|
||||
VITA_JoystickRumbleTriggers,
|
||||
|
||||
VITA_JoystickHasLED,
|
||||
VITA_JoystickSetLED,
|
||||
VITA_JoystickSetSensorsEnabled,
|
||||
|
||||
VITA_JoystickUpdate,
|
||||
VITA_JoystickClose,
|
||||
VITA_JoystickQuit,
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_VITA */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -50,14 +50,14 @@ static UINT SDL_RawDevListCount = 0;
|
||||
|
||||
/* Taken from Wine - Thanks! */
|
||||
static DIOBJECTDATAFORMAT dfDIJoystick2[] = {
|
||||
{ &GUID_XAxis, DIJOFS_X, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_YAxis, DIJOFS_Y, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_ZAxis, DIJOFS_Z, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RxAxis, DIJOFS_RX, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RyAxis, DIJOFS_RY, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RzAxis, DIJOFS_RZ, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_XAxis, DIJOFS_X, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_YAxis, DIJOFS_Y, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_ZAxis, DIJOFS_Z, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_RxAxis, DIJOFS_RX, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_RyAxis, DIJOFS_RY, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_RzAxis, DIJOFS_RZ, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION },
|
||||
{ &GUID_POV, DIJOFS_POV(0), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_POV, DIJOFS_POV(1), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_POV, DIJOFS_POV(2), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
|
||||
@@ -190,30 +190,33 @@ static DIOBJECTDATAFORMAT dfDIJoystick2[] = {
|
||||
{ NULL, DIJOFS_BUTTON(125), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
|
||||
{ NULL, DIJOFS_BUTTON(126), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
|
||||
{ NULL, DIJOFS_BUTTON(127), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lVX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lVY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lVZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lVRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lVRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lVRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lAX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lAY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lAZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lARx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lARy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lARz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lFX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lFY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lFZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lFRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lFRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lFRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lVX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lVY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lVZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lVRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lVRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lVRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
/* note: dwOfs value matches Windows */
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTVELOCITY },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lAX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lAY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lAZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lARx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lARy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lARz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
/* note: dwOfs value matches Windows */
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTACCEL },
|
||||
{ &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lFX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lFY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lFZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lFRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lFRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lFRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
/* note: dwOfs value matches Windows */
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
{ &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTFORCE },
|
||||
};
|
||||
|
||||
const DIDATAFORMAT SDL_c_dfDIJoystick2 = {
|
||||
@@ -241,7 +244,7 @@ static const IID CLSID_WbemLocator = { 0x4590f811, 0x1d3a, 0x11d0,{ 0x89, 0x1f,
|
||||
static const IID IID_IWbemLocator = { 0xdc12a687, 0x737f, 0x11cf,{ 0x88, 0x4d, 0x00, 0xaa, 0x00, 0x4b, 0x2e, 0x24 } };
|
||||
|
||||
static SDL_bool
|
||||
WIN_IsXInputDevice(const WCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
WIN_IsXInputDevice(const TCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
{
|
||||
IWbemLocator* pIWbemLocator = NULL;
|
||||
IEnumWbemClassObject* pEnumDevices = NULL;
|
||||
@@ -260,7 +263,7 @@ WIN_IsXInputDevice(const WCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (SDL_wcsstr(name, L" XINPUT ") != NULL) {
|
||||
if (SDL_tcsstr(name, TEXT(" XINPUT ")) != NULL) {
|
||||
/* This is a duplicate interface for a controller that will show up with XInput,
|
||||
e.g. Xbox One Elite Series 2 in Bluetooth mode.
|
||||
*/
|
||||
@@ -315,7 +318,7 @@ WIN_IsXInputDevice(const WCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
// Check if the device ID contains "IG_". If it does, then it's an XInput device
|
||||
// This information can not be found from DirectInput
|
||||
if (SDL_wcsstr(var.bstrVal, L"IG_")) {
|
||||
char *bstrVal = WIN_StringToUTF8(var.bstrVal);
|
||||
char *bstrVal = WIN_StringToUTF8W(var.bstrVal);
|
||||
|
||||
// If it does, then get the VID/PID from var.bstrVal
|
||||
DWORD dwPid = 0, dwVid = 0, dwVidPid;
|
||||
@@ -371,7 +374,7 @@ LCleanup:
|
||||
#endif /* 0 */
|
||||
|
||||
static SDL_bool
|
||||
SDL_IsXInputDevice(const WCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
SDL_IsXInputDevice(const TCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
{
|
||||
UINT i;
|
||||
|
||||
@@ -379,7 +382,7 @@ SDL_IsXInputDevice(const WCHAR *name, const GUID* pGuidProductFromDirectInput)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (SDL_wcsstr(name, L" XINPUT ") != NULL) {
|
||||
if (SDL_tcsstr(name, TEXT(" XINPUT ")) != NULL) {
|
||||
/* This is a duplicate interface for a controller that will show up with XInput,
|
||||
e.g. Xbox One Elite Series 2 in Bluetooth mode.
|
||||
*/
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
148
externals/SDL/src/joystick/windows/SDL_mmjoystick.c
vendored
148
externals/SDL/src/joystick/windows/SDL_mmjoystick.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -146,14 +146,14 @@ GetJoystickName(int index, const char *szRegKey)
|
||||
return (name);
|
||||
}
|
||||
|
||||
static int SDL_SYS_numjoysticks = 0;
|
||||
static int numjoysticks = 0;
|
||||
|
||||
/* Function to scan the system for joysticks.
|
||||
* Joystick 0 should be the system default joystick.
|
||||
* It should return 0, or -1 on an unrecoverable fatal error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickInit(void)
|
||||
static int
|
||||
WINMM_JoystickInit(void)
|
||||
{
|
||||
int i;
|
||||
int maxdevs;
|
||||
@@ -168,9 +168,9 @@ SDL_SYS_JoystickInit(void)
|
||||
}
|
||||
|
||||
/* Loop over all potential joystick devices */
|
||||
SDL_SYS_numjoysticks = 0;
|
||||
numjoysticks = 0;
|
||||
maxdevs = joyGetNumDevs();
|
||||
for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
|
||||
for (i = JOYSTICKID1; i < maxdevs && numjoysticks < MAX_JOYSTICKS; ++i) {
|
||||
|
||||
joyinfo.dwSize = sizeof(joyinfo);
|
||||
joyinfo.dwFlags = JOY_RETURNALL;
|
||||
@@ -178,31 +178,31 @@ SDL_SYS_JoystickInit(void)
|
||||
if (result == JOYERR_NOERROR) {
|
||||
result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
|
||||
if (result == JOYERR_NOERROR) {
|
||||
SYS_JoystickID[SDL_SYS_numjoysticks] = i;
|
||||
SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
|
||||
SYS_JoystickName[SDL_SYS_numjoysticks] =
|
||||
SYS_JoystickID[numjoysticks] = i;
|
||||
SYS_Joystick[numjoysticks] = joycaps;
|
||||
SYS_JoystickName[numjoysticks] =
|
||||
GetJoystickName(i, joycaps.szRegKey);
|
||||
SDL_SYS_numjoysticks++;
|
||||
numjoysticks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (SDL_SYS_numjoysticks);
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumJoysticks(void)
|
||||
static int
|
||||
WINMM_NumJoysticks(void)
|
||||
{
|
||||
return SDL_SYS_numjoysticks;
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_JoystickDetect(void)
|
||||
static void
|
||||
WINMM_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char *
|
||||
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
||||
static const char *
|
||||
WINMM_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
if (SYS_JoystickName[device_index] != NULL) {
|
||||
return (SYS_JoystickName[device_index]);
|
||||
@@ -211,8 +211,29 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
WINMM_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
WINMM_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_JoystickGUID WINMM_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = WINMM_JoystickGetDeviceName(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
static SDL_JoystickID WINMM_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
}
|
||||
@@ -222,15 +243,14 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
||||
static int
|
||||
WINMM_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
||||
{
|
||||
int index, i;
|
||||
int caps_flags[MAX_AXES - 2] =
|
||||
{ JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
|
||||
int axis_min[MAX_AXES], axis_max[MAX_AXES];
|
||||
|
||||
|
||||
/* shortcut */
|
||||
index = device_index;
|
||||
axis_min[0] = SYS_Joystick[index].wXmin;
|
||||
@@ -302,18 +322,46 @@ TranslatePOV(DWORD value)
|
||||
return (pos);
|
||||
}
|
||||
|
||||
static int
|
||||
WINMM_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
WINMM_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool WINMM_JoystickHasLED(SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
WINMM_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int WINMM_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
/* Function to update the state of a joystick - called as a device poll.
|
||||
* This function shouldn't update the joystick structure directly,
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
static void
|
||||
WINMM_JoystickUpdate(SDL_Joystick * joystick)
|
||||
{
|
||||
MMRESULT result;
|
||||
int i;
|
||||
DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
|
||||
JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
|
||||
JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
|
||||
};
|
||||
DWORD pos[MAX_AXES];
|
||||
struct _transaxis *transaxis;
|
||||
@@ -365,15 +413,15 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
void
|
||||
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
||||
static void
|
||||
WINMM_JoystickClose(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_free(joystick->hwdata);
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void
|
||||
SDL_SYS_JoystickQuit(void)
|
||||
static void
|
||||
WINMM_JoystickQuit(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_JOYSTICKS; i++) {
|
||||
@@ -382,24 +430,10 @@ SDL_SYS_JoystickQuit(void)
|
||||
}
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
|
||||
static SDL_bool
|
||||
WINMM_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
return guid;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = joystick->name;
|
||||
SDL_zero( guid );
|
||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||
return guid;
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -447,6 +481,28 @@ SetMMerror(char *function, int code)
|
||||
SDL_SetError("%s", errbuf);
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_WINMM_JoystickDriver =
|
||||
{
|
||||
WINMM_JoystickInit,
|
||||
WINMM_NumJoysticks,
|
||||
WINMM_JoystickDetect,
|
||||
WINMM_JoystickGetDeviceName,
|
||||
WINMM_JoystickGetDevicePlayerIndex,
|
||||
WINMM_JoystickSetDevicePlayerIndex,
|
||||
WINMM_JoystickGetDeviceGUID,
|
||||
WINMM_JoystickGetDeviceInstanceID,
|
||||
WINMM_JoystickOpen,
|
||||
WINMM_JoystickRumble,
|
||||
WINMM_JoystickRumbleTriggers,
|
||||
WINMM_JoystickHasLED,
|
||||
WINMM_JoystickSetLED,
|
||||
WINMM_JoystickSetSensorsEnabled,
|
||||
WINMM_JoystickUpdate,
|
||||
WINMM_JoystickClose,
|
||||
WINMM_JoystickQuit,
|
||||
WINMM_JoystickGetGamepadMapping
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_WINMM */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 2021 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
|
||||
@@ -44,7 +44,9 @@
|
||||
#include "../../core/windows/SDL_hid.h"
|
||||
#include "../hidapi/SDL_hidapijoystick_c.h"
|
||||
|
||||
#ifdef HAVE_XINPUT_H
|
||||
#define SDL_JOYSTICK_RAWINPUT_XINPUT
|
||||
#endif
|
||||
#ifdef SDL_WINDOWS10_SDK
|
||||
#define SDL_JOYSTICK_RAWINPUT_WGI
|
||||
#endif
|
||||
@@ -546,7 +548,7 @@ RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx)
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)GetProcAddress(hModule, "WindowsCreateStringReference");
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory");
|
||||
if (WindowsCreateStringReferenceFunc && RoGetActivationFactoryFunc) {
|
||||
LPTSTR pNamespace = L"Windows.Gaming.Input.Gamepad";
|
||||
PCWSTR pNamespace = L"Windows.Gaming.Input.Gamepad";
|
||||
HSTRING_HEADER hNamespaceStringHeader;
|
||||
HSTRING hNamespaceString;
|
||||
|
||||
@@ -733,10 +735,10 @@ RAWINPUT_AddDevice(HANDLE hDevice)
|
||||
WCHAR string[128];
|
||||
|
||||
if (SDL_HidD_GetManufacturerString(hFile, string, sizeof(string))) {
|
||||
manufacturer_string = WIN_StringToUTF8(string);
|
||||
manufacturer_string = WIN_StringToUTF8W(string);
|
||||
}
|
||||
if (SDL_HidD_GetProductString(hFile, string, sizeof(string))) {
|
||||
product_string = WIN_StringToUTF8(string);
|
||||
product_string = WIN_StringToUTF8W(string);
|
||||
}
|
||||
|
||||
device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
|
||||
@@ -1216,9 +1218,8 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
|
||||
{
|
||||
#if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT)
|
||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||
#endif
|
||||
|
||||
SDL_bool rumbled = SDL_FALSE;
|
||||
#endif
|
||||
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
if (!rumbled && ctx->wgi_correlated) {
|
||||
@@ -1481,7 +1482,9 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||
/* Parallel logic to WINDOWS_XINPUT below */
|
||||
RAWINPUT_UpdateWindowsGamingInput();
|
||||
if (ctx->wgi_correlated) {
|
||||
if (ctx->wgi_correlated &&
|
||||
!joystick->low_frequency_rumble && !joystick->high_frequency_rumble &&
|
||||
!joystick->left_trigger_rumble && !joystick->right_trigger_rumble) {
|
||||
/* We have been previously correlated, ensure we are still matching, see comments in XINPUT section */
|
||||
if (RAWINPUT_WindowsGamingInputSlotMatches(&match_state_xinput, ctx->wgi_slot)) {
|
||||
ctx->wgi_uncorrelate_count = 0;
|
||||
@@ -1489,9 +1492,9 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
++ctx->wgi_uncorrelate_count;
|
||||
/* Only un-correlate if this is consistent over multiple Update() calls - the timing of polling/event
|
||||
pumping can easily cause this to uncorrelate for a frame. 2 seemed reliable in my testing, but
|
||||
let's set it to 3 to be safe. An incorrect un-correlation will simply result in lower precision
|
||||
let's set it to 5 to be safe. An incorrect un-correlation will simply result in lower precision
|
||||
triggers for a frame. */
|
||||
if (ctx->wgi_uncorrelate_count >= 3) {
|
||||
if (ctx->wgi_uncorrelate_count >= 5) {
|
||||
#ifdef DEBUG_RAWINPUT
|
||||
SDL_Log("UN-Correlated joystick %d to WindowsGamingInput device #%d\n", joystick->instance_id, ctx->wgi_slot);
|
||||
#endif
|
||||
@@ -1559,7 +1562,8 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
/* Parallel logic to WINDOWS_GAMING_INPUT above */
|
||||
if (ctx->xinput_enabled) {
|
||||
RAWINPUT_UpdateXInput();
|
||||
if (ctx->xinput_correlated) {
|
||||
if (ctx->xinput_correlated &&
|
||||
!joystick->low_frequency_rumble && !joystick->high_frequency_rumble) {
|
||||
/* We have been previously correlated, ensure we are still matching */
|
||||
/* This is required to deal with two (mostly) un-preventable mis-correlation situations:
|
||||
A) Since the HID data stream does not provide an initial state (but polling XInput does), if we open
|
||||
@@ -1582,9 +1586,9 @@ RAWINPUT_UpdateOtherAPIs(SDL_Joystick *joystick)
|
||||
++ctx->xinput_uncorrelate_count;
|
||||
/* Only un-correlate if this is consistent over multiple Update() calls - the timing of polling/event
|
||||
pumping can easily cause this to uncorrelate for a frame. 2 seemed reliable in my testing, but
|
||||
let's set it to 3 to be safe. An incorrect un-correlation will simply result in lower precision
|
||||
let's set it to 5 to be safe. An incorrect un-correlation will simply result in lower precision
|
||||
triggers for a frame. */
|
||||
if (ctx->xinput_uncorrelate_count >= 3) {
|
||||
if (ctx->xinput_uncorrelate_count >= 5) {
|
||||
#ifdef DEBUG_RAWINPUT
|
||||
SDL_Log("UN-Correlated joystick %d to XInput device #%d\n", joystick->instance_id, ctx->xinput_slot);
|
||||
#endif
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -197,7 +197,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
if (SUCCEEDED(hr)) {
|
||||
PCWSTR string = WindowsGetStringRawBufferFunc(hString, NULL);
|
||||
if (string) {
|
||||
name = WIN_StringToUTF8(string);
|
||||
name = WIN_StringToUTF8W(string);
|
||||
}
|
||||
WindowsDeleteStringFunc(hString);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ WGI_JoystickInit(void)
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = (WindowsCreateStringReference_t)GetProcAddress(hModule, "WindowsCreateStringReference");
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = (RoGetActivationFactory_t)GetProcAddress(hModule, "RoGetActivationFactory");
|
||||
if (WindowsCreateStringReferenceFunc && RoGetActivationFactoryFunc) {
|
||||
LPTSTR pNamespace;
|
||||
PCWSTR pNamespace;
|
||||
HSTRING_HEADER hNamespaceStringHeader;
|
||||
HSTRING hNamespaceString;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
@@ -171,7 +171,7 @@ SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
|
||||
data->coinitialized = WIN_CoInitialize();
|
||||
|
||||
data->wincl.hInstance = GetModuleHandle(NULL);
|
||||
data->wincl.lpszClassName = L"Message";
|
||||
data->wincl.lpszClassName = TEXT("Message");
|
||||
data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */
|
||||
data->wincl.cbSize = sizeof (WNDCLASSEX);
|
||||
|
||||
@@ -181,7 +181,7 @@ SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
data->messageWindow = (HWND)CreateWindowEx(0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
||||
data->messageWindow = (HWND)CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
||||
if (!data->messageWindow) {
|
||||
WIN_SetError("Failed to create message window for joystick autodetect");
|
||||
SDL_CleanupDeviceNotification(data);
|
||||
@@ -356,6 +356,15 @@ WINDOWS_JoystickInit(void)
|
||||
|
||||
WINDOWS_JoystickDetect();
|
||||
|
||||
#ifdef __WINRT__
|
||||
/* FIXME: WinRT silently does not support device notifications.
|
||||
* Revisit this if UWP ever adds support in a future release.
|
||||
*/
|
||||
s_bJoystickThread = SDL_TRUE;
|
||||
if (SDL_StartJoystickThread() < 0) {
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
s_bJoystickThread = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_THREAD, SDL_FALSE);
|
||||
if (s_bJoystickThread) {
|
||||
if (SDL_StartJoystickThread() < 0) {
|
||||
@@ -366,6 +375,7 @@ WINDOWS_JoystickInit(void)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2021 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
|
||||
|
Reference in New Issue
Block a user