diff options
author | Mark Powers <mark@marks.kitchen> | 2021-08-15 04:52:18 +0100 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-08-15 04:52:18 +0100 |
commit | db747d54bece564ff881cda3e21e38b45c91f35e (patch) | |
tree | 55582958a39c48222d76022cc714d4aaf7875ab6 /main.py | |
parent | dc62736d843949a4f6a01cbd1af09c25a38673a9 (diff) |
Refactor some things
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 41 |
1 files changed, 6 insertions, 35 deletions
@@ -1,47 +1,18 @@ #!/usr/bin/env python3 -from dial import DialManager, DialThread -from hangup import HangUpThread - -from time import sleep -from queue import Queue -from threading import Event +from phone import Phone if __name__ == "__main__": - queue = Queue() - phone_held = Event() - phone_hung_up = Event() - processing_event = Event() - - # start phone as on hook - phone_held.clear() - phone_hung_up.set() - processing_event.clear() - - dial_thread = DialThread(queue, phone_held, processing_event) - dial_thread.start() - dial_manager = DialManager(phone_held, phone_hung_up) - - hang_up_thread = HangUpThread(phone_held, phone_hung_up, dial_manager) - hang_up_thread.start() - + phone = Phone.get_instance() print("Ready") while True: try: # Wait for phone to be picked up - phone_held.wait() + phone.wait_until_answered() # Dial a number - try: - dialed = queue.get(block=True, timeout=0.1) - except: - continue - response = dial_manager.dial(dialed) - # If we matched a sequence, play out event - if response is not None: - processing_event.set() - response.run() + phone.process_dial() except Exception as e: print(e) + raise e finally: - processing_event.clear() - + phone.clear_event() |