Skip to content

Commit c5194bf

Browse files
committed
mpd frontend
1 parent f3a9c38 commit c5194bf

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

scripts/pad_daemon.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess, os, time
4+
5+
TTY="/dev/ttyACM0"
6+
7+
cmd_map = {
8+
b'1': ['true'],
9+
b'2': ['mpc', 'volume', '+2'],
10+
b'3': ['true'],
11+
b'X': ['true'],
12+
13+
b'4': ['mpc', 'prev'],
14+
b'5': ['mpc', 'toggle'],
15+
b'6': ['mpc', 'next'],
16+
b'Y': ['true'],
17+
18+
b'7': ['true'],
19+
b'8': ['mpc', 'volume', '-2'],
20+
b'9': ['true'],
21+
b'Y': ['true'],
22+
23+
b'C': ['true'],
24+
b'0': ['true'],
25+
b'B': ['true'],
26+
b'W': ['true'],
27+
}
28+
29+
30+
def run_cmd(f, args):
31+
output = subprocess.check_output(args)
32+
lines = output.split(b'\n')
33+
if lines[1].startswith(b'[playing]'):
34+
f.write(b'P')
35+
else:
36+
f.write(b'O')
37+
f.flush()
38+
39+
def run():
40+
41+
try:
42+
subprocess.check_output(['stty', '-F', TTY, 'raw'])
43+
except subprocess.CalledProcessError:
44+
return
45+
46+
with open(TTY, 'r+b', buffering=0) as f:
47+
48+
run_cmd(f, ['mpc'])
49+
50+
c = None
51+
while c != b'':
52+
c = f.read(1)
53+
cmd = cmd_map.get(c, None)
54+
if cmd:
55+
run_cmd(f, cmd)
56+
57+
while True:
58+
run()
59+
time.sleep(1)
60+

0 commit comments

Comments
 (0)