aboutsummaryrefslogtreecommitdiffstats
path: root/libgamepad_open_device.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-25 13:23:08 +0200
committerMattias Andrée <maandree@kth.se>2022-07-25 13:23:08 +0200
commitedf5cfe55690b717ae16513519a6b5c3a7a222d0 (patch)
tree2c7ca59430ec9d1de382a3124a1d82dd901dc85a /libgamepad_open_device.c
parentm + add force feedback support (diff)
downloadlibgamepad-edf5cfe55690b717ae16513519a6b5c3a7a222d0.tar.gz
libgamepad-edf5cfe55690b717ae16513519a6b5c3a7a222d0.tar.bz2
libgamepad-edf5cfe55690b717ae16513519a6b5c3a7a222d0.tar.xz
m
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libgamepad_open_device.c')
-rw-r--r--libgamepad_open_device.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/libgamepad_open_device.c b/libgamepad_open_device.c
index 87868cb..cce0133 100644
--- a/libgamepad_open_device.c
+++ b/libgamepad_open_device.c
@@ -8,6 +8,7 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char
int err;
unsigned int i;
uint16_t n;
+ struct input_id id;
devicep->fd = dirfd;
devicep->close_fd = 0;
@@ -25,23 +26,31 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char
devicep->close_fd = 1;
}
- err = -libevdev_new_from_fd(devicep->fd, &devicep->dev);
- if (err > 0) {
+ if (ioctl(devicep->fd, EVIOCGID, &id)) {
if (devicep->close_fd) {
close(devicep->fd);
devicep->close_fd = 0;
}
- errno = err;
+ return -1;
+ }
+
+ err = libevdev_new_from_fd(devicep->fd, &devicep->dev);
+ if (err < 0) {
+ if (devicep->close_fd) {
+ close(devicep->fd);
+ devicep->close_fd = 0;
+ }
+ errno = -err;
return -1;
}
devicep->name = libevdev_get_name(devicep->dev);
devicep->unique_id = libevdev_get_uniq(devicep->dev);
devicep->physical_location = libevdev_get_phys(devicep->dev);
- devicep->bus_type = libevdev_get_id_bustype(devicep->dev);
- devicep->vendor = libevdev_get_id_vendor(devicep->dev);
- devicep->product = libevdev_get_id_product(devicep->dev);
- devicep->version = libevdev_get_id_version(devicep->dev);
+ devicep->bus_type = (unsigned int)id.bustype;
+ devicep->vendor = (unsigned int)id.vendor;
+ devicep->product = (unsigned int)id.product;
+ devicep->version = (unsigned int)id.version;
devicep->nbuttons = 0;
for (i = 0; i < KEY_CNT; i++) {