-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.py
195 lines (159 loc) · 5.34 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import time
import multiprocessing
from kiosk.kiosk import Kiosk
from kiosk.utils import read_yaml
from kiosk.artbutton import ArtButton
from watchdog.observers import Observer
from kiosk.art_event_handler import ArtEventHandler
from kiosk.pir_sensor_screensaver import PIRSensorScreensaver
def start_artbutton(GPIO_mode: str,
GPIO_pinout: int,
active_artwork_file_path: str,
image_directory: str,
loop_sleep_sec: float) -> None:
"""
Starts the art button listener.
Parameters
----------
GPIO_mode : str
GPIO mode used to set up the Nvidia Jetson board. Accepted values: {'BOARD', 'BCM'}
GPIO_pinout : int
GPIO pin number to which the button is connected.
active_artwork_file_path : str
Path to the active artwork file. This is the image that will be displayed in the Kiosk.
image_directory : str
Path to the image directory from where the images will be randomly sampled.
loop_sleep_sec : float
Seconds to sleep after registered button click. Risk of multiple unexpected simultaneous clicks
if set to low.
Returns
-------
None
"""
button = ArtButton(
GPIO_mode=GPIO_mode,
GPIO_pinout=GPIO_pinout,
active_artwork_file_path=active_artwork_file_path,
image_directory=image_directory,
loop_sleep_sec=loop_sleep_sec
)
button.start()
def start_kiosk(active_artwork_file_path: str,
frame_path: str,
frame_inner_size: tuple) -> None:
"""
Starts art kiosk.
Parameters
----------
active_artwork_file_path : str
Path to active artwork to be displayed. If the active artwork image is updated, the new image will be rendered.
frame_path : str
Path to frame image.
frame_inner_size : tuple
Inner size of frame. Used to resize artwork to fit frame.
Returns
-------
None
"""
kiosk = Kiosk(
active_artwork_path=active_artwork_file_path,
frame_path=frame_path,
frame_inner_size=frame_inner_size)
kiosk.start()
def start_pir(GPIO_mode: str,
GPIO_pinout: int,
loop_sleep_sec: float,
screensaver_after_sec: float) -> None:
"""
Starts passive infrared sensor listener.
Parameters
----------
GPIO_mode : str
GPIO mode used to set up the Nvidia Jetson board. Accepted values: {'BOARD', 'BCM'}
GPIO_pinout : int
GPIO pin number to which the PIR sensor is connected.
loop_sleep_sec : float
Seconds to sleep when reading PIR sensor and checking screensaver.
screensaver_after_sec : float
Seconds before the screensaver will be activated.
Returns
-------
None
"""
pir = PIRSensorScreensaver(
GPIO_mode=GPIO_mode,
GPIO_pinout=GPIO_pinout,
loop_sleep_sec=loop_sleep_sec,
screensaver_after_sec=screensaver_after_sec
)
pir.start()
def start_art_generator(image_directory: str,
lower_limit_num_images: int) -> None:
"""
Starts event handler that listens to deleted images in the image_directory. If an image is deleted from the
image_directory (i.e. moved to replace the active artwork) and the number of images in image_directory falls
below lower_limit_num_images, a process is spawned to generate new images.
NOTE: You need to update the class ArtEventHandler and pass the needed arguments to generate new images!
Parameters
----------
image_directory : str
Path to the image directory to where the newly generated images should be saved.
lower_limit_num_images : int
Lower threshold triggering new images to be generated.
Returns
-------
None
"""
handler = ArtEventHandler(
image_directory=image_directory,
lower_limit_num_images=lower_limit_num_images
)
observer = Observer()
observer.schedule(handler, path=image_directory, recursive=False)
observer.start()
while True:
time.sleep(1)
if __name__ == '__main__':
config = read_yaml('config.yaml')
p_button = multiprocessing.Process(
target=start_artbutton,
args=(
config['artbutton']['GPIO_mode'],
config['artbutton']['GPIO_pinout'],
config['active_artwork_file_path'],
config['image_directory'],
config['artbutton']['loop_sleep_sec']
)
)
p_kiosk = multiprocessing.Process(
target=start_kiosk,
args=(
config['active_artwork_file_path'],
config['kiosk']['path'],
(config['kiosk']['inner_width'], config['kiosk']['inner_height'])
)
)
p_pir = multiprocessing.Process(
target=start_pir,
args=(
config['pirsensor']['GPIO_mode'],
config['pirsensor']['GPIO_pinout'],
config['pirsensor']['loop_sleep_sec'],
config['pirsensor']['screensaver_after_sec'],
)
)
p_art = multiprocessing.Process(
target=start_art_generator,
args=(
config['image_directory'],
config['lower_limit_num_images']
)
)
p_button.start()
p_kiosk.start()
p_pir.start()
p_art.start()
p_button.join()
p_kiosk.join()
p_pir.join()
p_art.join()