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 --- Makefile | 4 +++ libgamepad.h | 58 +++++++++++++++++++++++++++++++ libgamepad_get_device_has_absolute_axis.c | 5 +++ libgamepad_get_device_has_button.c | 5 +++ libgamepad_get_device_has_ff_effect.c | 5 +++ libgamepad_get_device_has_relative_axis.c | 5 +++ 6 files changed, 82 insertions(+) create mode 100644 libgamepad_get_device_has_absolute_axis.c create mode 100644 libgamepad_get_device_has_button.c create mode 100644 libgamepad_get_device_has_ff_effect.c create mode 100644 libgamepad_get_device_has_relative_axis.c diff --git a/Makefile b/Makefile index b177653..0ef9633 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,10 @@ OBJ =\ libgamepad_get_button_by_name.o\ libgamepad_get_button_is_pressed.o\ libgamepad_get_button_name.o\ + libgamepad_get_device_has_absolute_axis.o\ + libgamepad_get_device_has_button.o\ + libgamepad_get_device_has_ff_effect.o\ + libgamepad_get_device_has_relative_axis.o\ libgamepad_get_force_feedback_max_concurrency.o\ libgamepad_get_relative_axis_by_name.o\ libgamepad_get_relative_axis_name.o\ 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 * diff --git a/libgamepad_get_device_has_absolute_axis.c b/libgamepad_get_device_has_absolute_axis.c new file mode 100644 index 0000000..b53133f --- /dev/null +++ b/libgamepad_get_device_has_absolute_axis.c @@ -0,0 +1,5 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +extern inline int libgamepad_get_device_has_absolute_axis(const struct libgamepad_device *, uint16_t); diff --git a/libgamepad_get_device_has_button.c b/libgamepad_get_device_has_button.c new file mode 100644 index 0000000..803c8b6 --- /dev/null +++ b/libgamepad_get_device_has_button.c @@ -0,0 +1,5 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +extern inline int libgamepad_get_device_has_button(const struct libgamepad_device *, uint16_t); diff --git a/libgamepad_get_device_has_ff_effect.c b/libgamepad_get_device_has_ff_effect.c new file mode 100644 index 0000000..41cc174 --- /dev/null +++ b/libgamepad_get_device_has_ff_effect.c @@ -0,0 +1,5 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +extern inline int libgamepad_get_device_has_ff_effect(const struct libgamepad_device *, uint16_t); diff --git a/libgamepad_get_device_has_relative_axis.c b/libgamepad_get_device_has_relative_axis.c new file mode 100644 index 0000000..94bddda --- /dev/null +++ b/libgamepad_get_device_has_relative_axis.c @@ -0,0 +1,5 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +extern inline int libgamepad_get_device_has_relative_axis(const struct libgamepad_device *, uint16_t); -- cgit v1.2.3-70-g09d2