-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairemote.py
executable file
·83 lines (70 loc) · 2.21 KB
/
airemote.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
#!/usr/bin/python
import usb
import virtkey
from sys import exit
class KeyMapper():
def __init__(self):
self.map_dic = {}
self.map_dic2 = {}
self.v = virtkey.virtkey()
def map(self, remotenr, keycode):
self.map_dic[remotenr] = keycode
def execute(self, remotenr):
try:
self.v.press_keycode(self.map_dic[remotenr])
self.v.release_keycode(self.map_dic[remotenr])
except KeyError:
print str(remotenr)+' (not mapped)'
#what busses are availible?
busses = usb.busses()
ai = None
#we only need the ASUS Ai Remote
while not ai:
for bus in busses:
for dev in bus.devices:
if dev.idVendor == 0x0b05 and dev.idProduct == 0x172e:
print 'ASUS Ai Remote found.'
ai = dev
#if the remote isn't found - exit
if not ai:
print 'No Device found!'
exit()
#If we want our RC to to something, we should map its keys.
mapper = KeyMapper()
mapper.map(4,121) #Mute
mapper.map(7,123) #VolumeUp
mapper.map(8,173) #Previous
mapper.map(9,172) #Play/Pause
mapper.map(10,171) #Next
mapper.map(11,122) #VolumeDown
mapper.map(1,124) #Shutdown
#we're still there so we open the device
handler = ai.open()
#we know that there is only one confoguration
conf = ai.configurations[0]
#only one interface
iface = conf.interfaces[0][0]
#only one endpoint
endp = iface.endpoints[0]
#we don't want the kernel to handle this device
try:
handler.detachKernelDriver(iface)
except usb.USBError, e:
print e.args[0]
if e.args != ('could not detach kernel driver from interface 0: No data available',):
raise e
#the try...except statement in the next loop is due to a pyusb bug, that raises
#an error ('USBError: no error') where there is none.
while True:
data = None
try:
data = handler.interruptRead(endp.address, endp.maxPacketSize,10)
except usb.USBError, e:
if e.args != ('No error',) and e.args != ('could not detach kernel driver from interface 0: No data available',): # http://bugs.debian.org/476796
raise e
#if data:
# print data
if data[1] != 0:
mapper.execute(data[1])
#if data[1] == 4:
# break