You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api.py
+20-26Lines changed: 20 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,9 @@
10
10
importos
11
11
12
12
13
-
fd=None
14
13
ctrl_list=dict()
15
14
16
-
definitialize(sensor_mode=2,v4l2_flux='/dev/video0'): # start the driver with a configurable sensor mode. (Initialization is necessary before using any other function)
17
-
globalfd
18
-
fd=open(v4l2_flux, 'rb+', buffering=0) #open the device
15
+
definitialize(fd,sensor_mode=2): # start the driver with a configurable sensor mode. (Initialization is necessary before using any other function)
19
16
20
17
if(fd.closed): #check if it opened well
21
18
print("error : can't open ",v4l2_flux)
@@ -52,48 +49,45 @@ def initialize(sensor_mode=2,v4l2_flux='/dev/video0'): # start the driver with a
52
49
line=ctrls.readline()
53
50
54
51
fmt=v4l2.v4l2_format()
55
-
fmt.type=v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE;
56
-
fmt.fmt.pix.field=v4l2.V4L2_FIELD_NONE;
52
+
fmt.type=v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
53
+
fmt.fmt.pix.field=v4l2.V4L2_FIELD_NONE
57
54
if(sensor_mode==2):
58
55
fmt.fmt.pix.width=1920
59
56
fmt.fmt.pix.height=1080
60
-
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_GREY;
61
-
set_control_value("sensor_mode",2)
57
+
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_GREY
58
+
set_control_value(fd,"sensor_mode",2)
62
59
elif(sensor_mode==0):
63
60
fmt.fmt.pix.width=1920
64
61
fmt.fmt.pix.height=1080
65
-
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_Y10;
66
-
set_control_value("sensor_mode",0)
62
+
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_Y10
63
+
set_control_value(fd,"sensor_mode",0)
67
64
elif(sensor_mode==1):
68
65
fmt.fmt.pix.width=1920
69
66
fmt.fmt.pix.height=800
70
-
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_Y10;
71
-
set_control_value("sensor_mode",1)
67
+
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_Y10
68
+
set_control_value(fd,"sensor_mode",1)
72
69
elif(sensor_mode==3):
73
-
fmt.fmt.pix.width=1920;
70
+
fmt.fmt.pix.width=1920
74
71
fmt.fmt.pix.height=80
75
-
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_GREY;
76
-
set_control_value("sensor_mode",3)
77
-
fcntl.ioctl(fd, v4l2.VIDIOC_S_FMT, fmt);
72
+
fmt.fmt.pix.pixelformat=v4l2.V4L2_PIX_FMT_GREY
73
+
set_control_value(fd,"sensor_mode",3)
74
+
fcntl.ioctl(fd, v4l2.VIDIOC_S_FMT, fmt)
78
75
79
-
defclose(v4l2_flux='/dev/video0'): # closes the access to the driver, must be used last, no other function must be called after this one (except if you want to do an initialization again)
76
+
defclose(fd): # closes the access to the driver, must be used last, no other function must be called after this one (except if you want to do an initialization again)
80
77
if(fd==None):
81
78
print("error : flux closed")
82
79
exit(0)
83
80
fd.close()
84
81
85
82
86
-
defget_device(): # return the device
87
-
returnfd
88
-
89
-
defget_device_controls(): # return all names of controls in an array
83
+
defget_device_controls(fd): # return all names of controls in an array
90
84
returnctrl_list.keys()
91
85
92
-
defget_control_info(control_name): # return all information about control example (min, max, default value ...) in a dict.
86
+
defget_control_info(fd,control_name): # return all information about control example (min, max, default value ...) in a dict.
93
87
returnctrl_list[control_name]
94
88
95
89
96
-
defset_controls(controls_dict): # use a dictionary to set controls to value
90
+
defset_controls(fd,controls_dict): # use a dictionary to set controls to value
97
91
98
92
if(fd==Noneorfd.closed): #check if file opened
99
93
print("error : initialize the connection with the function initialize()")
@@ -125,10 +119,10 @@ def set_controls(controls_dict): # use a dictionary to set controls to value
125
119
126
120
127
121
128
-
defget_controls_info(): # return the dictionary with all controls informations
122
+
defget_controls_info(fd): # return the dictionary with all controls informations
129
123
returnctrl_list
130
124
131
-
defset_control_value(control_name,value): # Allows to retrieve the whole value of a control from its name.
125
+
defset_control_value(fd,control_name,value): # Allows to retrieve the whole value of a control from its name.
132
126
if(fd==Noneorfd.closed): #check if file opened
133
127
print("error : initialize the connection with the function initialize()")
134
128
exit(0)
@@ -155,7 +149,7 @@ def set_control_value(control_name,value): # Allows to retrieve the whole value
155
149
ecs.controls=ec# set control list into the structure
156
150
fcntl.ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ecs) #set the control using v4l2 drivers
157
151
158
-
defget_control_value(control_name): # Allows to assign a value to a control from its name.
152
+
defget_control_value(fd,control_name): # Allows to assign a value to a control from its name.
159
153
if(fd==Noneorfd.closed):
160
154
print("error : initialize the connection with the function initialize()")
0 commit comments