-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimx296_set_trigger.py
executable file
·55 lines (46 loc) · 1.44 KB
/
imx296_set_trigger.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
#!/usr/bin/env python3
#
# Set the trigger mode on one or more cameras
#
#
# From the VC Github page
# (https://github.com/VC-MIPI-modules/vc_mipi_nvidia/blob/master/doc/TRIGGER_MODE.md)
#
# The command line is:
#
# v4l2-ctl -c trigger_mode=<trigger mode number>
#
# The trigger mode remains set until it is deactivated with
#
# v4l2-ctl -c trigger_mode=0
#
# IMX392 supports:
# 0. trigger disabled (streaming)
# 1. external
# 2. pulsewidth
# 3. self
# 4. single: v4l2-ctl -c single_trigger=1
import subprocess
import argparse
from enum import Enum
class TriggerMode(Enum):
STREAMING = 0
EXTERNAL = 1
PULSEWIDTH = 2
SELF = 3
SINGLE = 4
if __name__=="__main__":
parser = argparse.ArgumentParser()
mode_choices = [t.name.lower() for t in TriggerMode]
parser.add_argument("mode",
choices=mode_choices,
help=f"Trigger mode (options: {','.join(mode_choices)})")
parser.add_argument("--camera", "-c", action="append",
default=[], help="Camera(s) to modify (0,1). Can be specified multiple times.")
args = parser.parse_args()
mode = TriggerMode[ args.mode.upper() ]
if len(args.camera) == 0:
parser.error("No cameras specified, not doing anything")
for cam in args.camera:
print(f"Configuring camera {cam} to {mode.name}")
subprocess.run(["sudo", "v4l2-ctl", "-d", cam, "-c", f"trigger_mode={mode.value}"])