-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·98 lines (78 loc) · 2.05 KB
/
server.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
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import sys
from flask import Flask
HTTP_PORT = 5000
SERIAL_PORT = '/dev/ttyACM0'
def send(command):
print 'sending:', command
parts = command.split('/')
if len(parts) != 2:
return 'invalid command: ' + command
component, cmd = parts
if component not in CODES:
return 'unknown component: ' + component
if cmd not in CODES[component]:
return 'unknown command: ' + cmd
mode = MODES[component]
code = CODES[component][cmd]
f = open(SERIAL_PORT, 'wb')
f.write('{}\n{}\n'.format(mode, code))
answer = ''
for line in f:
if line.strip() == 'end':
break
answer += line + '\n'
f.close()
return answer
app = Flask(__name__)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def handle_command(path):
command = path.lstrip('/')
return send(command)
def main():
app.run(host='0.0.0.0', debug=True)
MODES = {
'tv': 'samsuung',
'preamp': 'rc5',
}
CODES = {
# Samsung UN32EH5300
'tv': {
'power': 'E0E040BF',
'up': 'E0E006F9',
'down': 'E0E08679',
'select': 'E0E016E9',
'source': 'E0E0807F',
'left': 'E0E0A659',
'right': 'E0E046B9',
'return': 'E0E01AE5',
'exit': 'E0E0B44B',
'tools': 'E0E0D22D',
'menu': 'E0E058A7',
'smart': 'E0E09E61',
'volup': 'E0E0E01F',
'voldown': 'E0E0D02F',
'mute': 'E0E0F00F',
'chup': 'E0E048B7',
'chdown': 'E0E008F7',
},
# Emotiva XDA-2
'preamp': {
'on': '60FF11EE',
'off': '60FF916E',
'mute': '60FFA15E',
'dim': '60FF21DE',
'up': '60FF936C',
'down': '60FFA35C',
'usb': '60FF13EC',
'aes': '60FF619E',
'opt1': '60FF51AE',
'opt2': '60FFD12E',
'coaxial1': '60FF23DC',
'coaxial2': '60FFE11E',
'src': '60FF639C',
},
}
if __name__ == '__main__':
main()