/
ir-remote.py
executable file
·79 lines (70 loc) · 2.41 KB
/
ir-remote.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
#! /usr/bin/env python
# Read the output of an Arduino which may be printing sensor output,
# and at the same time, monitor the user's input and send it to the Arduino.
# See also
# http://www.arcfn.com/2009/06/arduino-sheevaplug-cool-hardware.html
import sys, serial, select, subprocess, os
class Arduino() :
def run(self) :
# Port may vary, so look for it:
baseport = "/dev/ttyACM"
self.ser = None
for i in xrange(0, 9) :
try :
self.ser = serial.Serial(baseport + str(i), 115200, timeout=2)
break
except :
self.ser = None
pass
if not self.ser :
print "Couldn't open a serial port"
sys.exit(1)
print "Opened /dev/ttyUSB" + str(i)
self.ser.flushInput()
while True :
inp, outp, err = select.select([sys.stdin, self.ser], [], [], .2)
# If the user has typed anything, send it to the Arduino:
if sys.stdin in inp :
line = sys.stdin.readline()
self.ser.write(line)
# If the Arduino has printed anything, display it:
if self.ser in inp :
line = self.ser.readline().strip()
print "Arduino:", line
if line == "M":
os.system('quodlibet --play-pause')
os.system('echo -n "pause" | nc -U /home/media/vlc.sock')
if line == "N":
os.system('quodlibet --next')
os.system('echo -n "key key-jump+medium" | nc -U /home/media/vlc.sock')
if line == "P":
os.system('quodlibet --previous')
os.system('echo -n "key key-jump-medium" | nc -U /home/media/vlc.sock')
if line == "u":
os.system('quodlibet --volume-up')
os.system('echo -n "volup 2" | nc -U /home/media/vlc.sock')
if line == "d":
os.system('quodlibet --volume-down')
os.system('echo -n "voldown 2" | nc -U /home/media/vlc.sock')
if line == "U":
os.system('amixer set PCM 10%+ -c 1')
if line == "D":
os.system('amixer set PCM 10%- -c 1')
if line == "q":
os.system('quodlibet --quit')
os.system('echo -n "quit" | nc -U /home/media/vlc.sock')
if line == "f":
os.system('echo -n "f" | nc -U /home/media/vlc.sock')
if line == "s":
os.system('quodlibet &')
if line == "b":
os.system('echo -n "key key-jump-extrashort" | nc -U /home/media/vlc.sock')
arduino = Arduino()
try :
arduino.run()
except serial.SerialException :
print "Disconnected (Serial exception)"
except IOError :
print "Disconnected (I/O Error)"
except KeyboardInterrupt :
print "Interrupt"