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():
|
||||
error_sources = []
|
||||
logging.info("Attempting to import picamera...")
|
||||
|
||||
try:
|
||||
from picamerax import PiCamera as _
|
||||
from picamerax import PiCamera
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
# TODO: Parse exception object for a few different issues, and append different error sources
|
||||
# E.g. pi with camera already in use, disconnected, unsupported OS, etc
|
||||
# TODO: Parse exception object for a few different issues, and append
|
||||
# different error sources E.g. pi with camera already in use,
|
||||
# disconnected, unsupported OS, etc
|
||||
logging.error(e)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue