aboutsummaryrefslogtreecommitdiff
path: root/dial.py
diff options
context:
space:
mode:
Diffstat (limited to 'dial.py')
-rw-r--r--dial.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/dial.py b/dial.py
index d5117ff..fa5ca9e 100644
--- a/dial.py
+++ b/dial.py
@@ -10,12 +10,10 @@ REST_TIME = 0.3 # seconds
DIAL_RESET_TIME = 5 # seconds
class DialThread(threading.Thread):
- def __init__(self, queue, phone_held, processing_event):
+ def __init__(self, phone):
threading.Thread.__init__(self, args=(), kwargs=None)
- self.queue = queue
self.daemon = True
- self.phone_held = phone_held
- self.processing_event = processing_event
+ self.phone = phone
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
@@ -40,8 +38,8 @@ class DialThread(threading.Thread):
pressed = False
if self.dial_over(rest_start) and not printed:
# Only add this dial to queue if we should accept numbers at this time
- if self.phone_held.is_set() and not self.processing_event.is_set():
- self.queue.put(count % 10) # wrap 10 to 0
+ if self.phone.phone_held.is_set() and not self.phone.processing_event.is_set():
+ self.phone.queue.put(count % 10) # wrap 10 to 0
count = 0
printed = True
time.sleep(0.01)
@@ -52,23 +50,24 @@ class DialThread(threading.Thread):
class DialManager:
- def __init__(self, phone_held, phone_hung_up):
+ def __init__(self, phone):
self.sequence = []
+ self.phone = phone
self.update = datetime.now()
- self._load_sequences(phone_held, phone_hung_up)
+ self._load_sequences()
+ print(self.sequences)
- def _load_sequences(self, phone_held, phone_hung_up):
+ def _load_sequences(self):
def recursive_add(classname, sequence_list, sequences, args):
key = int(sequence_list[0])
if not sequence_list[1:]:
- sequences[key] = eval(classname)(self, phone_held, phone_hung_up, args)
+ sequences[key] = eval(classname)(self.phone, args)
else:
- sequences[key] = {}
+ sequences[key] = sequences[key] if key in sequences and isinstance(sequences[key], dict) else {}
recursive_add(classname, sequence_list[1:], sequences[key], args)
self.sequences = {}
for sequence in config["sequences"]:
- print(sequence, config["sequences"][sequence], sep="\t")
parts = config["sequences"][sequence].split(" ", 1)
classname = parts[0]
args = parts[1:]