-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho_test.py
58 lines (45 loc) · 1.67 KB
/
echo_test.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
import tools
log = tools.logger('var/log/echo_test.log')
import subprocess, sys
from remote import SiriRemote, RemoteListener
import gestures
class Callback(RemoteListener):
def __init__(self):
self.motion_enabled = False
self.swipe_recognizer = gestures.SwipeRecognizer(self.swipe_callback)
def event_battery(self, remote, percent: int):
print("Battery", percent)
def event_power(self, remote, charging: bool):
print("Charging", charging)
def event_button(self, remote, button: int):
print(f"Button {button:04X}")
if button & remote.profile.buttons.PLAY_PAUSE:
if remote.has_motion():
self.motion_enabled = not self.motion_enabled
remote.enable_motion(self.motion_enabled)
def event_touches(self, remote, touches):
print(f"Touch {touches}")
self.swipe_recognizer.touches(remote, touches)
def event_motion(self, remote, motion):
print(f"Motion {motion}")
def event_audio(self, remote, data):
print("Audio", data)
def swipe_callback(self, recognizer, event):
if event.type & gestures.EventType.Detected:
s = ''
if event.x < 0:
s = 'LEFT'
elif event.x > 0:
s = 'RIGHT'
elif event.y > 0:
s = 'UP'
elif event.y < 0:
s = 'DOWN'
print(f'Gesture {s}')
if __name__ == '__main__':
if len(sys.argv) > 1:
mac = sys.argv[1]
subprocess.run(['/usr/bin/bluetoothctl', 'disconnect', mac], capture_output=True)
SiriRemote(mac, Callback())
else:
print("error: no mac address")