Commit Graph

902 Commits

Author SHA1 Message Date
Sam Lantinga
07af9baa86 Use the correct name for the Amazon Luna Gamepad 2021-03-26 13:05:38 -07:00
Sam Lantinga
ef36355563 Added mapping for the Amazon Luna controller on macOS 2021-03-26 13:03:29 -07:00
Sam Lantinga
3377861ab1 Added support for the Amazon Game Controller to the HIDAPI driver 2021-03-26 11:57:19 -07:00
Sam Lantinga
0bdf4f95bf Disable system gestures on MFi controllers while they're open, so we get access to the back button, etc. 2021-03-22 19:19:01 -07:00
Ivan Epifanov
a4ddb175f1 Formatting 2021-03-08 09:07:12 -08:00
Ivan Epifanov
e5cbe7cf7a Add l2/r2 axes, l3/r3 buttons. rumble and ledbar support for ds4 2021-03-08 09:07:12 -08:00
Ivan Epifanov
a05f92da1c Update joystick api to 2.0.14 2021-03-08 09:07:12 -08:00
Ivan Epifanov
7d89f09f74 ISO C90 fixes 2021-03-08 09:07:12 -08:00
Ivan Epifanov
73b545ed28 Fix joystick support 2021-03-08 09:07:12 -08:00
Ivan Epifanov
2d64e37e41 Initial rebase of xerpi's port 2021-03-08 09:07:12 -08:00
JibbSmart
c287087fcc Only change joystick->nbuttons for Joy-Cons, since they're the only ones that have these "paddles" 2021-02-22 17:54:32 -08:00
JibbSmart
ee52624f95 Switch Joy-Con SL and SR buttons are now mapped to matching paddle positions so that all buttons can be accessed when using SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS 2021-02-22 17:54:32 -08:00
Mathieu Eyraud
7a2b6f331b Guard Inotify stuff with macro
This fix implicit declaration of close and unused variable warning.
2021-02-22 09:07:07 -08:00
Sam Lantinga
1a17ab30e1 Added mappings for popular controllers on Chromebooks 2021-02-21 11:03:26 -08:00
David Gow
db58166e9b joystick: hidapi: Properly include <unistd.h> when inotify not available
In the extremely unlikely event that inotify is not available (and,
therefore, HAVE_INOTIFY is not #defined), SDL will no-longer build.

This is because <unistd.h> is only included when HAVE_INOTIFY is
defined, and PR #4098 adds a call to access(…, F_OK), which requires
<unistd.h>.

(Note that the F_OK symbol is the only one which actually prevented
SDL from compiling, but both access() and close() fell back to implicit
definitions, which is a bit concerning.)

Fixes: 8d43f45a7b ("Don't use udev for joystick enumeration if running in a container")
2021-02-21 12:55:01 +03:00
Ludovico de Nittis
8d43f45a7b Don't use udev for joystick enumeration if running in a container
If we are running in a container, like Flatpak[1] or pressure-vessel[2],
it's likely that we are using user namespaces,
therefore udev event notification via netlink won't work reliably.
Use their filesystem API to detect them and automatically fallback to
the inotify-based enumeration.

[1] <https://flatpak.org/>
[2]
<https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/tree/master/pressure-vessel>

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-20 23:01:38 -08:00
Ludovico de Nittis
2c3269152a Use inotify for HIDAPI joystick enumeration if not using udev
This improves SDL's ability to detect HIDAPI joystick hotplug in a
container environment because we cannot reliably receive events from
udev in a container.

For a more detailed explanation of why this issue happens with
containers, please check the previous commit
"joystick: Use inotify to detect joystick unplug if not using udev"
(b0eba1c5).

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-20 23:01:38 -08:00
Ludovico de Nittis
b17242bf98 Allow libudev for HIDAPI joystick to be disabled at runtime
As already explained in the previous commit "joystick: Allow libudev to
be disabled at runtime" (13e7d1a9), libudev can fail in a container.

To make it easier to experiment with, we add a new environment variable
"SDL_HIDAPI_JOYSTICK_DISABLE_UDEV" that disables udev and let it
fallback to the device enumeration using polling.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2021-02-20 23:01:38 -08:00
Sam Lantinga
42607909a0 Remove devices from the list after they've been disconnected due to read errors.
This fixes problems with controllers not being re-detected when a computer goes to sleep and a controller is removed and plugged back in while it's asleep.
2021-02-20 22:51:57 -08:00
Matt Borgerson
4aa2e74844 Add Xbox Controller S entry to gamecontrollerdb 2021-02-16 10:15:44 -08:00
soredake
39153f81b9 add Linux mapping for Ipega PG-9087S, closes #3783 2021-02-12 08:00:41 -08:00
Sam Lantinga
5427f4861b Added support for trigger rumble for all Microsoft Xbox One controllers 2021-02-11 17:28:07 -08:00
Sam Lantinga
1f7ec3fa4e Added support for the PowerA Xbox One Series X Wired Controller 2021-02-11 17:27:22 -08:00
Ozkan Sezer
dc45a228b9 avoid some pedantic warnings in array initializers 2021-02-10 10:22:20 -05:00
Sam Lantinga
9c3aa7f055 SDL: fix packet handling for original version of Stadia FW 2021-02-10 10:22:20 -05:00
Cameron Gutman
f4d58689e0 Fix Xbox Series X controller on macOS
There were two different implementations of IsBluetoothXboxOneController(), one
in SDL_hidapi_xbox360.c and one in SDL_hidapi_xboxone.c. The latter had been
updated to include USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH while the former had
not.

This mismatch led to the Xbox Series X failing on macOS only. We have special
code for handling the 360Controller driver for macOS which requires us to use
the Xbox 360 driver for wired Xbox One controllers, and the SDL_hidapi_xbox360
version of IsBluetoothXboxOneController() was used to determine which devices
were wired.

In addition to adding the missing USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH, this
change moves IsBluetoothXboxOneController() into a single shared function which
will ensure this bug won't happen again.
2021-02-10 10:22:19 -05:00
Sam Lantinga
85235985fb Fixed detecting the paddles on the Xbox Elite Series 1 controller 2021-02-10 10:22:19 -05:00
Sam Lantinga
fadfa51022 Don't uncorrelate while rumble is active and stay correlated longer in case raw input messages are lagging a bit. 2021-02-10 10:22:19 -05:00
Sam Lantinga
2cc70ca39e Fixed crash if the GameCube controller hasn't been opened yet 2021-02-10 10:22:18 -05:00
Sam Lantinga
7f710e93f0 Make sure we don't create a game controller mapping for HID devices that aren't supported by HIDAPI 2021-02-10 10:22:18 -05:00
Sam Lantinga
7e19c634c1 Note that the Logitech G29 (PS4) is a racing wheel 2021-02-10 10:22:18 -05:00
Sam Lantinga
d81eaf8da5 Added explicit case from Uint8 to int before subtracting offset 2021-02-10 10:22:17 -05:00
Sam Lantinga
bec9d740ec Fixed compile warning 2021-02-10 10:22:17 -05:00
Sam Lantinga
ac72a2ba8e Fixed bug 5493 - Hint to let the user opt out of having Switch controllers' Home button lit when opened
jibb

New hint to let the user opt out of having Switch controllers' Home button lit when opened.

This is more consistent with the Switch itself (which doesn't light the button normally) and may be preferred by users who may disconnect their controller without letting the application close it.

I think this warrants a Switch-specific hint because the default behaviour is unusual (inconsistent with using a Switch controller on a Switch itself or with some other programs on PC), and because of that it's distinct from other lights (the player number on Switch controllers and the player colour on PlayStation controllers).
2021-02-10 10:22:16 -05:00
Sam Lantinga
c857b5e0c9 Minor cleanup 2021-01-24 00:51:26 -05:00
Sam Lantinga
1981d23f4b Fixed bug 5466 - Add haptic support for Stadia Controller
Dimitriy Ryazantcev

Consider adding support for Stadia Controller haptics.

Here is example code how to deal with it:
99314be815/device/gamepad/hid_haptic_gamepad.cc (L45)
2021-01-24 00:51:26 -05:00
JibbSmart
0f57864c9e Hint SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS added so we can recognise a Joy-Con as half a Pro Controller, so we can read its analog input and read its sensors just like we do a Pro Controller. 2021-01-24 00:51:25 -05:00
Ozkan Sezer
fd65aaa9a8 move outdated winmm and psp joystick codes to struct _SDL_JoystickDriver
build-tested only. (bug #5472.)
2021-01-24 00:51:25 -05:00
Ozkan Sezer
2376458841 renamed SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H to SDL_HAVE_MACHINE_JOYSTICK_H 2021-01-24 00:51:25 -05:00
Sam Lantinga
f68b36df75 Added support for the EVORETRO GameCube Adapter in PC mode 2021-01-24 00:51:25 -05:00
Sam Lantinga
9c88eac856 ControllerList: fix typo 2021-01-24 00:51:25 -05:00
Ozkan Sezer
11fce32162 SDL_dinputjoystick.c: fixes to dfDIJoystick2[] array from Wine git.
Fix V/A/FSlider dwOfs values in c_dfDIJoystick2
af2f419426

Add missing ASPECT flags for c_dfDIJoystick2
e2e100272f

Closes bug #5474.
2021-01-24 00:51:25 -05:00
Ozkan Sezer
4a776557af old os2 analogue joystick code ported from SDL-1.2. disabled by default,
build-tested only.
2021-01-24 00:51:25 -05:00
Sam Lantinga
9e45372a2f Fixed build on Android and iOS 2021-01-24 00:51:25 -05:00
Sam Lantinga
3527b49459 Fixed initializing the Nyko and EVORETRO GameCube adaptors
This requires root on most Linux distributions, as we have to directly send USB messages to the devices to enable input reports.
2021-01-24 00:51:24 -05:00
Sam Lantinga
178ae70a29 Don't add paddle mappings for the Xbox One Elite Series 1 controller, since they can't be unmapped and read directly on that controller. 2021-01-24 00:51:24 -05:00
Cameron Gutman
6e97170e96 Use PS4 rumble hint as the default for the PS5 rumble hint
Existing SDL applications may not know about the need to set a specific
hint to enable rumble on PS5 controllers, even though they may already
set the equivalent SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE hint for PS4
controller rumble support.

Rather than requiring those developers update their apps, let's use the
SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE value as an indication of the behavior
they are expected for all PlayStation controllers.
2021-01-24 00:51:24 -05:00
Ozkan Sezer
6393d14de5 SDL_virtualjoystick.c: remove wrong #endif comment. 2021-01-24 00:51:24 -05:00
Ozkan Sezer
f3835702d3 fix build with --disable-directx 2021-01-24 00:51:24 -05:00
Sam Lantinga
2ea393bd83 Fixed the screenshot button mapping on third party Bluetooth Nintendo Switch Pro controllers 2021-01-24 00:51:23 -05:00
Ozkan Sezer
bdb3e6b84f SDL_hidapi_switch.c: fix build with older compilers 2021-01-15 12:40:00 +03:00
Sam Lantinga
e3dbae5010 Get the serial number for the Nintendo Switch Pro controller 2021-01-14 23:49:41 -08:00
Sam Lantinga
5fc743c4fd Phantom Nintendo Switch Pro Controller initialization problem 2021-01-14 23:49:37 -08:00
Sam Lantinga
92742306a6 Fixed rumble reset failing for Switch Pro controllers in USB mode 2021-01-14 23:49:33 -08:00
Sam Lantinga
d0b87fede6 Added HIDAPI rumble debug info 2021-01-14 23:49:27 -08:00
Sam Lantinga
e2f46ed8ef Always lock the HIDAPI device when closing, in case rumble is pending 2021-01-14 23:49:20 -08:00
Sam Lantinga
907b8eebc3 Make sure the HIDAPI device is locked when closing it, in case there is rumble pending that didn't complete 2021-01-14 23:49:16 -08:00
Sam Lantinga
b3848c5120 Fixed bug 5445 - Incorrect Switch Pro Controller face buttons when SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS disabled
jibb

I'm testing with DualShock 4, DualSense, Switch Pro Controller, and PowerA Switch Controller.

I'm using the standard mapping file from here:
https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt

With SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS turned off (set to "0") I expect the button positions to be the same on all devices, based on Xbox controller button naming (eg SDL_GameControllerGetButton(g, SDL_CONTROLLER_BUTTON_Y) gives me whether the North face button is pressed).

However, the Switch Pro Controller layout is wrong (matching labels rather than positions, so X and Y are swapped and A and B are swapped). And with the PowerA controller the East and West buttons are correct, but the North and South buttons are swapped instead.

Mathias Kaerlev

Also seeing this on 2.0.14. This is most likely a regression, since we weren't seeing this on an earlier SDL version.

I suspect it might be caused by this commit:
a569b21188 (diff-da9344d94c66b8c702a45e7649f412039f08bba83bd82de33f5c80ea9c8c39d5)

It seems like both the HIDAPI driver and SDL_gamecontroller.c will try to swap the buttons if the hint is set to 0, causing the button remap to cancel out.
2021-01-14 15:15:57 -08:00
Sam Lantinga
bdc6e4ffc5 Fixed bug 5195 - Replugging in "mixed" controller types crashes on macOS
RustyM

This is related to Bug 5034, but crashes under a somewhat different condition.

In the latest tip (changeset 13914) or with the SDL 2.0.12 source + David?s 5034 patch, unplugging and then replugging in certain controller types on macOS will crash. A mix of new controllers like Switch Pro, PS4 and Xbox One all work without issue. But if a controller without a rumble function, like many SNES retro USB gamepads, is mixed with a PS4 or Switch Pro controller it will crash.

File: joystick/darwin/SDL_sysjoystick.c
Function: static recDevice *FreeDevice(recDevice *removeDevice)
On line 159: while (device->pNext != removeDevice) {
Causes: Thread 1: EXC_BAD_ACCESS (code=1, address=0x188)

This can be reproduced in testgamecontroller" by starting the test program with both a ?retro? controller plugged in and a ?modern rumble? controller (Switch Pro/PS4). This may crash on launch, but it depends on which controller ends up as device 0. If it doesn?t crash, unplug the ?modern rumble? controller and plug it back in.

Some of the "retro" controllers I?ve seen this crash with:
- iBuffalo SNES Controller
- 8Bitdo SN30 Gamepad (in MacOS mode)
- Retrolink NES Controller
- HuiJia SNES Controller Adaptor

The issue appears macOS specific. Seen on 10.12.6 and 10.14.6. Not seen on Windows 10.

The while loop in FreeDevice() assumes that every device is not NULL.

    recDevice *device = gpDeviceList;
    while (device->pNext != removeDevice) {
        device = device->pNext;
    }
    device->pNext = pDeviceNext;

So maybe we should check for NULL here? Or instead prevent adding NULL devices to the list in the first place? Checking device for NULL before entering the loop appears to work.

    recDevice *device = gpDeviceList;
    if (!device) {
        while (device->pNext != removeDevice) {
            device = device->pNext;
        }
    }
    device->pNext = pDeviceNext;
2021-01-14 15:03:11 -08:00
Sam Lantinga
fbd7c718b6 Don't blink the Xbox 360 LED when setting the player slot, it's probably already been set by a driver 2021-01-13 11:02:07 -08:00
Sam Lantinga
d757ec7f5c Only select the gamepad interfaces on the Xbox 360 wireless adapter 2021-01-13 11:02:01 -08:00
JibbSmart
e9887045a2 Gyro and Accel sensor support for Switch Pro Controller.
Note that axes are changed to match the axes we're using with PlayStation controllers, since users will appreciate consistent behaviour across devices.
2021-01-11 15:36:40 +08:00
Sam Lantinga
a5dba7d3ab Fixed Xbox One Series X share button incorrectly triggering on newer firmware 2021-01-08 09:54:52 -08:00
Sam Lantinga
d72dbd9883 Fixed detection of the Wooting Two keyboard, which shows up as an Xbox 360 controller 2021-01-04 17:30:28 -08:00
Sam Lantinga
b2a0c712cb Allow setting the player index to -1, which turns off the player LED for PS5 controllers 2021-01-04 12:24:44 -08:00
Sam Lantinga
bf754b52bf Valve contributed code is under the Zlib license 2021-01-04 12:17:24 -08:00
Ozkan Sezer
a594b85031 use WIN_StringToUTF8W macro instead of WIN_StringToUTF8, where needed:
i.e. where the string is known guaranteed to be WCHAR*, in:
- SDL_dinputjoystick.c (WIN_IsXInputDevice): VARIANT->var is BSTR (WCHAR*)
- SDL_rawinputjoystick.c (RAWINPUT_AddDevice): string is WCHAR*
- SDL_windows_gaming_input.c (IEventHandler_CRawGameControllerVtbl_InvokeAdded):
  string is WCHAR*

There should be more of these..
2021-01-04 10:00:30 +03:00
Ozkan Sezer
f2bd861cd7 move SDL_tcsstr definition to core/windows/SDL_windows.h 2021-01-04 08:50:00 +03:00
Ozkan Sezer
ae18109a92 SDL_windowsjoystick.c (SDL_CreateDeviceNotification): use L, not TEXT()
cf. bug #5435.
2021-01-04 01:23:50 +03:00
Ozkan Sezer
398d2764c7 RAWINPUT_InitWindowsGamingInput: change pNamespace from LPTSTR to PCWSTR
because WindowsCreateStringReference specifically accepts const WCHAR *
- WGI_JoystickInit(): ditto.

cf. bug #5435.
2021-01-04 01:23:50 +03:00
Ozkan Sezer
f09e0af7aa SDL_dinputjoystick.c (IsXInputDevice): adjust to be ANSI/UNICODE-agnostic
cf. bug #5435.
2021-01-04 01:23:50 +03:00
Sam Lantinga
9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga
480c1f9fef Make sure we're not starving report reads when there's lots of rumble 2021-01-01 11:12:36 -08:00
Sam Lantinga
0684572ccc Added a hint to control whether the player LEDs should be lit to indicate which player is associated with a PS5 controller. 2020-12-29 12:13:10 -08:00
Sam Lantinga
0ed4d92938 Fixed setting player LEDs for PS5 controllers over Bluetooth 2020-12-23 04:53:23 -08:00
Sam Lantinga
6341bb35a5 Fixed controller disconnect detection for PS4 and PS5 controllers over Bluetooth 2020-12-22 21:51:59 -08:00
Sam Lantinga
a30adae567 Make it possible to turn on PS4 rumble effects at runtime using the hint 2020-12-22 20:58:32 -08:00
Sam Lantinga
c93947a2cb Make it possible to turn on PS5 rumble effects at runtime using the hint 2020-12-22 20:12:03 -08:00
Sam Lantinga
058a0ab47f Set the pad lights on the PS5 controller corresponding to the player index
Also allow setting the player index from testgamecontroller using the number keys
2020-12-22 14:38:32 -08:00
Sam Lantinga
6a57072eef Only add the touchpad and sensors to the PS5 controller if effects are enabled 2020-12-22 14:10:08 -08:00
Sam Lantinga
4ec776c334 Don't switch the PS5 controller out of DirectInput mode by default 2020-12-22 13:29:23 -08:00
Sam Lantinga
ee180efda7 Fixed bug 5406 - Upstreaming DragonFlyBSD changes from DeltaPorts (patch from David Carlier) 2020-12-20 12:08:49 -08:00
Sam Lantinga
cbe13d232d Fixed controller hotplug detection when joystick thread is not enabled 2020-12-18 13:10:36 -08:00
Sam Lantinga
f0577bc9ea ControllerList: setup the ps5 default deadzone to match PS4 instead of defaulting to same a XboxOne/Switch 2020-12-18 10:09:06 -08:00
Ozkan Sezer
90456670b5 more "'for' loop initial declarations are only allowed in C99 mode" fixes 2020-12-17 14:11:00 +03:00
Sam Lantinga
f484abbdc8 Added Android mapping for the Xbox One Series X controller over Bluetooth 2020-12-15 14:57:51 -08:00
Ozkan Sezer
637d425e3e whitespace. 2020-12-15 00:11:10 +03:00
Sam Lantinga
e65e4fd3ef Fixed detecting the guide button on Xbox One S controllers over Bluetooth on Linux 2020-12-14 09:48:51 -08:00
Sam Lantinga
8795ca7067 Fixed bug 5241 - SDL on Linux needs a way to turn deadzones off
pj5085

I added some printf to verify the math being done.  Of the three joysticks I have, it works correctly for at least two, and seems to work correctly for the third.  I say "seems to" because, for the third joystick, the values never go through the AxisCorrect function, and thus never hit my printf statements, even though they did in the version I wrote my patch against.  I'm not sure what's going on there, but it at least seems to be working correctly in as much as I can tell.

I note this result in particular, for an SNES Gamepad (min=0, max=255):

Joystick value 0 becomes -32768
Joystick value 127 becomes 0
Joystick value 255 becomes 32767

Without the code that forces a zero point, the 127 input value would become -129, so I think you see why I added that code to turn it into zero.  However, I think Kai Krakow has a point about how SDL shouldn't assume that there should be a center.

Obviously in the majority of cases there actually should be a center, and the code that turns that 127 into an actual 0 is creating only a 0.2% error over 0.4% of this joystick's range.  However, what if there is an axis that is some kind of special control, like a 4-position switch, and, for whatever reason, the joystick reports it as an axis with 4 possible values, 0 to 3?  In that case, mutilating the two center values to the same value is much more of an error and and turns that 4-position switch into a 3-position switch.  If any joystick does this with a 2-position switch, then this code would render that control entirely useless as it would report the same value with the switch in either position.  Obviously the code could require that there be at least N possible values, to guess whether something is a proper axis or just some kind of switch, but the choice of N would be arbitrary and that's ugly.

I guess the real problem here is that my gamepad is just kind of broken.  It should be reporting a range of -1 to +1 since that's what it actually does.  Also, as Kai Krakow points out, it's probably not SDL's place to fix broken hardware.  I'll add that, if SDL does fix broken hardware, it should probably actually know that it's broken rather than be merely guessing that it is.

So, to the extent that SDL is able to do stuff like this, perhaps it's something better left for the user to configure in some kind of config file.
2020-12-14 09:15:47 -08:00
Ozkan Sezer
b6e63625c8 fix bug #5395: handle old systems where inotify_init1 is not available 2020-12-13 15:32:24 +03:00
Sam Lantinga
80e5c689eb Fixed the PS5 controller not disconnecting when powered off 2020-12-13 01:20:38 -08:00
Sam Lantinga
db0a2025c3 Fixed bug 5241 - SDL on Linux needs a way to turn deadzones off
pj5085

It occurred to me that my simple patch that comments out a few lines of code does not correctly remove the dead zone since the calculation presumably assumes the dead zone has been cut out of the range.  Then, while looking into how to make it output the correct range of values, I realized SDL wasn't returning the correct range of values to begin with.

This line of code was already present:

printf("Values = { %d, %d, %d, %d, %d }\n", absinfo.value, absinfo.minimum, absinfo.maximum, absinfo.fuzz, absinfo.flat);

For my joystick this yeilds:

Values = { 0, -127, 127, 0, 15 }

Then this code calculates the coefficients:

In SDL1:
joystick->hwdata->abs_correct[i].coef[0] = (absinfo.maximum + absinfo.minimum) / 2 - absinfo.flat;
joystick->hwdata->abs_correct[i].coef[1] = (absinfo.maximum + absinfo.minimum) / 2 + absinfo.flat;
t = ((absinfo.maximum - absinfo.minimum) / 2 - 2 * absinfo.flat);
if ( t != 0 ) {
  joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t;
} else {
  joystick->hwdata->abs_correct[i].coef[2] = 0;
}

In SDL2:
joystick->hwdata->abs_correct[i].coef[0] = (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
joystick->hwdata->abs_correct[i].coef[1] = (absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat;
t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat);
if (t != 0) {
  joystick->hwdata->abs_correct[i].coef[2] = (1 << 28) / t;
} else {
  joystick->hwdata->abs_correct[i].coef[2] = 0;
}

Neither calculates the correct coefficients for the code in the AxisCorrect function.

In SDL1:
if ( value > correct->coef[0] ) {
  if ( value < correct->coef[1] ) {
    return 0;
  }
  value -= correct->coef[1];
} else {
  value -= correct->coef[0];
}
value *= correct->coef[2];
value >>= 14;

In SDL2:
value *= 2;
if (value > correct->coef[0]) {
  if (value < correct->coef[1]) {
    return 0;
  }
  value -= correct->coef[1];
} else {
  value -= correct->coef[0];
}

In SDL1, the calculated coefficients are coef[0]=15, coef[1]=-15 and coef[2]=5534751.  So with a full-scale input of 127, it calculates an output value of 37835, which is considerably out of range.

In SDL2, the calculated coefficients are coef[0]=30, coef[1]=-30, and coef[2]=1383687.  So with a full-scale input of 127, it calculates the same output value of 37835.

I tested it with the 3 joysticks I have, and it produces out-of-range values for all of them.

Anyway, since dead zones are garbage, I just deleted all of that junk and wrote some code that takes the absinfo.minimum and absinfo.maximum values and uses them to scale the axis range to -32767 through +32767.

I also made it detect when a range doesn't have an integer center point, e.g. the center of -128 to + 127 is -0.5.  In such cases, if either value to the side of the center is provided, it zeros it, but it otherwise doesn't implement any kind of dead zone.  This seemed important with my gamepad which provides only the values of 0, 127, and 255, since without this hack it would never be centered.

Also, the previous minimum output value was -32768, but as that creates an output range that has no true center, I changed the minimum value to -32767.

I tested it with the 3 joystick devices I have and it seems to create correct values for all of them.
2020-12-12 23:48:02 -08:00
Sam Lantinga
0ccb3afd37 Fixed polling values after SYN_DROPPED event 2020-12-12 22:33:11 -08:00
Sam Lantinga
9ee0e8886c Whoops, make the hint actually default to false 2020-12-12 22:11:00 -08:00
Sam Lantinga
13a4caf1d7 Fixed bug 4286 - Joystick subsystem causes "not responding" when app is in the background
Added a hint to control whether a separate thread should be used for joystick events.
This is off by default because dispatching messages in other threads appears to cause problems on some versions of Windows.
2020-12-12 22:08:02 -08:00
Sam Lantinga
797a6910fd Fixed bug 5375 - WGI: Fix HSTRING memory leak.
Joel Linn

TLDR; https://godbolt.org/z/43fd8G

Let's deduce this from C++ reference code:

https://docs.microsoft.com/en-us/cpp/cppcx/wrl/how-to-activate-and-use-a-windows-runtime-component-using-wrl?view=msvc-160
At the bottom of the page there is this snippet:
```
int wmain()
{
    /* ... more code ... */

    // Get the domain part of the URI.
    HString domainName;
    hr = uri->get_Domain(domainName.GetAddressOf());
    if (FAILED(hr))
    {
        return PrintError(__LINE__, hr);
    }

    // Print the domain name and return.
    wprintf_s(L"Domain name: %s\n", domainName.GetRawBuffer(nullptr));

    // All smart pointers and RAII objects go out of scope here.
}
```

`HString` is defined in `corewrappers.h` and the call chain for the destructor is:
`~HString() -> Release() -> ::WindowsDeleteString()`

QED
2020-12-09 20:28:51 -08:00
Sam Lantinga
a77a07152a Disabled raw input debug output 2020-12-09 07:50:15 -08:00
Sam Lantinga
cb36189692 Fixed bug 5235 - All internal sources should include SDL_assert.h
Ryan C. Gordon

We should really stick this in SDL_internal.h or something so it's always available.
2020-12-09 07:16:22 -08:00
Sam Lantinga
f2fff21762 Fixed bug 5374 - WGI: Use fast-pass strings.
Joel Linn

Eliminate additional heap allocation for short-lived HSTRINGs.
Uses `WindowsCreateStringReference()` to disable reference counting and memory management by the Window Runtime.
2020-12-09 06:24:40 -08:00
Alice Rowan
3835f2008d Fix Nyko Airflo Ex Windows mapping, add Linux/Mac mappings 2019-03-03 12:38:23 -07:00