-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
78 lines (61 loc) · 2.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
###################################################
# FILE: main.py #
# AUTHOR: NotPike #
# Function: main() #
###################################################
## Logging
import logging
## Envirement Variables and log config
try:
from env import *
env = ENV()
logging.basicConfig(filename=env.LOGGING_FILE, level=env.LOGGING_LEVEL, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S')
except ImportError as error:
from env_example import *
env = ENV()
logging.basicConfig(filename=env.LOGGING_FILE, level=env.LOGGING_LEVEL, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S')
logging.critical("Missing env.py file. Please copy the env_example.py to env.py and update variables.")
exit()
## Utility Classes
from utils.DTMF import *
from utils.RX import *
from utils.TX import *
from ModuleController import *
def init():
global mc
global dtmf
global rx
mc = ModuleController(env)
dtmf = DTMF()
rx = RX()
def start():
logging.info('### Start ###')
lastNumber = "" # Debounce
pin = ""
loop = 0 # Timeout timer
maxLoop = 15 # Timeout limit
## MAIN LOOP
run = True
while(run):
if(loop >= maxLoop): # If timedout, clear pin reset timer
pin = ""
loop = 0
rx.recordAudio() # Record Audio, 0.4sec samples
number = dtmf.dtmfDecode() # Sample Audio find DTMF Number
if(str(number) != lastNumber): # Debounce
if(str(number) != "None"):
pin += str(number) # Concat Number to PIN
loop = 0 # Reset timeout
logging.info("PIN: " + pin)
# If PIN is valid or > 6
if(mc.select(pin) or len(pin) > 6):
pin = ""
else:
loop += 1
continue
lastNumber = str(number)
rx.killAudio() # Stop Audio Recording
logging.info('### Stop ###')
if __name__ == "__main__":
init()
start()