esp32-cam: support applying camera config
This commit is contained in:
parent
009f1f22f1
commit
70a4e03c96
@ -959,6 +959,7 @@ static esp_err_t status_handler(httpd_req_t *req)
|
|||||||
p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma);
|
p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma);
|
||||||
p += sprintf(p, "\"lenc\":%u,", s->status.lenc);
|
p += sprintf(p, "\"lenc\":%u,", s->status.lenc);
|
||||||
p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror);
|
p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror);
|
||||||
|
p += sprintf(p, "\"vflip\":%u,", s->status.vflip);
|
||||||
p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
|
p += sprintf(p, "\"dcw\":%u,", s->status.dcw);
|
||||||
p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
|
p += sprintf(p, "\"colorbar\":%u", s->status.colorbar);
|
||||||
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
|
#ifdef CONFIG_LED_ILLUMINATOR_ENABLED
|
||||||
|
@ -47,6 +47,50 @@ class WebClient:
|
|||||||
self.delay = 0
|
self.delay = 0
|
||||||
self.isfirstrequest = True
|
self.isfirstrequest = True
|
||||||
|
|
||||||
|
def syncsettings(self, settings) -> bool:
|
||||||
|
status = self.getstatus()
|
||||||
|
self.logger.debug(f'syncsettings: status={status}')
|
||||||
|
|
||||||
|
changed_anything = False
|
||||||
|
|
||||||
|
for name, value in settings.items():
|
||||||
|
server_name = name
|
||||||
|
if name == 'aec_dsp':
|
||||||
|
server_name = 'aec2'
|
||||||
|
|
||||||
|
if server_name not in status:
|
||||||
|
# legacy compatibility
|
||||||
|
if server_name != 'vflip':
|
||||||
|
self.logger.warning(f'syncsettings: field `{server_name}` not found in camera status')
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
# server returns 0 or 1 for bool values
|
||||||
|
if type(value) is bool:
|
||||||
|
value = int(value)
|
||||||
|
|
||||||
|
if status[server_name] == value:
|
||||||
|
continue
|
||||||
|
except KeyError as exc:
|
||||||
|
if name != 'vflip':
|
||||||
|
self.logger.error(exc)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# fix for cases like when field is called raw_gma, but method is setrawgma()
|
||||||
|
name = name.replace('_', '')
|
||||||
|
|
||||||
|
func = getattr(self, f'set{name}')
|
||||||
|
self.logger.debug(f'syncsettings: calling set{name}({value})')
|
||||||
|
|
||||||
|
func(value)
|
||||||
|
|
||||||
|
changed_anything = True
|
||||||
|
except AttributeError as exc:
|
||||||
|
self.logger.exception(exc)
|
||||||
|
self.logger.error(f'syncsettings: method set{name}() not found')
|
||||||
|
|
||||||
|
return changed_anything
|
||||||
|
|
||||||
def setdelay(self, delay: int):
|
def setdelay(self, delay: int):
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
|
|
||||||
@ -59,7 +103,9 @@ class WebClient:
|
|||||||
def setflash(self, enable: bool):
|
def setflash(self, enable: bool):
|
||||||
self._control('flash', int(enable))
|
self._control('flash', int(enable))
|
||||||
|
|
||||||
def setresolution(self, fs: FrameSize):
|
def setframesize(self, fs: Union[int, FrameSize]):
|
||||||
|
if type(fs) is int:
|
||||||
|
fs = FrameSize(fs)
|
||||||
self._control('framesize', fs.value)
|
self._control('framesize', fs.value)
|
||||||
|
|
||||||
def sethmirror(self, enable: bool):
|
def sethmirror(self, enable: bool):
|
||||||
|
@ -54,6 +54,13 @@ def camera_exists(name: str) -> bool:
|
|||||||
return name in config['cameras']
|
return name in config['cameras']
|
||||||
|
|
||||||
|
|
||||||
|
def camera_settings(name: str) -> Optional[dict]:
|
||||||
|
try:
|
||||||
|
return config['cameras'][name]['settings']
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def have_cameras() -> bool:
|
def have_cameras() -> bool:
|
||||||
return 'cameras' in config and config['cameras']
|
return 'cameras' in config and config['cameras']
|
||||||
|
|
||||||
@ -427,6 +434,10 @@ def camera_capture(ctx: Context) -> None:
|
|||||||
ctx.answer()
|
ctx.answer()
|
||||||
|
|
||||||
client = camera_client(cam)
|
client = camera_client(cam)
|
||||||
|
if client.syncsettings(camera_settings(cam)) is True:
|
||||||
|
logger.debug('some settings were changed, sleeping for 0.4 sec')
|
||||||
|
time.sleep(0.4)
|
||||||
|
|
||||||
client.setflash(True if flash else False)
|
client.setflash(True if flash else False)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user