forked from Yanndroid/SiriRemote-Linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (60 loc) · 2.02 KB
/
main.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
import sys
from remote.remote import SiriRemote, RemoteListener
from hid_input import Input
hid_input = Input()
class Callback(RemoteListener):
def event_battery(self, percent: int):
print("Battery", percent)
def event_power(self, charging: bool):
print("Charging", charging)
def event_button(self, button: int):
handle_button_event(button)
def event_touchpad(self, data, pressed: bool):
if len(data) == 2 and data[0][2] == 0: # "ghost" finger with pressure 0
handle_touchpad_event(data[1])
else:
handle_touchpad_event(data[0])
prevXY = [None, None]
def handle_touchpad_event(data):
sensi = 8
x = data[0] * sensi
y = data[1] * - sensi
p = data[2]
if prevXY[0] and prevXY[1]:
hid_input.move_cursor(x - prevXY[0], y - prevXY[1])
if p == 0:
prevXY[0] = prevXY[1] = None
else:
prevXY[0] = x
prevXY[1] = y
def handle_button_event(button):
if button == SiriRemote.BUTTON_RELEASED:
hid_input.release()
return
if button & SiriRemote.BUTTON_AIRPLAY:
hid_input.add_key(Input.KEY_NEXTSONG)
if button & SiriRemote.BUTTON_VOLUME_UP:
hid_input.add_key(Input.KEY_VOLUMEUP)
if button & SiriRemote.BUTTON_VOLUME_DOWN:
hid_input.add_key(Input.KEY_VOLUMEDOWN)
if button & SiriRemote.BUTTON_PLAY_PAUSE:
hid_input.add_key(Input.KEY_PLAYPAUSE)
# if button & SiriRemote.BUTTON_SIRI:
# print("Siri")
if button & SiriRemote.BUTTON_MENU:
hid_input.add_key(Input.KEY_PREVIOUSSONG)
if button & SiriRemote.BUTTON_TOUCHPAD_2:
hid_input.add_key(Input.BTN_RIGHT)
if button & SiriRemote.BUTTON_TOUCHPAD:
hid_input.add_key(Input.BTN_LEFT)
hid_input.press()
if __name__ == '__main__':
try:
if len(sys.argv) > 1:
mac = sys.argv[1]
SiriRemote(mac, Callback())
else:
print("error: no mac address")
except KeyboardInterrupt:
hid_input.close()
exit()