From c72abd79e4dbfd9b533d75bb00fea1ded9975d95 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 12 Jul 2021 03:15:06 +0100 Subject: Add config, weather event, and demo timer event demoing hang up event --- dial.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'dial.py') diff --git a/dial.py b/dial.py index 1d08a05..0d14a32 100644 --- a/dial.py +++ b/dial.py @@ -2,7 +2,6 @@ from datetime import datetime, timedelta import time import RPi.GPIO as GPIO import threading - import events BUTTON_GPIO = 25 @@ -10,10 +9,9 @@ REST_TIME = 0.3 # seconds DIAL_RESET_TIME = 5 # seconds class DialThread(threading.Thread): - def __init__(self, queue, pressed): + def __init__(self, queue): threading.Thread.__init__(self, args=(), kwargs=None) self.queue = queue - self.pressed = pressed self.daemon = True GPIO.setmode(GPIO.BCM) @@ -44,20 +42,23 @@ class DialThread(threading.Thread): time.sleep(0.01) def dial_over(self, rest_start): + # After REST_TIME seconds, assume the rotary dial stopped spinning return datetime.now() - rest_start > timedelta(seconds=REST_TIME) class DialManager: - def __init__(self): + def __init__(self, phone_held, phone_hung_up): self.sequence = [] self.update = datetime.now() - self._load_sequences() + self._load_sequences(phone_held, phone_hung_up) - def _load_sequences(self): + def _load_sequences(self, phone_held, phone_hung_up): self.sequences = { - 0: events.OperatorEvent(self), - 4: {1: {1: events.DirectoryEvent(self)}}, - 7: events.FortuneEvent(self), + 0: events.OperatorEvent(self, phone_held, phone_hung_up), + 1: events.WeatherEvent(self, phone_held, phone_hung_up), + 2: events.TimerEvent(self, phone_held, phone_hung_up), + 4: {1: {1: events.DirectoryEvent(self, phone_held, phone_hung_up)}}, + 7: events.FortuneEvent(self, phone_held, phone_hung_up), } print(self.sequences) -- cgit v1.2.3