-
Notifications
You must be signed in to change notification settings - Fork 23
/
music_control.py
executable file
·100 lines (96 loc) · 2.06 KB
/
music_control.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
99
100
#!/usr/bin/env python
import eZ430, dbus, time, math
#Rhythmbox dbus
session_bus = dbus.SessionBus()
proxy_obj = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
player = dbus.Interface(proxy_obj, 'org.gnome.Rhythmbox.Player')
#Wireless link init
watch = eZ430.watch()
#Variables
#link=0
#pd=0
r=0
l=0
down=0
up=0
playing=0
paused=0
downmillies=int(round(time.time()*1000))
upmillies=int(round(time.time()*1000))
x=0
y=0
z=0
#Gestures
def raised():
print "Gesture detected!"
print "Name:\tHeld up"
print "Bind:\tToggle Play/Pause\n"
playing!=playing
player.playPause(playing)
def pronate():
print "Gesture detected!"
print "Name:\tPronate"
print "Bind:\tVolume +1%\n"
player.setVolumeRelative(0.01)
def supanate():
print "Gesture detected!"
print "Name:\tSupanate"
print "Bind:\tVolume -1%\n"
player.setVolumeRelative(-0.01)
def swing_down():
print "Gesture detected!"
print "Name:\tSwing down"
print "Bind:\tNext track\n"
player.next()
#def clear():
# down=0
# l=0
# r=0
while 1:
data = watch.read()
acc={'x':ord(data[0]), 'y':ord(data[1]), 'z':ord(data[2])}
if acc['x']+acc['y']+acc['z']!=0:
x=(acc['x'] + x) /2
y=(acc['y'] + y) /2
z=(acc['z'] + z) /2
print "x: %s\ty:%s\tz:%s"%(acc['x'],acc['y'],acc['z'])
if (y>25) & (y<100) & (z>35):
down+=1
if (y<220) & (y>190) & (z>240) & (z<250):
up+=1
# volume, but only if hand not holding the head ;)
if (y>230) or (y<30):
if (x>20) & (x<=35):
r+=1;
elif (x>35) & (x<55):
r+=8 #strong tilt
elif (x<225) & (x>=205):
l+=1
elif (x<205) & (x>190):
l+=8 #strong tilt
else:
r=0
l=0
if (r>20):
pronate()
r=0
if (l>20):
supanate()
l=0
#down gesture unpaus OR next title
if (down>5) & (downmillies-int(round(time.time()*1000))<-2000):
downmillies=int(round(time.time()*1000))
down=0
up=0
if (paused==1):
paused=0
raised()
else:
swing_down()
#raise hand to pause, down gesture to unpause
if (up>5) & (paused==0) & (upmillies-int(round(time.time()*1000))<-2000):
paused=1
upmillies=int(round(time.time()*1000))
up=0
down=0
raised()