Add zoom commands

This commit is contained in:
Max Ziermann
2020-03-04 13:48:44 +01:00
parent da46f0efca
commit 8506e3a294
3 changed files with 37 additions and 3 deletions

View File

@@ -73,7 +73,7 @@ SET:
- [ ] User -> Add User - [ ] User -> Add User
- [ ] User -> Manage User - [ ] User -> Manage User
- [ ] Device -> HDD/SD Card - [ ] Device -> HDD/SD Card
- [ ] Zoom - [x] Zoom
- [ ] Focus - [ ] Focus
- [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate) - [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate)
- [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) - [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)

View File

@@ -1,4 +1,5 @@
from api.recording import RecordingAPIMixin from .recording import RecordingAPIMixin
from .zoom import ZoomAPIMixin
from .device import DeviceAPIMixin from .device import DeviceAPIMixin
from .display import DisplayAPIMixin from .display import DisplayAPIMixin
from .network import NetworkAPIMixin from .network import NetworkAPIMixin
@@ -12,7 +13,8 @@ class APIHandler(SystemAPIMixin,
UserAPIMixin, UserAPIMixin,
DeviceAPIMixin, DeviceAPIMixin,
DisplayAPIMixin, DisplayAPIMixin,
RecordingAPIMixin): RecordingAPIMixin,
ZoomAPIMixin):
""" """
The APIHandler class is the backend part of the API, the actual API calls The APIHandler class is the backend part of the API, the actual API calls
are implemented in Mixins. are implemented in Mixins.

32
api/zoom.py Normal file
View File

@@ -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)