aboutsummaryrefslogtreecommitdiffstats
path: root/test-details.c
blob: dfff98ffa6f761374a3b55a1c6db113d3953eb88 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
}