4
4
import time
5
5
import argparse
6
6
7
- enable_4k = True # Will downscale 4K -> 1080p
8
-
9
7
parser = argparse .ArgumentParser ()
10
8
parser .add_argument ('-fb' , '--flash-bootloader' , default = False , action = "store_true" )
11
9
parser .add_argument ('-f' , '--flash-app' , default = False , action = "store_true" )
10
+ parser .add_argument ('-l' , '--load-and-exit' , default = False , action = "store_true" )
12
11
args = parser .parse_args ()
13
12
14
13
def getPipeline ():
15
- # Start defining a pipeline
14
+ enable_4k = True # Will downscale 4K -> 1080p
15
+
16
16
pipeline = dai .Pipeline ()
17
17
18
18
# Define a source - color camera
19
19
cam_rgb = pipeline .createColorCamera ()
20
- cam_rgb .setBoardSocket (dai .CameraBoardSocket .RGB )
20
+ cam_rgb .setBoardSocket (dai .CameraBoardSocket .CAM_A )
21
21
cam_rgb .setInterleaved (False )
22
22
#cam_rgb.initialControl.setManualFocus(130)
23
23
@@ -27,25 +27,29 @@ def getPipeline():
27
27
else :
28
28
cam_rgb .setResolution (dai .ColorCameraProperties .SensorResolution .THE_1080_P )
29
29
30
- # Create an UVC (USB Video Class) output node. It needs 1920x1080, NV12 input
30
+ # Create an UVC (USB Video Class) output node
31
31
uvc = pipeline .createUVC ()
32
32
cam_rgb .video .link (uvc .input )
33
33
34
- return pipeline
34
+ # Note: if the pipeline is sent later to device (using startPipeline()),
35
+ # it is important to pass the device config separately when creating the device
36
+ config = dai .Device .Config ()
37
+ # config.board.uvc = dai.BoardConfig.UVC() # enable default 1920x1080 NV12
38
+ config .board .uvc = dai .BoardConfig .UVC (1920 , 1080 )
39
+ config .board .uvc .frameType = dai .ImgFrame .Type .NV12
40
+ # config.board.uvc.cameraName = "My Custom Cam"
41
+ pipeline .setBoardConfig (config .board )
35
42
36
- # Workaround for a bug with the timeout-enabled bootloader
37
- progressCalled = False
38
- # TODO move this under flash(), will need to handle `progressCalled` differently
39
- def progress (p ):
40
- global progressCalled
41
- progressCalled = True
42
- print (f'Flashing progress: { p * 100 :.1f} %' )
43
+ return pipeline
43
44
44
45
# Will flash the bootloader if no pipeline is provided as argument
45
46
def flash (pipeline = None ):
46
47
(f , bl ) = dai .DeviceBootloader .getFirstAvailableDevice ()
47
48
bootloader = dai .DeviceBootloader (bl , True )
48
49
50
+ # Create a progress callback lambda
51
+ progress = lambda p : print (f'Flashing progress: { p * 100 :.1f} %' )
52
+
49
53
startTime = time .monotonic ()
50
54
if pipeline is None :
51
55
print ("Flashing bootloader..." )
@@ -54,8 +58,6 @@ def flash(pipeline=None):
54
58
print ("Flashing application pipeline..." )
55
59
bootloader .flash (progress , pipeline )
56
60
57
- if not progressCalled :
58
- raise RuntimeError ('Flashing failed, please try again' )
59
61
elapsedTime = round (time .monotonic () - startTime , 2 )
60
62
print ("Done in" , elapsedTime , "seconds" )
61
63
@@ -65,11 +67,23 @@ def flash(pipeline=None):
65
67
print ("Flashing successful. Please power-cycle the device" )
66
68
quit ()
67
69
68
- # Pipeline defined, now the device is connected to
70
+ if args .load_and_exit :
71
+ import os
72
+ # Disabling device watchdog, so it doesn't need the host to ping periodically
73
+ os .environ ["DEPTHAI_WATCHDOG" ] = "0"
74
+ device = dai .Device (getPipeline ())
75
+ print ("\n Device started, open a UVC viewer to check the camera stream." )
76
+ print ("Attempting to force-quit this process..." )
77
+ print ("To reconnect with depthai, a device power-cycle may be required" )
78
+ # We do not want the device to be closed, so kill the process.
79
+ # (TODO add depthai API to be able to cleanly exit without closing device)
80
+ import signal
81
+ os .kill (os .getpid (),signal .SIGKILL )
82
+
83
+ # Standard UVC load with depthai
69
84
with dai .Device (getPipeline ()) as device :
70
85
print ("\n Device started, please keep this process running" )
71
- print ("and open an UVC viewer. Example on Linux:" )
72
- print (" guvcview -d /dev/video0" )
86
+ print ("and open an UVC viewer to check the camera stream." )
73
87
print ("\n To close: Ctrl+C" )
74
88
75
89
# Doing nothing here, just keeping the host feeding the watchdog
0 commit comments