-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhallowphone.py
170 lines (132 loc) · 4.49 KB
/
hallowphone.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
print("Hello world!")
import os
os.add_dll_directory(r'C:\Program Files\VideoLAN\VLC')
from time import sleep
from gpiozero import Button, LED
import vlc
from pathlib import Path
vlc_ins = vlc.Instance()
player = vlc_ins.media_player_new()
sounds_directory = Path(__file__).parent / "public/sounds"
ringing_sound = vlc_ins.media_new(sounds_directory / "dialup-0b.mp3")
intro = vlc_ins.media_new(sounds_directory / "dialup-2a.mp3")
intro_2 = vlc_ins.media_new(sounds_directory / "dialup-2b.mp3")
on_getting_matryoska = vlc_ins.media_new(sounds_directory / "dialup-3a.mp3")
on_getting_strangerlights = vlc_ins.media_new(sounds_directory / "dialup-6a.mp3")
on_getting_ouija = vlc_ins.media_new(sounds_directory / "dialup-7a.mp3")
# qq sounds
def wait_for_door_to_open():
door = Button(5)
while True:
print(door.is_pressed)
sleep(0.1)
if not door.is_pressed:
return
dial_pulser = Button(13) # blue on pi; orange in phone
dialling = Button(19) # yellow on pi; brown in phone
off_hook = Button(26) # red on pi; yellow in phone
# Ground: Black on pi; greu from hook and red from dialler in phone
##dialling = Button(17) # brown from phone
##dial_pulser = Button(27) # orange from phone
##off_hook = Button(22) # yellow from phone
## black wires to ground
indicator = LED(23)
playing = False
def wait_for_dial():
counter = 0
button_state = True
ticks_counter = 0
while True:
#sleep(0.1)
#print(str(dialling.is_pressed) + " " + str(dial_pulser.is_pressed) + ' ' + str(off_hook.is_pressed))
if not off_hook.is_pressed:
pass
else:
if dialling.is_pressed:
if player.is_playing():
player.pause()
if dial_pulser.is_pressed:
indicator.on()
if button_state:
# Was on, stay on
ticks_counter += 1
else:
if ticks_counter < 100:
print("Was about to get a false ON; ticks count: " + str(ticks_counter))
pass
else:
# Was off, now on
counter += 1
print("== OFF TICKS: " + str(ticks_counter))
print("Is now on; incrementing keys to: " + str(counter))
ticks_counter = 0
button_state = True
else:
indicator.off()
if button_state:
if ticks_counter < 100:
print("Was about to get a false OFF; ticks count: " + str(ticks_counter))
pass
else:
# Was on, now off
print("== ON TICKS: " + str(ticks_counter))
print("Now off!")
ticks_counter = 0
button_state = False
else:
# Was off, stay off
ticks_counter += 1
else:
if counter > 0:
print("You just dialled:")
print(counter)
if counter > 10:
print("we should not be here :(((")
return counter % 10
def hold_until_dialled(answer):
history = ""
while True:
result = wait_for_dial()
history += str(result)
if len(history) > 20: # let's be reasonable now
history = history[-20:]
print("Dialled " + history)
if history.endswith(answer):
return
player.set_media(ringing_sound)
wait_for_door_to_open()
player.play() # qq play on loop
off_hook.wait_for_press()
## INTRO ##
player.pause()
sleep(1)
player.set_media(intro)
player.play()
hold_until_dialled("1")
## INTRO PART 2 ##
player.set_media(intro_2)
player.play()
hold_until_dialled("222")
## SECOND PUZZLE ##
player.set_media(on_getting_strangerlights)
player.play()
hold_until_dialled("286673327")
## THIRD PUZZLE ##
player.set_media(on_getting_matryoska)
player.play()
reddd = LED(17)
reddd.on()
hold_until_dialled("8")
reddd.off()
blue = LED(27)
blue.on()
hold_until_dialled("3")
blue.off()
yellooo = LED(22)
yellooo.on()
hold_until_dialled("2")
yellooo.off()
## FINAL PUZZLE ##
player.set_media(on_getting_ouija)
player.play()
print("You're done!")