-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpi_phone.py
More file actions
77 lines (63 loc) · 2.34 KB
/
pi_phone.py
File metadata and controls
77 lines (63 loc) · 2.34 KB
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
from pi_hardware import pi_hardware
from pi_modem import pi_modem
class pi_phone:
def __init__(self, hardware, modem, debugger):
self.debugger = debugger
self.hardware = hardware
self.modem = modem
def loop(self):
self.hardware.serial_flush()
if not self.modem.check_status():
self.power_on_modem()
self.modem.caller_id()
if self.hardware.hook_lifted():
self.debugger.out('Waiting on hook.')
while self.hardware.hook_lifted():
self.debugger.wait(0.4)
self.hardware.ring(0.5)
while True:
print('')
self.debugger.wait(0.1)
if self.modem.no_modem_response() and self.modem.allow_restart:
self.power_on_modem()
if self.hardware.hook_lifted():
self.make_call()
else:
self.receive_call()
def power_on_modem(self):
self.debugger.out("Initializing modem...")
while True:
self.debugger.wait(1.0)
self.modem.power_on()
self.debugger.wait(5.0)
if self.modem.check_status():
break
elif not self.modem.allow_restart:
self.debugger.out("Failed, but forcing start.")
break
else:
self.debugger.out("Failed, making new attempt.")
def make_call(self):
number = self.hardware.get_rotary()
if len(number) < 3 or not self.hardware.hook_lifted():
self.debugger.out("No number or hook returned!")
return
if not self.modem.check_status():
self.debugger.out("Failed to make call, modem off!")
return
self.modem.call(number)
while self.hardware.hook_lifted():
self.debugger.wait(0.5)
self.modem.hang_up()
def receive_call(self):
incoming = self.modem.check_incoming_call()
while incoming and not self.hardware.hook_lifted():
self.hardware.ring(1.0)
self.debugger.wait(0.05)
incoming = self.modem.check_incoming_call()
if incoming:
self.debugger.out('Receiving call')
self.modem.receive()
while self.hardware.hook_lifted():
self.debugger.wait(0.5)
self.modem.hang_up()