aboutsummaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--TODO1
-rw-r--r--libgamepad.h8
-rw-r--r--libgamepad_open_device.c23
-rw-r--r--test-details.c8
4 files changed, 24 insertions, 16 deletions
diff --git a/TODO b/TODO
index c8bccdc..c0f54a0 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
Add support for quirks
-Add support for battery
Add support for leds
Add support for audio
Add support for accelerometer
diff --git a/libgamepad.h b/libgamepad.h
index 665e012..5b6c46c 100644
--- a/libgamepad.h
+++ b/libgamepad.h
@@ -190,22 +190,22 @@ struct libgamepad_device {
* Bus type the device is connect via, see BUS_-prefixed
* constants in <linux/input.h>
*/
- int bus_type;
+ unsigned int bus_type;
/**
* Vendor ID for the device (sub- or superdevice)
*/
- int vendor;
+ unsigned int vendor;
/**
* Product ID for the device (sub- or superdevice)
*/
- int product;
+ unsigned int product;
/**
* Product version ID for the device (sub- or superdevice)
*/
- int version;
+ unsigned int version;
/**
* FOR INTERNAL USE
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++) {
diff --git a/test-details.c b/test-details.c
index 6ccfbe6..420e007 100644
--- a/test-details.c
+++ b/test-details.c
@@ -24,10 +24,10 @@ main(int argc, char *argv[])
return 1;
}
- printf("Bus type: %i\n", gamepad.bus_type);
- printf("Vendor: %i\n", gamepad.vendor);
- printf("Product: %i\n", gamepad.product);
- printf("Version: %i\n", gamepad.version);
+ printf("Bus type: %u\n", gamepad.bus_type);
+ printf("Vendor: %u\n", gamepad.vendor);
+ printf("Product: %u\n", gamepad.product);
+ printf("Version: %u\n", gamepad.version);
printf("Name: %s\n", gamepad.name);
printf("Unique id: %s\n", gamepad.unique_id);
printf("Physical location: %s\n", gamepad.physical_location);