diff options
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | common.h | 7 | ||||
-rw-r--r-- | libgamepad.h | 23 | ||||
-rw-r--r-- | libgamepad_close_device.c | 14 | ||||
-rw-r--r-- | libgamepad_get_absolute_axis_info.c | 2 | ||||
-rw-r--r-- | libgamepad_get_button_is_pressed.c | 2 | ||||
-rw-r--r-- | libgamepad_next_event.c | 12 | ||||
-rw-r--r-- | libgamepad_open_device.c | 40 |
8 files changed, 51 insertions, 52 deletions
@@ -1,4 +1,5 @@ -Add support for profiles (conformation, button names/shapes/colours, controller layout images) +Add userspace driver for Sixaxis/DualShock 3 +Add support for profiles (conformation, button names/icons/colours, controller layout images) Add support for quirks Add support for leds Add support for accelerometer and gyroscope @@ -30,6 +30,13 @@ struct libgamepad_attachment_monitor { }; +struct libgamepad_device_internals { + int close_fd; + int require_sync; + struct libevdev *dev; +}; + + extern const char *libgamepad_button_names__[ #include "button.count" ]; diff --git a/libgamepad.h b/libgamepad.h index d039082..404e526 100644 --- a/libgamepad.h +++ b/libgamepad.h @@ -20,6 +20,11 @@ */ typedef struct libgamepad_attachment_monitor LIBGAMEPAD_ATTACHMENT_MONITOR; +/** + * Opaque structure for internal data in `struct libgamepad_device` + */ +typedef struct libgamepad_device_internals LIBGAMEPAD_DEVICE_INTERNALS; + /** * Device attachment event type @@ -1259,18 +1264,9 @@ struct libgamepad_device { unsigned int version; /** - * FOR INTERNAL USE - * - * Specifies whether `.fd` shall be closed with the device + * Data for internal use */ - int close_fd; - - /** - * FOR INTERNAL USE - * - * Whether the device must be synchronised - */ - int require_sync; + LIBGAMEPAD_DEVICE_INTERNALS *internals; /** * Human-readable device (sub- or superdevice) name @@ -1289,11 +1285,6 @@ struct libgamepad_device { const char *physical_location; /** - * libevdev instance for the device - */ - struct libevdev *dev; - - /** * Number of (digital) buttons/keys present * on the device */ diff --git a/libgamepad_close_device.c b/libgamepad_close_device.c index edb8361..3b00149 100644 --- a/libgamepad_close_device.c +++ b/libgamepad_close_device.c @@ -6,15 +6,17 @@ void libgamepad_close_device(struct libgamepad_device *device) { if (device) { - if (device->close_fd) - close(device->fd); - if (device->dev) - libevdev_free(device->dev); + if (device->internals) { + if (device->internals->close_fd) + close(device->fd); + if (device->internals->dev) + libevdev_free(device->internals->dev); + free(device->internals); + device->internals = NULL; + } free(device->buttons); free(device->absolute_axes); free(device->relative_axes); - device->close_fd = 0; - device->dev = NULL; device->buttons = NULL; device->absolute_axes = NULL; device->relative_axes = NULL; diff --git a/libgamepad_get_absolute_axis_info.c b/libgamepad_get_absolute_axis_info.c index 307d85a..a5aa4d5 100644 --- a/libgamepad_get_absolute_axis_info.c +++ b/libgamepad_get_absolute_axis_info.c @@ -5,5 +5,5 @@ const struct input_absinfo * libgamepad_get_absolute_axis_info(struct libgamepad_device *device, uint16_t code) { - return libevdev_get_abs_info(device->dev, (unsigned int)code); + return libevdev_get_abs_info(device->internals->dev, (unsigned int)code); } diff --git a/libgamepad_get_button_is_pressed.c b/libgamepad_get_button_is_pressed.c index 2e61297..e3c0265 100644 --- a/libgamepad_get_button_is_pressed.c +++ b/libgamepad_get_button_is_pressed.c @@ -5,5 +5,5 @@ int libgamepad_get_button_is_pressed(struct libgamepad_device *device, uint16_t code) { - return libevdev_get_event_value(device->dev, EV_KEY, (unsigned int)code); + return libevdev_get_event_value(device->internals->dev, EV_KEY, (unsigned int)code); } diff --git a/libgamepad_next_event.c b/libgamepad_next_event.c index acc23ea..c74d641 100644 --- a/libgamepad_next_event.c +++ b/libgamepad_next_event.c @@ -8,23 +8,23 @@ libgamepad_next_event(struct libgamepad_device *device, struct libgamepad_input_ int r; struct input_event ev; - if (!device->require_sync) { - r = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); + if (!device->internals->require_sync) { + r = libevdev_next_event(device->internals->dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (r < 0) { errno = -r; return -1; } } else { - r = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_SYNC, &ev); + r = libevdev_next_event(device->internals->dev, LIBEVDEV_READ_FLAG_SYNC, &ev); if (r == -EAGAIN) { - device->require_sync = 0; /* yes, this is how it is document */ + device->internals->require_sync = 0; /* yes, this is how it is document */ return 0; } else if (r < 0) { errno = -r; return -1; } if (r != LIBEVDEV_READ_STATUS_SYNC) /* just to be safe */ - device->require_sync = 0; + device->internals->require_sync = 0; } eventp->sync_event = (r == LIBEVDEV_READ_STATUS_SYNC); @@ -48,7 +48,7 @@ libgamepad_next_event(struct libgamepad_device *device, struct libgamepad_input_ case EV_SYN: if (ev.code == SYN_DROPPED) - device->require_sync = 1; + device->internals->require_sync = 1; return 0; default: diff --git a/libgamepad_open_device.c b/libgamepad_open_device.c index cce0133..3c2a751 100644 --- a/libgamepad_open_device.c +++ b/libgamepad_open_device.c @@ -11,42 +11,40 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char struct input_id id; devicep->fd = dirfd; - devicep->close_fd = 0; - devicep->require_sync = 0; - devicep->dev = NULL; + devicep->internals = NULL; devicep->buttons = NULL; devicep->absolute_axes = NULL; devicep->relative_axes = NULL; memset(devicep->force_feedback_support, 0, sizeof(devicep->force_feedback_support)); + devicep->internals = calloc(1, sizeof(*devicep->internals)); + if (!devicep->internals) + return -1; + if (path && *path) { devicep->fd = openat(dirfd, path, mode); - if (devicep->fd < 0) + if (devicep->fd < 0) { + libgamepad_close_device(devicep); return -1; - devicep->close_fd = 1; + } + devicep->internals->close_fd = 1; } if (ioctl(devicep->fd, EVIOCGID, &id)) { - if (devicep->close_fd) { - close(devicep->fd); - devicep->close_fd = 0; - } + libgamepad_close_device(devicep); return -1; } - err = libevdev_new_from_fd(devicep->fd, &devicep->dev); + err = libevdev_new_from_fd(devicep->fd, &devicep->internals->dev); if (err < 0) { - if (devicep->close_fd) { - close(devicep->fd); - devicep->close_fd = 0; - } + libgamepad_close_device(devicep); 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->name = libevdev_get_name(devicep->internals->dev); + devicep->unique_id = libevdev_get_uniq(devicep->internals->dev); + devicep->physical_location = libevdev_get_phys(devicep->internals->dev); devicep->bus_type = (unsigned int)id.bustype; devicep->vendor = (unsigned int)id.vendor; devicep->product = (unsigned int)id.product; @@ -55,26 +53,26 @@ libgamepad_open_device(struct libgamepad_device *devicep, int dirfd, const char devicep->nbuttons = 0; for (i = 0; i < KEY_CNT; i++) { devicep->button_map[i] = -1; - if (libevdev_has_event_code(devicep->dev, EV_KEY, i)) + if (libevdev_has_event_code(devicep->internals->dev, EV_KEY, i)) devicep->button_map[i] = (int16_t)devicep->nbuttons++; } devicep->nabsolute_axes = 0; for (i = 0; i < ABS_CNT; i++) { devicep->absolute_axis_map[i] = -1; - if (libevdev_has_event_code(devicep->dev, EV_ABS, i)) + if (libevdev_has_event_code(devicep->internals->dev, EV_ABS, i)) devicep->absolute_axis_map[i] = (int16_t)devicep->nabsolute_axes++; } devicep->nrelative_axes = 0; for (i = 0; i < REL_CNT; i++) { devicep->relative_axis_map[i] = -1; - if (libevdev_has_event_code(devicep->dev, EV_REL, i)) + if (libevdev_has_event_code(devicep->internals->dev, EV_REL, i)) devicep->relative_axis_map[i] = (int16_t)devicep->nrelative_axes++; } for (i = 0; i < FF_CNT; i++) - if (libevdev_has_event_code(devicep->dev, EV_FF, i)) + if (libevdev_has_event_code(devicep->internals->dev, EV_FF, i)) devicep->force_feedback_support[i / 8] |= (uint8_t)(1 << (i & 7)); if (devicep->nbuttons) { |