Commit Graph

560 Commits

Author SHA1 Message Date
Sam Lantinga
106ffd57d8 Fixed bug 5049 - HORI Wireless Switch Pad does not connect properly via Bluetooth
bluenaxela+sdl

The HORI Wireless Switch Pad does not properly connect via bluetooth. I did some debugging and found that the code that tries to control the Home LED causes this controller to disconnect.
2020-03-20 20:45:30 -07:00
Jimb Esser
417713a75c Probable fix for compile errors on Mac OS and (non-VS) Win32 2020-03-20 19:49:19 -07:00
Sam Lantinga
dc36f133b4 Backed out changeset c29d04c3fa49 2020-03-20 19:49:15 -07:00
Sam Lantinga
2db65a7fe7 Fixed compile warnings 2020-03-20 19:47:46 -07:00
David Ludwig
7e5340c5ac Fix for Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.0.12
This is a multi-part fix, and is the 2nd attempt at a fix for Bug 5034.  Here
are the problems being addressed:

1. On macOS 10.14.x and earlier, trying to call IOHIDDeviceUnscheduleFromRunLoop
   without a prior, paired call to IOHIDDeviceScheduleWithRunLoop, appears to
   lead to a crash.  A per-device flag has been added to make sure that these
   calls are paired.
2. DARWIN_JoystickDetect was free'ing its SDL_joystick's hwdata field
   (via FreeDevice) without setting it to NULL, and DARWIN_JoystickRumble wasn't
   checking for a NULL hwdata.  FreeDevice will now set hwdata to NULL and
   DARWIN_JoystickRumble will check for a NULL hwdata.
2020-03-17 17:34:24 -04:00
David Ludwig
36d5845152 Backout prior fix for Bug 5034, which needs more research
This backs-out the change, https://hg.libsdl.org/SDL/rev/14c961903135
2020-03-17 02:31:47 -04:00
Sam Lantinga
9b879a08aa Fixed compiler warning 2020-03-16 19:15:28 -07:00
Jimb Esser
c2c5d0b392 Fix compile error 2020-03-16 16:52:49 -07:00
David Ludwig
197b14de4a Fixed Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.0.12
The Darwin/macOS joystick driver was freeing its joystick's hwdata field
without zeroing it out in any live instance of SDL_Joystick.
2020-03-16 19:24:25 -04:00
Jimb Esser
47da53b91d Fix compiler warnings 2020-03-16 14:49:20 -07:00
David Ludwig
8cd08646bb virtual joysticks: move variable decls to top of function (for C90 compat; Bug 5038) 2020-03-16 17:19:18 -04:00
Sam Lantinga
543994b193 Fixed bug 4477 - Support more than 4 XInput-capable devices on Windows
Jimb Esser

Add new RawInput controller API, and improved correlation with XInput/WGI

Reorder joystick init so drivers can ask the others if they handle a device reliably
Do not poll disconnected XInput devices (major perf issue)
Fix various cases where incorrect correlation could happen
Simple mechanism for propagating unhandled Guide button presses even before guaranteed correlation
Correlate by axis motion as well as button presses
Fix failing to zero other trigger
Fix SDL_HINT_JOYSTICK_HIDAPI not working if set before calling SDL_Init()
Add missing device to device names
Disable RawInput if we have a mismatch of XInput-capable but not RawInput-capable devices

Updated to SDL 2.0.13 code with the following notes:
New HID driver: xbox360w - no idea what that is, hopefully urelated
SDL_hidapijoystick.c had been refactored to couple data handling logic with device opening logic and device lists caused some problems, yields slightly uglier integration than previously when the 360 HID device driver was just handling the data.
SDL_hidapijoystick.c now often pulls the device off of the joystick_hwdata structure for some rumble logic, but it appears that code path is never reached, so probably not a problem.
Looks like joystick_hwdata was refactored to not include a mutex in other drivers, maintainers may want to do the same refactor here if that's useful for some reason.
Something changed in how devices get names, so getting generic names.
Had to fix a (new?) bug where removing an XInput controller caused existing controllers (that moved to a new XInput index) to get identified as 0x045e/0x02fd ("it's probably Bluetooth" in code), rendering the existing HIDAPI_IsDevicePresent and new RAWINPUT_IsDevicePresent unreliable.
2020-03-16 12:25:02 -07:00
Sam Lantinga
4dea340ca7 Fixed bug 4477 - Support more than 4 XInput-capable devices on Windows
Jimb Esser

Add new RawInput controller API, and improved correlation with XInput/WGI

Reorder joystick init so drivers can ask the others if they handle a device reliably
Do not poll disconnected XInput devices (major perf issue)
Fix various cases where incorrect correlation could happen
Simple mechanism for propagating unhandled Guide button presses even before guaranteed correlation
Correlate by axis motion as well as button presses
Fix failing to zero other trigger
Fix SDL_HINT_JOYSTICK_HIDAPI not working if set before calling SDL_Init()
Add missing device to device names
Disable RawInput if we have a mismatch of XInput-capable but not RawInput-capable devices

Updated to SDL 2.0.13 code with the following notes:
New HID driver: xbox360w - no idea what that is, hopefully urelated
SDL_hidapijoystick.c had been refactored to couple data handling logic with device opening logic and device lists caused some problems, yields slightly uglier integration than previously when the 360 HID device driver was just handling the data.
SDL_hidapijoystick.c now often pulls the device off of the joystick_hwdata structure for some rumble logic, but it appears that code path is never reached, so probably not a problem.
Looks like joystick_hwdata was refactored to not include a mutex in other drivers, maintainers may want to do the same refactor here if that's useful for some reason.
Something changed in how devices get names, so getting generic names.
Had to fix a (new?) bug where removing an XInput controller caused existing controllers (that moved to a new XInput index) to get identified as 0x045e/0x02fd ("it's probably Bluetooth" in code), rendering the existing HIDAPI_IsDevicePresent and new RAWINPUT_IsDevicePresent unreliable.
2020-03-16 12:23:38 -07:00
David Ludwig
b2296506bc virtual joysticks: MSVC support part 1/2, make driver's .c file be uniquely named 2020-03-15 15:05:36 -04:00
David Ludwig
cc90875647 virtual joysticks: removed ball support (Bug 5028) 2020-03-15 13:25:49 -04:00
Sam Lantinga
151c8fbf19 Fixed build error
Malte Kie?ling

I get a build error in SDL_sysjoystick.c:74 for the merged patch, but its nothing to sweat about, just -Werror=declaration-after-statement doing its usual stuff.
2020-03-14 17:45:00 -07:00
Sam Lantinga
2be75c6a61 Fixed bug 5028 - Virtual Joysticks (new joystick backend)
David Ludwig

I have created a new driver for SDL's Joystick and Game-Controller subsystem: a Virtual driver.  This driver allows one to create a software-based joystick, which to SDL applications will look and react like a real joystick, but whose state can be set programmatically.  A primary use case for this is to help enable developers to add touch-screen joysticks to their apps.

The driver comes with a set of new, public APIs, with functions to attach and detach joysticks, set virtual-joystick state, and to determine if a joystick is a virtual-one.

Use of virtual joysticks goes as such:

1. Attach one or more virtual joysticks by calling SDL_JoystickAttachVirtual.  If successful, this returns the virtual-device's joystick-index.
2. Open the virtual joysticks (using indicies returned by SDL_JoystickAttachVirtual).
3. Call any of the SDL_JoystickSetVirtual* functions when joystick-state changes.  Please note that virtual-joystick state will only get applied on the next call to SDL_JoystickUpdate, or when pumping or polling for SDL events (via SDL_PumpEvents or SDL_PollEvent).


Here is a listing of the new, public APIs, at present and subject to change:

------------------------------------------------------------

/**
 * Attaches a new virtual joystick.
 * Returns the joystick's device index, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nballs, int nbuttons, int nhats);

/**
 * Detaches a virtual joystick
 * Returns 0 on success, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);

/**
 * Indicates whether or not a virtual-joystick is at a given device index.
 */
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);

/**
 * Set values on an opened, virtual-joystick's controls.
 * Returns 0 on success, -1 on error.
 */
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick * joystick, int axis, Sint16 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualBall(SDL_Joystick * joystick, int ball, Sint16 xrel, Sint16 yrel);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick * joystick, int button, Uint8 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick * joystick, int hat, Uint8 value);

------------------------------------------------------------

Miscellaneous notes on the initial patch, which are also subject to change:

1. no test code is present in SDL, yet.  This should, perhaps, change.  Initial development was done with an ImGui-based app, which potentially is too thick for use in SDL-official.  If tests are to be added, what kind of tests?  Automated?  Graphical?

2. virtual game controllers can be created by calling SDL_JoystickAttachVirtual with a joystick-type of SDL_JOYSTICK_TYPE_GAME_CONTROLLER, with naxes (num axes) set to SDL_CONTROLLER_AXIS_MAX, and with nbuttons (num buttons) set to SDL_CONTROLLER_BUTTON_MAX.  When updating their state, values of type SDL_GameControllerAxis or SDL_GameControllerButton can be casted to an int and used for the control-index (in calls to SDL_JoystickSetVirtual* functions).

3. virtual joysticks' guids are mostly all-zeros with the exception of the last two bytes, the first of which is a 'v', to indicate that the guid is a virtual one, and the second of which is a SDL_JoystickType that has been converted into a Uint8.

4. virtual joysticks are ONLY turned into virtual game-controllers if and when their joystick-type is set to SDL_JOYSTICK_TYPE_GAMECONTROLLER.  This is controlled by having SDL's default list of game-controllers have a single entry for a virtual game controller (of guid, "00000000000000000000000000007601", which is subject to the guid-encoding described above).

5. regarding having to call SDL_JoystickUpdate, either directly or indirectly via SDL_PumpEvents or SDL_PollEvents, before new virtual-joystick state becomes active (as specified via SDL_JoystickSetVirtual* function-calls), this was done to match behavior found in SDL's other joystick drivers, almost all of which will only update SDL-state during SDL_JoystickUpdate.

6. the initial patch is based off of SDL 2.0.12

7. the virtual joystick subsystem is disabled by default.  It should be possible to enable it by building with SDL_JOYSTICK_VIRTUAL=1



Questions, comments, suggestions, or bug reports very welcome!
2020-03-13 19:08:45 -07:00
Sam Lantinga
879f137aec Added support for the older Xbox One S Bluetooth controller report format 2020-03-13 19:00:24 -07:00
Sam Lantinga
d662a65964 Fixed crash if manufacturer or product string is NULL 2020-03-13 19:00:22 -07:00
Sam Lantinga
255c9c23d4 Fixed bug 4921 - Do not swap B/X buttons on GameCube controller unless it's requested
The binding for the Mayflash GameCube controller adapter now respects the SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS hint
2020-03-13 13:28:33 -07:00
Sam Lantinga
6318765d54 Handle entirely duplicated joystick product names, as well as vendor and product names that start with the name of the vendor, but with different case (e.g. 8bitdo 8BitDo) 2020-03-13 13:05:43 -07:00
Sam Lantinga
de2001eeee Fixed binding the D-PAD on the 8BitDo M30 controller 2020-03-13 13:05:40 -07:00
Sam Lantinga
cb2f78b12d Updated 8BitDo SF30 Pro mapping with hint support, added Android binding for the 8BitDo M30 Gamepad 2020-03-13 13:05:38 -07:00
Sam Lantinga
80d075a01a Fixed compiler warnings 2020-03-13 09:43:48 -07:00
Sam Lantinga
5722e88481 Fixed build warnings 2020-03-12 19:49:33 -07:00
Sam Lantinga
c44473ba73 Unified code to standardize joystick names 2020-03-12 19:47:30 -07:00
Sam Lantinga
db3b3a1d84 Added support for SDL hints in the game controller mapping database 2020-03-12 19:47:28 -07:00
Sam Lantinga
9fdc6cf307 Removed Xbox HIDAPI debug code 2020-03-10 18:34:33 -07:00
Sam Lantinga
fe97992185 Read the buttons on Nintendo Switch and GameCube controllers as they are labeled, and swap them if the applications wants positional button data instead. 2020-03-10 17:35:14 -07:00
Sam Lantinga
4caa6a0688 Fixed bug 4921 - Do not swap B/X buttons on GameCube controller unless it's requested
Ethan Lee

Basically replicating the solution of the Switch Controller's button label issue. Physical layout should take priority unless it's explicitly requested by the user or application!
2020-03-10 16:41:42 -07:00
Cameron Gutman
4e0fb110c8 Clear the old player index slot when moving to a new one 2020-03-07 19:21:21 -08:00
Cameron Gutman
165ccaa85b Fix incorrect player index when assigning a joystick the same index twice
Prior to this fix, we would hit the existing_instance >= 0 case and move the joystick
again to a different index than the one requested by the caller. It also breaks the assumption
that a SDL_JoystickID is only present in SDL_joystick_players at one location.
2020-03-07 17:20:04 -08:00
Cameron Gutman
467434b92d Added support for indicating player index on DS4 controllers 2020-03-07 13:17:28 -08:00
Sam Lantinga
e9bc21fba5 Fixed rumble for third-party Nintento Switch Pro controllers
The 8BitDo SF30 Pro Gamepad will generate a single motor pulse for each rumble message, so we need to do this frequently to have continous rumble on this device.
2020-03-04 17:10:37 -08:00
Sam Lantinga
428cfddb4c Fixed crash when a controller is disconnected while rumble is pending 2020-03-04 14:59:44 -08:00
Sam Lantinga
281d05a6d1 Fixed handling the guide button with both V1 and V2 of the Xbox One Bluetooth wireless protocols 2020-03-04 09:42:10 -08:00
Sam Lantinga
07000bfc33 Fixed bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application
Jake Breen

I have tracked it down to a call on
hid_device_info() -> HidD_GetManufacturerString (Line 499 in src\hidapi\windows\hid.c)
2020-03-02 17:31:58 -08:00
Sam Lantinga
3b3ae4d14d Possible fix for bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application
Jake Breen

When I run SDL_INIT with SDL_INIT_JOYSTICK it stalls for about 10 seconds (last report was 10,615ms), but only if I'm currently playing audio. (Like in Spotify for example.)

querying something related to device access (last dll loaded)
'BabbysFirst64.exe' (Win32): Loaded 'C:\Windows\SysWOW64\deviceaccess.dll'.

I use a USB DAC because my mobo's audio out is pretty not great. And I've noticed unplugging it seems to solve the issue. I haven't noticed any other issues that are caused by my DAC.

My DAC is the Sound BlasterX G1 https://us.creative.com/p/gaming-headsets/sound-blasterx-g1
Vid = 041E
PID = 3249

My system specs:
- Windows 10 Pro
- Ryzen 2700x
- 16GB Ram
- Nvidia 2070 RTX

Additional USB devices plugged in:
- Valve Index
- Xbox One Elite Controller
2020-03-02 15:06:47 -08:00
Sam Lantinga
eb19631a1e This controller firmware is supported on Windows, and is covered by the Bluetooth check on Mac OSX 2020-03-02 10:57:57 -08:00
Sam Lantinga
49564c8b8d Added support for the PDP Victrix Pro FS with Touch Pad for PS4 2020-03-02 10:47:48 -08:00
Sam Lantinga
4572dd2ae6 Fixed bug 4854 - Add a way to extend the values in controller_type.h
Added a hint SDL_HINT_GAMECONTROLLERTYPE to allow overriding the built-in controller type database
2020-03-02 10:37:28 -08:00
Sam Lantinga
27f346a058 Fixed compile warning 2020-03-02 09:46:37 -08:00
Sam Lantinga
339612d5af ControllerList: add support for Victrix Pro FS w/ Touchpad for PS4 2020-03-02 09:35:12 -08:00
Sam Lantinga
52be663380 Use SDL math functions in Steam Controller support 2020-03-02 09:35:09 -08:00
Sam Lantinga
756d2073fe Updated the HIDAPI Xbox One driver with support for Bluetooth Xbox One controllers 2020-03-02 09:26:12 -08:00
Sam Lantinga
6590d078d7 Fixed bug 4996 - Mac: XBoxOne Bluetooth rumble isn't working
rofferom

I have an annoying issue on MacOS about XBoxOne Bluetooth rumble (Vendor: 0x045e, Product: 0x02fd).

When 360controller is installed, rumble is working correctly. However, Bluetooth rumble isn't working at all, with or without 360controller installed (although it is working with Chrome + https://html5gamepad.com).

I looked at the code, and it seems that XBox controllers are managed in MacOS in this file: SDL_hidapi_xbox360.c. The XBoxOne file is disabled for MacOS in SDL_hidjoystick_c.h.

The function HIDAPI_DriverXbox360_Rumble() is called correctly, and hid_write() returns no error.

I have tried a stupid test. I took the rumble packet from 360controller: ec4e88eb2d/XBOBTFF/FFDriver.cpp (L620). With the patch I have attached, I manage to have rumble working on Bluetooth (with some stupid vibration level, but it proves it can if the packet is changed).

But it breaks the USB rumble with 360controller. A comment in the function makes an explicit reference to 360controller, I think that's why I have broken this specific usecase.

I don't know what is the correct way to fix this, but it seems that the current implementation has a missing case for Bluetooth support.


Note that I also tested master this morning, and I have another issue:
    if (!device->ffservice) {
        return SDL_Unsupported();
    }

test fails in DARWIN_JoystickRumble(). This test has been done quickly, I'm not totaly confident about its accuracy.
2020-03-01 14:52:49 -08:00
Romain Roff?
5346216368 mac: Fix gamepad detection 2020-03-01 13:01:53 -08:00
Sam Lantinga
1af31a26d1 Fixed trying to handle the HORI Wireless Switch Pad when connected via USB 2020-02-27 13:53:32 -08:00
Sam Lantinga
20d67446e0 Xbox One controller rumble doesn't need synchronization if you use a packet counter of 0 2020-02-27 09:33:32 -08:00
Sam Lantinga
8d14636326 Fixed support for third party Xbox 360 wireless controller dongle 2020-02-19 08:26:00 -08:00