diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-23 14:39:44 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-23 14:40:11 +0200 |
commit | d49393b339c47733c2eda207b8ba03d61db0a5a3 (patch) | |
tree | bc609622c3cabe1dc6b59970cb8a9a8364a561a7 /test-details.c | |
download | libgamepad-d49393b339c47733c2eda207b8ba03d61db0a5a3.tar.gz libgamepad-d49393b339c47733c2eda207b8ba03d61db0a5a3.tar.bz2 libgamepad-d49393b339c47733c2eda207b8ba03d61db0a5a3.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test-details.c')
-rw-r--r-- | test-details.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/test-details.c b/test-details.c new file mode 100644 index 0000000..dfff98f --- /dev/null +++ b/test-details.c @@ -0,0 +1,101 @@ +/* See LICENSE file for copyright and license details. */ +#include "libgamepad.h" + +#include <assert.h> +#include <stdio.h> + +#define ELEMSOF(A) (sizeof(A) / sizeof(*(A))) + + +int +main(int argc, char *argv[]) +{ + const struct input_absinfo *absinfo; + struct libgamepad_device gamepad; + size_t i, n; + + if (argc != 2) { + fprintf(stderr, "Please provide the path to the subdevice as the only command line argument\n"); + return 1; + } + + if (libgamepad_open_device(&gamepad, AT_FDCWD, argv[1], O_RDONLY)) { + perror("libgamepad_open_device"); + return 1; + } + + printf("Bus type: %i\n", gamepad.bus_type); + printf("Vendor: %i\n", gamepad.vendor); + printf("Product: %i\n", gamepad.product); + printf("Version: %i\n", gamepad.version); + printf("Name: %s\n", gamepad.name); + printf("Unique id: %s\n", gamepad.unique_id); + printf("Physical location: %s\n", gamepad.physical_location); + + printf("Buttons:\n"); + for (i = 0; i < gamepad.nbuttons; i++) { + assert(gamepad.buttons); + assert(gamepad.buttons[i] < ELEMSOF(gamepad.button_map)); + assert(gamepad.button_map[gamepad.buttons[i]] == (int16_t)i); + printf("\t%s [pressed=%i]\n", + libgamepad_get_button_name(gamepad.buttons[i]), + libgamepad_get_button_is_pressed(&gamepad, (unsigned int)gamepad.buttons[i])); + } + n = 0; + for (i = 0; i < ELEMSOF(gamepad.button_map); i++) { + assert(gamepad.button_map[i] >= -1); + assert((ssize_t)gamepad.button_map[i] < (ssize_t)gamepad.nbuttons); + if (gamepad.button_map[i] != -1) { + assert(gamepad.buttons[gamepad.button_map[i]] == (uint16_t)i); + n++; + } + } + assert(n == gamepad.nbuttons); + + printf("Absolute axes:\n"); + for (i = 0; i < gamepad.nabsolute_axes; i++) { + assert(gamepad.absolute_axes); + assert(gamepad.absolute_axes[i] < ELEMSOF(gamepad.absolute_axis_map)); + assert(gamepad.absolute_axis_map[gamepad.absolute_axes[i]] == (int16_t)i); + absinfo = libgamepad_get_absolute_axis_info(&gamepad, gamepad.absolute_axes[i]); + if (!absinfo) { + printf("\t%s\n", libgamepad_get_absolute_axis_name(gamepad.absolute_axes[i])); + } else { + printf("\t%s [value=%i, min=%i, max=%i, fuzz=%i, flat=%i, resolution=%i]\n", + libgamepad_get_absolute_axis_name(gamepad.absolute_axes[i]), + absinfo->value, absinfo->minimum, absinfo->maximum, + absinfo->fuzz, absinfo->flat, absinfo->resolution); + } + } + n = 0; + for (i = 0; i < ELEMSOF(gamepad.absolute_axis_map); i++) { + assert(gamepad.absolute_axis_map[i] >= -1); + assert((ssize_t)gamepad.absolute_axis_map[i] < (ssize_t)gamepad.nabsolute_axes); + if (gamepad.absolute_axis_map[i] != -1) { + assert(gamepad.absolute_axes[gamepad.absolute_axis_map[i]] == (uint16_t)i); + n++; + } + } + assert(n == gamepad.nabsolute_axes); + + printf("Relative axes:\n"); + for (i = 0; i < gamepad.nrelative_axes; i++) { + assert(gamepad.relative_axes); + assert(gamepad.relative_axes[i] < ELEMSOF(gamepad.relative_axis_map)); + assert(gamepad.relative_axis_map[gamepad.relative_axes[i]] == (int16_t)i); + printf("\t%s\n", libgamepad_get_relative_axis_name(gamepad.relative_axes[i])); + } + n = 0; + for (i = 0; i < ELEMSOF(gamepad.relative_axis_map); i++) { + assert(gamepad.relative_axis_map[i] >= -1); + assert((ssize_t)gamepad.relative_axis_map[i] < (ssize_t)gamepad.nrelative_axes); + if (gamepad.relative_axis_map[i] != -1) { + assert(gamepad.relative_axes[gamepad.relative_axis_map[i]] == (uint16_t)i); + n++; + } + } + assert(n == gamepad.nrelative_axes); + + libgamepad_close_device(&gamepad); + return 0; +} |