-
Notifications
You must be signed in to change notification settings - Fork 2
/
remote.py
executable file
·57 lines (47 loc) · 1.28 KB
/
remote.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
#!/usr/bin/env python3
import sys
from subprocess import Popen, PIPE
DEVICE_NAME = "PY"
BUTTON_RELEASE = 0b10000000
BUTTON_FOCUS = 0b01000000
BUTTON_TELE = 0b00100000
BUTTON_WIDE = 0b00010000
MODE_IMMEDIATE = 0b00001100
MODE_DELAY = 0b00000100
MODE_MOVIE = 0b00001000
device = sys.argv[1]
cmd = sys.argv[2]
if cmd != 'pair':
if cmd[0] == 'r':
button = BUTTON_RELEASE
elif cmd[0] == 'f':
button = BUTTON_FOCUS
elif cmd[0] == 't':
button = BUTTON_TELE
elif cmd[0] == 'w':
button = BUTTON_WIDE
else:
print("No command")
if cmd[1] == 'i':
mode = MODE_IMMEDIATE
elif cmd[1] == 'm':
mode = MODE_MOVIE
elif cmd[1] == 'd':
mode = MODE_DELAY
else:
print("No Mode")
p = Popen(['btgatt-client', '-d', device],
stdout=PIPE, stdin=PIPE, universal_newlines=True)
def wait_contain(s):
while True:
line = p.stdout.readline()
if s in line:
break
def write_value(*values):
p.stdin.write("write-value " + ' '.join(map(str, values)) + '\n')
p.stdin.flush()
wait_contain("Write successful")
wait_contain("GATT discovery procedures complete")
write_value(0xf504, 3, *map(ord, DEVICE_NAME))
if cmd != 'pair':
write_value(0xf506, button | mode)