Enclosed changes to camera settings in try-catch block. Fixes #55

This commit is contained in:
Balthasar Reuter
2018-10-19 23:37:36 +02:00
parent 15077b2e74
commit 1615f658c1
2 changed files with 62 additions and 42 deletions

View File

@@ -43,11 +43,18 @@ class CameraGphoto2(CameraInterface):
def cleanup(self):
config = self._cap.get_config()
config.get_child_by_name('imageformat').set_value(self._imageformat)
config.get_child_by_name('imageformatsd').set_value(self._imageformat)
# config.get_child_by_name('autopoweroff').set_value(self._autopoweroff)
self._cap.set_config(config)
try:
config = self._cap.get_config()
config.get_child_by_name('imageformat').set_value(
self._imageformat)
config.get_child_by_name('imageformatsd').set_value(
self._imageformat)
# config.get_child_by_name('autopoweroff').set_value(
# self._autopoweroff)
self._cap.set_config(config)
except BaseException as e:
logging.warn('Error while changing camera settings: {}.'.format(e))
self._cap.exit(self._ctxt)
def _setupLogging(self):
@@ -64,29 +71,33 @@ class CameraGphoto2(CameraInterface):
logging.info('Camera summary: %s',
str(self._cap.get_summary(self._ctxt)))
# get configuration tree
config = self._cap.get_config()
try:
# get configuration tree
config = self._cap.get_config()
# make sure camera format is not set to raw
imageformat = config.get_child_by_name('imageformat')
self._imageformat = imageformat.get_value()
if 'raw' in self._imageformat.lower():
imageformat.set_value('Large Fine JPEG')
imageformatsd = config.get_child_by_name('imageformatsd')
self._imageformatsd = imageformatsd.get_value()
if 'raw' in self._imageformatsd.lower():
imageformatsd.set_value('Large Fine JPEG')
# make sure camera format is not set to raw
imageformat = config.get_child_by_name('imageformat')
self._imageformat = imageformat.get_value()
if 'raw' in self._imageformat.lower():
imageformat.set_value('Large Fine JPEG')
imageformatsd = config.get_child_by_name('imageformatsd')
self._imageformatsd = imageformatsd.get_value()
if 'raw' in self._imageformatsd.lower():
imageformatsd.set_value('Large Fine JPEG')
# make sure autopoweroff is disabled
# this doesn't seem to work
# autopoweroff = config.get_child_by_name('autopoweroff')
# self._autopoweroff = autopoweroff.get_value()
# logging.info('autopoweroff: {}'.format(self._autopoweroff))
# if int(self._autopoweroff) > 0:
# autopoweroff.set_value('0')
# make sure autopoweroff is disabled
# this doesn't seem to work
# autopoweroff = config.get_child_by_name('autopoweroff')
# self._autopoweroff = autopoweroff.get_value()
# logging.info('autopoweroff: {}'.format(self._autopoweroff))
# if int(self._autopoweroff) > 0:
# autopoweroff.set_value('0')
# apply configuration and print current config
self._cap.set_config(config)
except BaseException as e:
logging.warn('Error while changing camera settings: {}.'.format(e))
# apply configuration and print current config
self._cap.set_config(config)
self._printConfig(self._cap.get_config())
@staticmethod

View File

@@ -42,9 +42,14 @@ class CameraGphoto2Cffi(CameraInterface):
def cleanup(self):
self._cap.config['imgsettings']['imageformat'].set(self._imgfmt)
self._cap.config['imgsettings']['imageformatsd'].set(self._imgfmtsd)
# self._cap.config['settings']['autopoweroff'].set(self._autopoweroff)
try:
self._cap.config['imgsettings']['imageformat'].set(self._imgfmt)
self._cap.config['imgsettings']['imageformatsd'].set(
self._imgfmtsd)
# self._cap.config['settings']['autopoweroff'].set(
# self._autopoweroff)
except BaseException as e:
logging.warn('Error while changing camera settings: {}.'.format(e))
def _setupCamera(self):
@@ -52,21 +57,25 @@ class CameraGphoto2Cffi(CameraInterface):
logging.info('Supported operations: %s',
self._cap.supported_operations)
# make sure camera format is not set to raw
imgfmt = 'Large Fine JPEG'
self._imgfmt = self._cap.config['imgsettings']['imageformat'].value
if 'raw' in self._imgfmt.lower():
self._cap.config['imgsettings']['imageformat'].set(imgfmt)
self._imgfmtsd = self._cap.config['imgsettings']['imageformatsd'].value
if 'raw' in self._imgfmtsd.lower():
self._cap.config['imgsettings']['imageformatsd'].set(imgfmt)
try:
# make sure camera format is not set to raw
imgfmt = 'Large Fine JPEG'
self._imgfmt = self._cap.config['imgsettings']['imageformat'].value
if 'raw' in self._imgfmt.lower():
self._cap.config['imgsettings']['imageformat'].set(imgfmt)
self._imgfmtsd = (
self._cap.config['imgsettings']['imageformatsd'].value)
if 'raw' in self._imgfmtsd.lower():
self._cap.config['imgsettings']['imageformatsd'].set(imgfmt)
# make sure autopoweroff is disabled
# this doesn't seem to work
# self._autopoweroff = int(
# self._cap.config['settings']['autopoweroff'].value)
# if self._autopoweroff > 0:
# self._cap.config['settings']['autopoweroff'].set("0")
# make sure autopoweroff is disabled
# this doesn't seem to work
# self._autopoweroff = int(
# self._cap.config['settings']['autopoweroff'].value)
# if self._autopoweroff > 0:
# self._cap.config['settings']['autopoweroff'].set("0")
except BaseException as e:
logging.warn('Error while changing camera settings: {}.'.format(e))
# print current config
self._printConfig(self._cap.config)