From aca2a514d4622b4b4a79efbab0cf649b6b6679a9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 27 Jul 2022 16:14:23 +0200 Subject: Add inline functions for testing support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamepad.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'libgamepad.h') diff --git a/libgamepad.h b/libgamepad.h index e7abd6a..5cee653 100644 --- a/libgamepad.h +++ b/libgamepad.h @@ -1805,6 +1805,64 @@ int16_t libgamepad_get_absolute_axis_by_name(const char *); 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 * -- cgit v1.2.3-70-g09d2