|
a |
|
b/python/hid_info.py |
|
|
1 |
import platform |
|
|
2 |
import sys |
|
|
3 |
|
|
|
4 |
if sys.version_info >= (3, 0): # pragma: no cover |
|
|
5 |
unicode = str |
|
|
6 |
|
|
|
7 |
system_platform = platform.system() |
|
|
8 |
if system_platform == "Windows": |
|
|
9 |
import pywinusb.hid as hidapi |
|
|
10 |
else: |
|
|
11 |
import hidapi |
|
|
12 |
|
|
|
13 |
hidapi.hid_init() |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
def hid_enumerate_nix(): |
|
|
17 |
return hidapi.hid_enumerate() |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
def hid_enumerate_win(): |
|
|
21 |
return hidapi.find_all_hid_devices() |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
def print_hid_enumerate(platform): |
|
|
25 |
""" |
|
|
26 |
Loops over all devices in the hidapi and attempts prints information. |
|
|
27 |
|
|
|
28 |
This is a fall back method that gives the user information to give the developers when opening an issue. |
|
|
29 |
""" |
|
|
30 |
devices = get_hid_devices[platform]() |
|
|
31 |
for device in devices: |
|
|
32 |
print("-------------------------") |
|
|
33 |
for key, value in device.__dict__.items(): |
|
|
34 |
print("%s, %s" % (key, unicode(value))) |
|
|
35 |
# if not sys.version_info >= (3, 0): |
|
|
36 |
# if type(value) == unicode or type(value) == str: |
|
|
37 |
# print("%s, %s" % (key, value.encode(locale.getpreferredencoding()))) |
|
|
38 |
# else: |
|
|
39 |
# print("%s, %s" % (key, str(value))) |
|
|
40 |
# else: |
|
|
41 |
# if type(value) == unicode: |
|
|
42 |
# print("%s, %s" % (key, value.encode(locale.getpreferredencoding()))) |
|
|
43 |
# else: |
|
|
44 |
# print("%s, %s" % (key, unicode(value))) |
|
|
45 |
print("************************************************************") |
|
|
46 |
print("! Please include this information if you open a new issue. !") |
|
|
47 |
print("************************************************************") |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
get_hid_devices = { |
|
|
51 |
'Darwin': hid_enumerate_nix, |
|
|
52 |
'Linux': hid_enumerate_nix, |
|
|
53 |
'Windows': hid_enumerate_win |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
print(sys.version_info) |
|
|
57 |
print(system_platform) |
|
|
58 |
|
|
|
59 |
print_hid_enumerate(system_platform) |