diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-27 16:14:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-27 18:03:37 +0200 |
commit | aca2a514d4622b4b4a79efbab0cf649b6b6679a9 (patch) | |
tree | d5b51ff2f21a1f7117fd5217eedd6a4057c4e218 /libgamepad.h | |
parent | m + add controller fingerprint + relay less on libevdev (diff) | |
download | libgamepad-aca2a514d4622b4b4a79efbab0cf649b6b6679a9.tar.gz libgamepad-aca2a514d4622b4b4a79efbab0cf649b6b6679a9.tar.bz2 libgamepad-aca2a514d4622b4b4a79efbab0cf649b6b6679a9.tar.xz |
Add inline functions for testing support
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libgamepad.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libgamepad.h b/libgamepad.h index e7abd6a..5cee653 100644 --- a/libgamepad.h +++ b/libgamepad.h @@ -1806,6 +1806,64 @@ int16_t libgamepad_get_relative_axis_by_name(const char *); /** + * Get whether a device has a specific button or key + * + * @param device The device + * @param code The button/key + * @return 1 if the button/key is reported as present, 0 otherwise + */ +inline int +libgamepad_get_device_has_button(const struct libgamepad_device *device, uint16_t code) +{ + return code < sizeof(device->button_map) / sizeof(*device->button_map) && + device->button_map[code] >= 0; +} + +/** + * Get whether a device has a specific absolute axis + * + * @param device The device + * @param code The axis + * @return 1 if the axis is reported as present, 0 otherwise + */ +inline int +libgamepad_get_device_has_absolute_axis(const struct libgamepad_device *device, uint16_t code) +{ + return code < sizeof(device->absolute_axis_map) / sizeof(*device->absolute_axis_map) && + device->absolute_axis_map[code] >= 0; +} + +/** + * Get whether a device has a specific relative axis + * + * @param device The device + * @param code The axis + * @return 1 if the axis is reported as present, 0 otherwise + */ +inline int +libgamepad_get_device_has_relative_axis(const struct libgamepad_device *device, uint16_t code) +{ + return code < sizeof(device->relative_axis_map) / sizeof(*device->relative_axis_map) && + device->relative_axis_map[code] >= 0; +} + +/** + * Get whether a device has a specific force feedback effect + * + * @param device The device + * @param code The force feedback effect or waveform + * @return 1 if the axis is reported as present, 0 otherwise + */ +inline int +libgamepad_get_device_has_ff_effect(const struct libgamepad_device *device, uint16_t code) +{ + return code < sizeof(device->force_feedback_support) * 8 && + (1 & (device->force_feedback_support[code / (8 * sizeof(*device->force_feedback_support))] >> + (code % (8 * sizeof(*device->force_feedback_support))))); +} + + +/** * Get whether a button/key is pressed down or not * * libgamepad caches the last read button/key state, |