This repository has been archived by the owner on Aug 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_devices.c
58 lines (52 loc) · 1.77 KB
/
list_devices.c
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
/*
* rzctl(1) -- Razer mouse control utility
* Copyright (c) 2019 Angel <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <libusb-1.0/libusb.h>
#include "list_devices.h"
#include "util.h"
int list_devices(int verbose)
{
struct razer_device *devs;
int ndevs, i;
if (libusb_init(NULL) < 0) {
fprintf(stderr, PR_ERROR "could not initialize libusb\n");
return 1;
}
if (verbose)
libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
ndevs = razer_get_devices(&devs);
if (ndevs < 0) {
fprintf(stderr, PR_ERROR "could not get Razer devices\n");
return 1;
}
for (i = 0; i < ndevs; i++) {
if (razer_init(&devs[i]) < 0) {
fprintf(stderr,
PR_ERROR "could not initialize Razer device %04x:%04x: ",
devs[i].desc.idVendor, devs[i].desc.idProduct);
perror(NULL);
continue;
}
printf("%04x:%04x %s (%s)\n", devs[i].desc.idVendor, devs[i].desc.idProduct,
devs[i].s_product, devs[i].s_manufacturer);
razer_deinit(&devs[i]);
}
razer_free_devices(&devs);
libusb_exit(NULL);
return 0;
}