From 1edb32ec29ca3c1bf4d1a53215ecb2544aa04a6e Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 12 Jul 2021 02:00:54 +0100 Subject: Refactor code to support phone hangup button --- main.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index ec3d0b6..ef51809 100755 --- a/main.py +++ b/main.py @@ -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() -- cgit v1.2.3