aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-27 16:14:23 +0200
committerMattias Andrée <maandree@kth.se>2022-07-27 18:03:37 +0200
commitaca2a514d4622b4b4a79efbab0cf649b6b6679a9 (patch)
treed5b51ff2f21a1f7117fd5217eedd6a4057c4e218
parentm + add controller fingerprint + relay less on libevdev (diff)
downloadlibgamepad-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>
-rw-r--r--Makefile4
-rw-r--r--libgamepad.h58
-rw-r--r--libgamepad_get_device_has_absolute_axis.c5
-rw-r--r--libgamepad_get_device_has_button.c5
-rw-r--r--libgamepad_get_device_has_ff_effect.c5
-rw-r--r--libgamepad_get_device_has_relative_axis.c5
6 files changed, 82 insertions, 0 deletions
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
@@ -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,
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);