forked from tingbot/tbprocessd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbbuttonsd.py
42 lines (32 loc) · 1.1 KB
/
tbbuttonsd.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
from __future__ import print_function
import subprocess, threading, signal
from tingbot.platform_specific.tingbot import register_button_callback
midleft_state = 'up'
midright_state = 'up'
home_event = threading.Event()
def button_callback(button_index, state):
global midleft_state, midright_state
if button_index == 1:
midleft_state = state
elif button_index == 2:
midright_state = state
if midleft_state == 'down' and midright_state == 'down':
home_event.set()
def respond_to_home_event():
while True:
home_event.wait()
print('Home combo detected')
subprocess.call(['tbopen', '/apps/home'])
home_event.clear()
def main():
register_button_callback(button_callback)
# got to keep the main thread free to respond ot signals e.g. SIGTERM
# Event.wait() will block signals until set so we push this to its own
# thread.
respond_thread = threading.Thread(target=respond_to_home_event)
respond_thread.daemon = True
respond_thread.start()
while True:
signal.pause()
if __name__ == '__main__':
main()