aboutsummaryrefslogblamecommitdiffstats
path: root/test-details.c
blob: e8348196cf619975003c294aa0cd70f7bf3cf168 (plain) (tree)

























                                                                                                                



                                                   









                                                                             
                                                                            
                                                                                       


















                                                                                                
                                                                                                            

                                                                                                    
                                                                                                 



















                                                                                                   
                                                                                                    














                                                                                                   
/* 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: %u\n", gamepad.bus_type);
	printf("Vendor: %u\n", gamepad.vendor);
	printf("Product: %u\n", gamepad.product);
	printf("Version: %u\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(NULL, gamepad.buttons[i]),
		       libgamepad_get_button_is_pressed(&gamepad, 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(NULL, 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(NULL, 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(NULL, 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;
}