From 8506e3a294778a82a722599dd3cbf40565bea140 Mon Sep 17 00:00:00 2001 From: Max Ziermann Date: Wed, 4 Mar 2020 13:48:44 +0100 Subject: [PATCH] Add zoom commands --- README.md | 2 +- api/APIHandler.py | 6 ++++-- api/zoom.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 api/zoom.py diff --git a/README.md b/README.md index 7feee35..b5105d7 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ SET: - [ ] User -> Add User - [ ] User -> Manage User - [ ] Device -> HDD/SD Card -- [ ] Zoom +- [x] Zoom - [ ] Focus - [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate) - [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) diff --git a/api/APIHandler.py b/api/APIHandler.py index 61274e7..eb59ec6 100644 --- a/api/APIHandler.py +++ b/api/APIHandler.py @@ -1,4 +1,5 @@ -from api.recording import RecordingAPIMixin +from .recording import RecordingAPIMixin +from .zoom import ZoomAPIMixin from .device import DeviceAPIMixin from .display import DisplayAPIMixin from .network import NetworkAPIMixin @@ -12,7 +13,8 @@ class APIHandler(SystemAPIMixin, UserAPIMixin, DeviceAPIMixin, DisplayAPIMixin, - RecordingAPIMixin): + RecordingAPIMixin, + ZoomAPIMixin): """ The APIHandler class is the backend part of the API, the actual API calls are implemented in Mixins. diff --git a/api/zoom.py b/api/zoom.py new file mode 100644 index 0000000..a3e2097 --- /dev/null +++ b/api/zoom.py @@ -0,0 +1,32 @@ +class ZoomAPIMixin: + """ + API for zooming and changing focus. + Note that the API does not allow zooming/focusing by absolute + values rather that changing focus/zoom for a given time. + """ + def _start_zoom(self, direction, speed=60): + op = 'ZoomInc' if direction == 'in' else 'ZoomDec' + data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": op, "speed": speed}}] + return self._execute_command('PtzCtrl', data) + + def start_zoom_in(self, speed=60): + """ + The camera zooms in until self.stop_zoom() is called. + :return: response json + """ + return self._start_zoom('in', speed=speed) + + def start_zoom_out(self, speed=60): + """ + The camera zooms out until self.stop_zoom() is called. + :return: response json + """ + return self._start_zoom('out', speed=speed) + + def stop_zoom(self): + """ + Stop zooming. + :return: response json + """ + data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}] + return self._execute_command('PtzCtrl', data)