diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-26 16:01:13 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-26 16:02:05 +0200 |
commit | 9de0de4d3d32ab97226fa9868de1fa2290120429 (patch) | |
tree | 292473831841529716f97565391303fb9b071c15 /libgamepad.h | |
parent | Update information about Sixaxis (diff) | |
download | libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.gz libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.bz2 libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.xz |
Do not relay on libevdev for button/axis names, an prepare for device specific names, and add reverse lookup functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libgamepad.h')
-rw-r--r-- | libgamepad.h | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/libgamepad.h b/libgamepad.h index a6002fe..d039082 100644 --- a/libgamepad.h +++ b/libgamepad.h @@ -1503,65 +1503,86 @@ int libgamepad_next_event(struct libgamepad_device *, struct libgamepad_input_ev /** * Get the name of a button/key * - * @param code The button/key - * @return The button/key's name + * @param device If `NULL`, a generic name will be returned, + * otherwise the canonical name for the button/key + * on the specific device will be returned + * (`NULL` if not information is unavailable) + * @param code The button/key + * @return The button/key's name, `NULL` if not found */ -inline const char * -libgamepad_get_button_name(uint16_t code) -{ - return libevdev_event_code_get_name(EV_KEY, (unsigned int)code); -} +const char *libgamepad_get_button_name(const struct libgamepad_device *, uint16_t); /** * Get the name of an absolute axis * - * @param code The axis - * @return The axis' name + * @param device If `NULL`, a generic name will be returned, + * otherwise the canonical name for the axis + * on the specific device will be returned + * (`NULL` if not information is unavailable) + * @param code The axis + * @return The axis' name, `NULL` if not found */ -inline const char * -libgamepad_get_absolute_axis_name(uint16_t code) -{ - return libevdev_event_code_get_name(EV_ABS, (unsigned int)code); -} +const char *libgamepad_get_absolute_axis_name(const struct libgamepad_device *, uint16_t); /** * Get the name of a relative axis * - * @param code The axis - * @return The axis' name + * @param device If `NULL`, a generic name will be returned, + * otherwise the canonical name for the axis + * on the specific device will be returned + * (`NULL` if not information is unavailable) + * @param code The axis + * @return The axis' name, `NULL` if not found */ -inline const char * -libgamepad_get_relative_axis_name(uint16_t code) -{ - return libevdev_event_code_get_name(EV_REL, (unsigned int)code); -} +const char *libgamepad_get_relative_axis_name(const struct libgamepad_device *, uint16_t); + +/** + * Get a button/key code from it's name + * + * @param name The button/key's name or textual + * representation of its code number + * @return The button/key, -1 if not found + */ +int16_t libgamepad_get_button_by_name(const char *); + +/** + * Get a absolute axis code from it's name + * + * @param name The absolute axis' name or textual + * representation of its code number + * @return The absolute axis, -1 if not found + */ +int16_t libgamepad_get_absolute_axis_by_name(const char *); + +/** + * Get a relative axis code from it's name + * + * @param name The relative axis' name or textual + * representation of its code number + * @return The relative axis, -1 if not found + */ +int16_t libgamepad_get_relative_axis_by_name(const char *); + /** * Get whether a button/key is pressed down or not - * + * * @param device The device to retrieve the information for * @param code The button/key * @return 1 if the button/key is pressed down, * 0 otherwise */ -inline 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); -} +int libgamepad_get_button_is_pressed(struct libgamepad_device *, uint16_t); /** * Get information about an absolute axis - * + * * @param device The device to retrieve the information for * @param code The axis * @return Information about the axis */ -inline const struct input_absinfo * /* `struct input_absinfo` is defined in <linux/input.h> */ -libgamepad_get_absolute_axis_info(struct libgamepad_device *device, uint16_t code) -{ - return libevdev_get_abs_info(device->dev, (unsigned int)code); -} +const struct input_absinfo *libgamepad_get_absolute_axis_info(struct libgamepad_device *, uint16_t); +/* `struct input_absinfo` is defined in <linux/input.h> */ /** |