Commit graph

31 commits

Author SHA1 Message Date
Lioncash
50a476c371 Assert: Uppercase assertion macros
Macros should be all upper-cased. This is also kind of a wart that's
been sticking out for quite a while now (we avoid prefixing
underscores).
2018-03-14 22:03:12 -04:00
Léo Lam
6a93223283 evdev: Always unref received udev devices
Whenever udev_monitor_receive_device() returns a non-null pointer,
the device must be unref'd after use with udev_device_unref().

We previously missed some unref calls for non-evdev devices.
2018-02-05 01:01:05 +01:00
Léo Lam
0822bb347d evdev: Don't leak eventfd on shutdown 2018-02-04 22:48:38 +01:00
Léo Lam
9a3705f82d evdev: Fix select() call
It's not guaranteed that the eventfd is smaller than the monitor fd,
because fds are not always monotonically allocated. To select()
correctly in all cases, use the max between the monitor fd and eventfd.
2018-02-04 22:45:28 +01:00
Leo Lam
4733bbd8f3
Merge pull request #6166 from ligfx/invokedeviceschangedcallbacks
ControllerInterface: cleanup callbacks API and logic
2017-12-15 21:05:17 +01:00
Scott Pleb
0bede93daa evdev: Correctly calculate axis range for min values greater than 0.
Axis range was previously calculated as max + abs(min), which relies on the assumption that
min will not exceed 0. For (min, max) values like (0, 255) or (-128, 127), which I assume to
be the most common cases, the range is correctly calculated as 255. However, given (20,
235), the range is erroneously calculated as 255, leading to axis values being normalized
incorrectly.

SDL already handles this case correctly. After changing the range calculation to max - min,
the axis values received from the evdev backend are practically identical to the values
received from the SDL backend.
2017-11-11 02:07:04 -05:00
Michael M
7355b5f70d ControllerInterface: invoke callbacks in AddDevice/RemoveDevice
Some backends already cause this to happen, so make it consistent across
systems.
2017-11-10 13:37:41 -08:00
Lioncash
696e1b40b5 Common: Move version strings to their own header
Ideally Common.h wouldn't be a header in the Common library, and instead be renamed to something else, like PlatformCompatibility.h or something, but even then, there's still some things in the header that don't really fall under that label

This moves the version strings out to their own version header that doesn't dump a bunch of other unrelated things into scope, like what Common.h was doing.

This also places them into the Common namespace, as opposed to letting them sit in the global namespace.
2017-09-09 19:28:10 -04:00
Tillmann Karras
57a005ff3e evdev: reduce startup time
GetName() creates a new evdev device which calls tons of ioctls. But the
main culprit is close() which for input devices appears to be a slow
path in the kernel.

This commit reduces PopulateDevices() by 50% on my laptop, but ~730 ms
is still ridiculously slow for something that isn't needed right away.
2016-12-26 01:24:35 +01:00
Tillmann Karras
f575902cf3 evdev: set flag in a thread-safe way 2016-12-05 00:47:26 +00:00
Tillmann Karras
3c090a37d4 evdev: fix shutdown hang
Note: This probably means our approach of populating from udev isn't
safe to be called multiple times.
2016-12-05 00:47:26 +00:00
Michael Maltese
3e69d066f5 ControllerInterface: replace Reinitialize with RefreshDevices
The SDL backend crashes when you close a joystick after SDL_Quit has
been called. Some backends don't need to be shutdown and
re-initialized everytime, we can just ask to enumerate devices again.
2016-11-30 16:07:55 -08:00
Léo Lam
68156a02ed Fix -Wunused-result warnings 2016-10-23 00:43:08 +02:00
Léo Lam
135641404a evdev: Add hotplugging support
This adds hotplugging support to the evdev input backend. We use
libudev to monitor changes to input devices in a separate thread.
Removed devices are removed from the devices list, and new devices
are added to the list.

The effect is that controllers are usable immediately after plugging
them without having to manually refresh devices (if they were
configured to be used, of course).
2016-07-29 17:18:40 +02:00
Léo Lam
788e19f54d ControllerInterface: Make the ID assigning code common
This makes the device ID assigning code common to all backends, by
moving it to AddDevice() instead of copy-pasting or replicating
the logic in the backends.

Also, to prepare for hotplugging, instead of relying on a name usage
count, the new ID assigning system always starts from ID 0 and tries
to assign the first ID that is not used.
2016-07-14 10:50:53 +02:00
Scott Mansell
e0839a9478 Strip whitespace from Evdev and OSX controller names. 2016-07-12 14:19:07 +12:00
Léo Lam
6cc4591226 evdev: Clamp axis values to the 0.0-1.0 range
The values are expected to be in the 0.0-1.0 range (as indicated by the
comment), and other parts of Dolphin also expect it to be in that range
since the "full" axis has a -1.0 to 1.0 range.  However, this is not
always the case and fvalue can end up being outside of the range. This
clamps fvalue to always be in the 0.0 and 1.0 range.
2016-07-11 14:00:09 +02:00
Léo Lam
8678133e87 ControllerInterface: Switch to std::shared_ptr
Small cleanup by using std::shared_ptr and getting rid of
ciface.Devices() which just returned the m_devices (which defeats the
point of making m_devices protected).

Incidentally, this should make the code safer when we have
different threads accessing devices in the future (for hotplug?).

A lot of code use Device references directly so there is
no easy way to remove FindDevice() and make those unique_ptrs.
2016-06-25 21:46:39 +02:00
Léo Lam
fd29e5c4cc ControllerInterface: Don't pass m_devices to the backends
Previously, the devices vector would be passed to all backends. They
would then manually push_back to it to add new devices. This was fine
but caused issues when trying to add synchronisation.

Instead, backends now call AddDevice() to fill m_devices so that it is
not accessible from the outside.
2016-06-25 13:46:53 +02:00
Pierre Bourdon
3570c7f03a Reformat all the things. Have fun with merge conflicts. 2016-06-24 10:43:46 +02:00
Lioncash
19ac565e0d Common: Move asserts to their own header 2015-09-26 18:51:27 -04:00
Tillmann Karras
b3ff66dc7a evdev: don't pass null path to the kernel 2015-08-15 12:51:34 +02:00
Rohit Nirmal
ac54bbe02d Fix building with PCH disabled. 2015-08-04 12:59:34 -05:00
Tillmann Karras
5a05187b3b Fix some warnings
reorder, sign-compare, pessimizing-move
2015-08-04 10:58:24 +02:00
Gabriel Corona
2722f3f337 Stable device identifier for evdev 2015-08-02 01:51:06 +02:00
Scott Mansell
dc25277a2f Merge branch 'stable' into 'master' 2015-07-13 12:40:38 +12:00
Rohit Nirmal
c38ae5236e Fix building with PCH disabled. 2015-07-08 13:52:43 -05:00
Scott Mansell
6e969133f5 evdev: Delete rumble effects on the correct file descriptor.
Was using m_id insted of m_fd.
Also re-arrange the code so rumble effects always get deleted instead of
just on stop commands.
2015-07-07 16:59:10 +12:00
Tillmann Karras
64b51df55d evdev: fix -Wunused-private-field warning 2015-07-04 14:14:15 +02:00
Scott Mansell
77183899e0 evdev: Support axis with ranges which extend below zero. 2015-07-01 10:13:05 +12:00
Scott Mansell
2721fdf8a9 Linux: Add an evdev based controller backend, to replace SDL. 2015-07-01 10:13:05 +12:00