aboutsummaryrefslogtreecommitdiffstats
path: root/test-list.c
blob: 51ef13bece87b8ccfd8d041e697be3a55092cabe (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
/* See LICENSE file for copyright and license details. */
#include "libgamepad.h"

#include <stdio.h>
#include <stdlib.h>


int
main(void)
{
	char **devices;
	size_t ndevices, i, j, *sound_cards;
	ssize_t nsound_cards;
	struct libgamepad_superdevice device;

	if (libgamepad_list_superdevices(&devices, &ndevices)) {
		perror("libgamepad_list_superdevices");
		return 1;
	}

	for (i = 0; i < ndevices; i++) {
		if (libgamepad_open_superdevice(&device, devices[i])) {
			perror("libgamepad_open_superdevice");
			free(devices[i]);
			continue;
		}
		free(devices[i]);

		printf("%s\n", device.syspath);
		for (j = 0; j < device.ndevices; j++)
			printf("\t%s (%x)\n", device.devices[j]->path, device.devices[j]->type);
		for (j = 0; j < device.nleds; j++)
			printf("\t%s (LED)\n", device.leds[j]);
		for (j = 0; j < device.npower_supplies; j++)
			printf("\t%s (PSU)\n", device.power_supplies[j]);
		nsound_cards = libgamepad_find_sound_devices(device.syspath, &sound_cards);
		if (nsound_cards < 0) {
			perror("libgamepad_find_sound_devices");
		} else {
			for (j = 0; j < (size_t)nsound_cards; j++)
				printf("\t%zu (SND)\n", sound_cards[j]);
			free(sound_cards);
		}

		libgamepad_close_superdevice(&device);
	}

	free(devices);

	return 0;
}