Detect camera not enabled picamerax error
This commit is contained in:
parent
9be4b32bf8
commit
fbd3b349df
1 changed files with 22 additions and 3 deletions
|
|
@ -9,17 +9,36 @@ picamera_import_error = ErrorSource(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
picamera_errors = (
|
||||||
|
"Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
error_sources = []
|
error_sources = []
|
||||||
logging.info("Attempting to import picamera...")
|
logging.info("Attempting to import picamera...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from picamerax import PiCamera as _
|
from picamerax import PiCamera
|
||||||
except Exception as e: # pylint: disable=W0703
|
except Exception as e: # pylint: disable=W0703
|
||||||
# TODO: Parse exception object for a few different issues, and append different error sources
|
# TODO: Parse exception object for a few different issues, and append
|
||||||
# E.g. pi with camera already in use, disconnected, unsupported OS, etc
|
# different error sources E.g. pi with camera already in use,
|
||||||
|
# disconnected, unsupported OS, etc
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
error_sources.append(picamera_import_error)
|
error_sources.append(picamera_import_error)
|
||||||
|
else:
|
||||||
|
import picamerax.exc.PiCameraError
|
||||||
|
|
||||||
|
try:
|
||||||
|
cam = PiCamera()
|
||||||
|
except picamerax.exc.PiCameraError as e:
|
||||||
|
if e.args[0] in picamera_errors:
|
||||||
|
error_sources.append(ErrorSource(e.args[0]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return error_sources
|
return error_sources
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue