-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpi.py
More file actions
71 lines (59 loc) · 2.35 KB
/
rpi.py
File metadata and controls
71 lines (59 loc) · 2.35 KB
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
from firebase import firebase
from time import sleep
import os
import signal
import sys
def update_vol_bal(balance, volume):
if balance == 'left':
os.popen('amixer sset Master 0%,' + str(volume) + '%')
elif balance == 'right':
os.popen('amixer sset Master ' + str(volume) + '%,0%')
# when ctrl+c is pressed kill the tmux session before exiting
def signal_handler(sig, frame):
os.popen('tmux kill-session -t SmartSoundSystem')
sys.exit(0)
#connecting to the firebase
firebase = firebase.FirebaseApplication("https://smart-sound-system.firebaseio.com/", None)
#open spotify
os.popen('tmux new-session -s SmartSoundSystem -d -n spotify tizonia --spotify-playlist "New"')
signal.signal(signal.SIGINT, signal_handler)
on = 1
volume = 100
balance = 'left'
while 1:
result = firebase.get('/Instructions', '')
if result != None:
#processing all available Instructions
for key, inst in result.items(): #for each command
firebase.delete('/Instructions', key)
print(inst)
if inst == 'ONOFF':
if on == 1:
os.popen('tmux kill-session -t SmartSoundSystem')
on=0
else:
os.popen('tmux new-session -s SmartSoundSystem -d -n spotify tizonia --spotify-playlist "New"')
on=1
elif inst == 'NEXT': #send n
os.popen('tmux send-keys -t spotify "n^M"')
update_vol_bal(balance, volume)
elif inst == 'PREV': #send p
os.popen('tmux send-keys -t spotify "p^M"')
update_vol_bal(balance, volume)
elif inst == 'PLAY': #send space
os.popen('tmux send-keys -t spotify " ^M"')
elif inst == 'UP': #send +
if volume <= 90:
volume = volume + 10
update_vol_bal(balance, volume)
elif inst == 'DOWN': #send -
if volume >= 10:
volume = volume - 10
update_vol_bal(balance, volume)
elif inst == 'LEFT': #change balance to left speaker
balance = 'left'
update_vol_bal(balance, volume)
elif inst == 'RIGHT': #change balance to right speaker
balance = 'right'
update_vol_bal(balance, volume)
sleep(2)