[a32498]: / python / hid_info.py

Download this file

60 lines (45 with data), 1.8 kB

 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
import platform
import sys
if sys.version_info >= (3, 0): # pragma: no cover
unicode = str
system_platform = platform.system()
if system_platform == "Windows":
import pywinusb.hid as hidapi
else:
import hidapi
hidapi.hid_init()
def hid_enumerate_nix():
return hidapi.hid_enumerate()
def hid_enumerate_win():
return hidapi.find_all_hid_devices()
def print_hid_enumerate(platform):
"""
Loops over all devices in the hidapi and attempts prints information.
This is a fall back method that gives the user information to give the developers when opening an issue.
"""
devices = get_hid_devices[platform]()
for device in devices:
print("-------------------------")
for key, value in device.__dict__.items():
print("%s, %s" % (key, unicode(value)))
# if not sys.version_info >= (3, 0):
# if type(value) == unicode or type(value) == str:
# print("%s, %s" % (key, value.encode(locale.getpreferredencoding())))
# else:
# print("%s, %s" % (key, str(value)))
# else:
# if type(value) == unicode:
# print("%s, %s" % (key, value.encode(locale.getpreferredencoding())))
# else:
# print("%s, %s" % (key, unicode(value)))
print("************************************************************")
print("! Please include this information if you open a new issue. !")
print("************************************************************")
get_hid_devices = {
'Darwin': hid_enumerate_nix,
'Linux': hid_enumerate_nix,
'Windows': hid_enumerate_win
}
print(sys.version_info)
print(system_platform)
print_hid_enumerate(system_platform)