diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-05-19 00:21:32 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-05-19 00:21:32 +0300 |
commit | 70a4e03c962d4fdd321e8756e7cc9f805932b708 (patch) | |
tree | 536c68c2cf913a2d4a9cc6abeb480d350b0d99a9 | |
parent | 009f1f22f1ff64228460a91e74d49eb409253fec (diff) |
esp32-cam: support applying camera config
-rw-r--r-- | esp32-cam/CameraWebServer/app_httpd.cpp | 1 | ||||
-rw-r--r-- | src/home/camera/esp32.py | 48 | ||||
-rwxr-xr-x | src/sound_bot.py | 11 |
3 files changed, 59 insertions, 1 deletions
diff --git a/esp32-cam/CameraWebServer/app_httpd.cpp b/esp32-cam/CameraWebServer/app_httpd.cpp index 45c6f6c..16fd7d0 100644 --- a/esp32-cam/CameraWebServer/app_httpd.cpp +++ b/esp32-cam/CameraWebServer/app_httpd.cpp @@ -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, "\"lenc\":%u,", s->status.lenc); 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, "\"colorbar\":%u", s->status.colorbar); #ifdef CONFIG_LED_ILLUMINATOR_ENABLED diff --git a/src/home/camera/esp32.py b/src/home/camera/esp32.py index ef0ec53..246022b 100644 --- a/src/home/camera/esp32.py +++ b/src/home/camera/esp32.py @@ -47,6 +47,50 @@ class WebClient: self.delay = 0 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): self.delay = delay @@ -59,7 +103,9 @@ class WebClient: def setflash(self, enable: bool): 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) def sethmirror(self, enable: bool): diff --git a/src/sound_bot.py b/src/sound_bot.py index 4cc08a3..ff522cd 100755 --- a/src/sound_bot.py +++ b/src/sound_bot.py @@ -54,6 +54,13 @@ def camera_exists(name: str) -> bool: 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: return 'cameras' in config and config['cameras'] @@ -427,6 +434,10 @@ def camera_capture(ctx: Context) -> None: ctx.answer() 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) time.sleep(0.2) |