-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (57 loc) · 2.38 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
import signal
from argparse import Namespace
from multiprocessing import freeze_support
from pyftdi.ftdi import Ftdi
from reactivex import Subject
from CommandLineParser import CommandLineParser
from SignalHandler import signal_handler
"""
Technologies used in this project
ReactiveX for Signal Handling:
Reactivex is being used for handling photo cell signals. This allows for asynchronous and non-blocking operation
improving responsiveness.
Spawning Processes:
Circumvent the Global Interpreter Lock (GIL) by using separate processes for writing images to persistent
storage.
Chunk Processing for Efficiency:
Usage of a chunk of images for writing to persistent storage is an efficient strategy that reduces the number of
context switches and system calls.
Shared Memory for Fast Data Transfer:
Employing shared memory for transferring image data to a separate process (inter-process communication).
Monitoring:
The inclusion of a monitoring window provides valuable insights into program execution.
Logging:
Logging capabilities to help analyse potential problems.
"""
def main():
freeze_support()
# Signal handler is called on interrupt (ctrl-c) and terminate
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
# retrieve command line arguments
args: Namespace = CommandLineParser().parse_args()
# initialize FTDI device driver
ftdi = Ftdi()
# list available ftdi devices
# on macOS do a `ls -lta /dev/cu*` when the ftdi microcontroller is connected
print(f"List attached FT232H devices: {ftdi.list_devices()}")
try:
# open a dedicated ftdi device contained in the list of ftdi devices
# URL Scheme
# ftdi://[vendor][:[product][:serial|:bus:address|:index]]/interface
ftdi.open_from_url("ftdi:///1")
except Exception as e:
print(f"Error accessing FT232H chip: {e}")
exit(1)
from DigitizeVideo import DigitizeVideo
from Ft232hConnector import Ft232hConnector
optocoupler_signal_subject = Subject()
# create class instances
DigitizeVideo(args, optocoupler_signal_subject)
ft232h = Ft232hConnector(optocoupler_signal_subject, args.maxcount)
# start recording - wait for signal(s) to take picture(s)
ft232h.signal_input()
# disconnect FT232H
ftdi.close()
if __name__ == '__main__':
main()