-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearncodes.py~
28 lines (28 loc) · 1017 Bytes
/
learncodes.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
#!/usr/bin/python
import serial
import simplejson
ser = serial.Serial('/dev/ttyUSB0', 115200)
mykeys = {}
lastkey = ()
usedkeys = ['KEY_UP','KEY_DOWN','KEY_LEFT','KEY_RIGHT','KEY_OK','KEY_ESC','KEY_INFO',
'KEY_MENU','KEY_PLAY','KEY_PAUSE','KEY_FASTFORWARD','KEY_NEXT','KEY_REWIND','KEY_BACK',
'KEY_POWER2','KEY_STOP','KEY_1','KEY_2','KEY_3','KEY_4','KEY_5','KEY_6','KEY_7','KEY_8',
'KEY_9','KEY_0','KEY_RED','KEY_GREEN','KEY_YELLOW','KEY_BLUE','KEY_SCREEN','KEY_SUBTITLE',
'KEY_EPG','KEY_PVR','KEY_CHANNEL','KEY_MODE','KEY_TIME','KEY_FN']
for key in usedkeys:
print "please press", key
while 1:
line = ser.readline()
try:
p,a,c,n = line.split()
if lastkey != (p,a,c):
mykeys["%s_%s_%s"%(p,a[2:],int(c[2:], 16))] = key
lastkey = (p,a,c)
break
except:
pass
keyjson = simplejson.JSONEncoder().encode(mykeys)
with open("keymap.json","w") as mykeytable:
mykeytable.writelines(keyjson)
print mykeys
ser.close()