kopia lustrzana https://github.com/projecthorus/wenet
Allow a few attempt to initialise the camera on startup. Also catch any exceptions from the capture function and re-initialise the camera
rodzic
1f1d4db9a7
commit
09209b2872
|
@ -54,7 +54,8 @@ class WenetPiCamera2(object):
|
||||||
whitebalance = 'auto',
|
whitebalance = 'auto',
|
||||||
lens_position = -1,
|
lens_position = -1,
|
||||||
temp_filename_prefix = 'picam_temp',
|
temp_filename_prefix = 'picam_temp',
|
||||||
debug_ptr = None
|
debug_ptr = None,
|
||||||
|
init_retries = 10
|
||||||
):
|
):
|
||||||
|
|
||||||
""" Instantiate a WenetPiCam Object
|
""" Instantiate a WenetPiCam Object
|
||||||
|
@ -103,8 +104,13 @@ class WenetPiCamera2(object):
|
||||||
self.whitebalance = self.wb_lookup['auto']
|
self.whitebalance = self.wb_lookup['auto']
|
||||||
|
|
||||||
|
|
||||||
|
while init_retries > 0:
|
||||||
|
try:
|
||||||
self.init_camera()
|
self.init_camera()
|
||||||
|
except Exception as e:
|
||||||
|
self.debug_message(f"Error initialising camera, retrying in 10 seconds: - {str(e)}")
|
||||||
|
time.sleep(10)
|
||||||
|
init_retries -= 1
|
||||||
|
|
||||||
|
|
||||||
def init_camera(self):
|
def init_camera(self):
|
||||||
|
@ -323,7 +329,11 @@ class WenetPiCamera2(object):
|
||||||
capture_filename = destination_directory + "/%s_picam.jpg" % capture_time
|
capture_filename = destination_directory + "/%s_picam.jpg" % capture_time
|
||||||
|
|
||||||
# Attempt to capture.
|
# Attempt to capture.
|
||||||
|
try:
|
||||||
capture_successful = self.capture(capture_filename)
|
capture_successful = self.capture(capture_filename)
|
||||||
|
except Exception as e:
|
||||||
|
self.debug_message(f"Exception on capture - {str(e)}")
|
||||||
|
capture_successful = False
|
||||||
|
|
||||||
# If capture was unsuccessful, try again in a little bit
|
# If capture was unsuccessful, try again in a little bit
|
||||||
if not capture_successful:
|
if not capture_successful:
|
||||||
|
|
Ładowanie…
Reference in New Issue