diff options
author | Mark Powers <mark@marks.kitchen> | 2021-07-12 02:00:54 +0100 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-07-12 02:00:54 +0100 |
commit | 1edb32ec29ca3c1bf4d1a53215ecb2544aa04a6e (patch) | |
tree | d770c0f3dd74dab11a5b13c54f37b14c81daa990 /main.py | |
parent | a981a50b0597498a9fc92249f93f940998455ca3 (diff) |
Refactor code to support phone hangup button
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -1,24 +1,36 @@ #!/usr/bin/env python3 from dial import DialManager, DialThread -from phone import PhoneManager +from hangup import HangUpThread from time import sleep from queue import Queue +from threading import Event if __name__ == "__main__": queue = Queue() - dial_thread = DialThread(queue) - print("starting thread") - dial_thread.start() + phone_held = Event() + + # start phone as on hook + phone_held.clear() + dial_thread = DialThread(queue, phone_held) + print("starting dial thread") + dial_thread.start() dial_manager = DialManager() - phone_manager = PhoneManager() + + hang_up_thread = HangUpThread(phone_held, dial_manager) + print("starting hang up thread") + hang_up_thread.start() print("main loop") while True: - dialed = queue.get(block=True) + phone_held.wait() + try: + dialed = queue.get(block=True, timeout=0.1) + except: + continue response = dial_manager.dial(dialed) if response is not None: - phone_manager.handle_event(response) + response.speak() |