-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriver.py
87 lines (77 loc) · 1.72 KB
/
driver.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import usb.core
import usb.util
import time
import signal
def clear():
for i in range(0,99):
print()
def byeeeee(a,b):
clear()
print("""
ad8888
d8" ""
88
MM88MMM 88 8b,dPPYba,
88 88 88P' `"8a
88 88 88 88
88 88 88 88
88 88 88 88
""")
device.reset()
exit(0)
def map_dis(output):
keys = ''
if output[4] == 72:
keys = keys + 'B '
elif output[4] == 40:
keys = keys + 'A '
elif output[4] == 136:
keys = keys + 'Y '
elif output[4] == 24:
keys = keys + 'X '
elif output[4] == 0:
keys = keys + '↑ '
elif output[4] == 4:
keys = keys + '↓ '
elif output[4] == 2:
keys = keys + '→ '
elif output[4] == 6:
keys = keys + '← '
else:
pass
if output[5] == 1:
keys = keys + 'L1 '
elif output[5] == 4:
keys = keys + 'L2 '
elif output[5] == 2:
keys = keys + 'R1 '
elif output[5] == 8:
keys = keys + 'R2 '
elif output[5] == 16:
keys = keys + 'BACK'
elif output[5] == 32:
keys = keys + 'START'
elif output[5] == 128:
byeeeee(6,9)
else:
pass
keys = keys + ' || RIGHT : ({},{}) LEFT :({},{})'.format(output[0],output[1],output[2],output[3])
return keys
signal.signal(signal.SIGINT,byeeeee)
device = usb.core.find(idVendor=0x046d,idProduct=0xc218)
if device is None:
raise ValueError("No device connected.")
if device.is_kernel_driver_active(0):
print("Disabling kernel control")
device.detach_kernel_driver(0)
device.set_configuration()
print("success")
while True:
output = None
try:
output = device.read(0x81,8)
except:
pass
if output is not None:
print(map_dis(output))
time.sleep(0.01)