aboutsummaryrefslogtreecommitdiffstats
path: root/libgamepad.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libgamepad.h58
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,