Skip to content

Commit

Permalink
Fix ptz
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Oct 19, 2023
1 parent 04a2256 commit de4b3c1
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 97 deletions.
6 changes: 6 additions & 0 deletions axis/vapix/interfaces/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ImageParam,
Param,
PropertyParam,
PTZParam,
StreamProfileParam,
)
from ..models.stream_profile import StreamProfile
Expand Down Expand Up @@ -386,6 +387,11 @@ async def update_ptz(self) -> None:
"""Update PTZ group of parameters."""
await self.update(PTZ)

@property
def ptz_params(self) -> PTZParam:
"""Provide property parameters."""
return PTZParam.decode(self[PTZ].raw)

@property
def ptz_camera_default(self) -> int:
"""PTZ default video channel.
Expand Down
145 changes: 145 additions & 0 deletions axis/vapix/models/param_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,151 @@ def decode(cls, data: dict[str, str]) -> Self:
)


@dataclass
class PTZParam(ApiItem):
"""Stream profile parameters."""

camera_default: int
"""PTZ default video channel.
When camera parameter is omitted in HTTP requests.
"""

number_of_cameras: int
"""Amount of video channels."""

number_of_serial_ports: int
"""Amount of serial ports."""

limits: dict
"""PTZ.Limit.L# are populated when a driver is installed on a video channel.
Index # is the video channel number, starting on 1.
When it is possible to obtain the current position from the driver,
for example the current pan position, it is possible to apply limit restrictions
to the requested operation. For instance, if an absolute pan to position 150
is requested, but the upper limit is set to 140, the new pan position will be 140.
This is the purpose of all but MinFieldAngle and MaxFieldAngle in this group.
The purpose of those two parameters is to calibrate image centering.
"""

support: dict
"""PTZ.Support.S# are populated when a driver is installed on a video channel.
A parameter in the group has the value true if the corresponding capability
is supported by the driver. The index # is the video channel number which starts from 1.
An absolute operation means moving to a certain position,
a relative operation means moving relative to the current position.
Arguments referred to apply to PTZ control.
"""

various: dict
"""PTZ.Various.V# are populated when a driver is installed on a video channel.
The index # is the video channel number which starts from 1.
The group consists of several different types of parameters for the video channel.
To distinguish the parameter types, the group is presented as
three different categories below. The Enabled parameters determine
if a specific feature can be controlled using ptz.cgi (see section PTZ control).
"""

@classmethod
def decode(cls, data: dict[str, str]) -> Self:
"""Decode dictionary to class object."""
number_of_cameras = int(data["NbrOfCameras"])
limit_attributes = (
"MaxBrightness",
"MaxFieldAngle",
"MaxFocus",
"MaxIris",
"MaxPan",
"MaxTilt",
"MaxZoom",
"MinBrightness",
"MinFieldAngle",
"MinFocus",
"MinIris",
"MinPan",
"MinTilt",
"MinZoom",
)
support_attributes = (
"AbsoluteBrightness",
"AbsoluteFocus",
"AbsoluteIris",
"AbsolutePan",
"AbsoluteTilt",
"AbsoluteZoom",
"ActionNotification",
"AreaZoom",
"AutoFocus",
"AutoIrCutFilter",
"AutoIris",
"Auxiliary",
"BackLight",
"ContinuousBrightness",
"ContinuousFocus",
"ContinuousIris",
"ContinuousPan",
"ContinuousTilt",
"ContinuousZoom",
"DevicePreset",
"DigitalZoom",
"GenericHTTP",
"IrCutFilter",
"JoyStickEmulation",
"LensOffset",
"OSDMenu",
"ProportionalSpeed",
"RelativeBrightness",
"RelativeFocus",
"RelativeIris",
"RelativePan",
"RelativeTilt",
"RelativeZoom",
"ServerPreset",
"SpeedCtl",
)
various_attributes = (
"AutoFocus",
"AutoIris",
"BackLight",
"BackLightEnabled",
"BrightnessEnabled",
"CtlQueueing",
"CtlQueueLimit",
"CtlQueuePollTime",
"FocusEnabled",
"HomePresetSet",
"IrCutFilter",
"IrCutFilterEnabled",
"IrisEnabled",
"MaxProportionalSpeed",
"PanEnabled",
"ProportionalSpeedEnabled",
"PTZCounter",
"ReturnToOverview",
"SpeedCtlEnabled",
"TiltEnabled",
"ZoomEnabled",
)
return cls(
id="ptz",
camera_default=int(data["CameraDefault"]),
number_of_cameras=int(data["NbrOfCameras"]),
number_of_serial_ports=int(data["NbrOfSerPorts"]),
limits=process_dynamic_group(
data, "Limit.L", limit_attributes, range(1, number_of_cameras + 1)
),
support=process_dynamic_group(
data, "Support.S", support_attributes, range(1, number_of_cameras + 1)
),
various=process_dynamic_group(
data, "Various.V", various_attributes, range(1, number_of_cameras + 1)
),
)


@dataclass
class StreamProfileParam(ApiItem):
"""Stream profile parameters."""
Expand Down
Loading

0 comments on commit de4b3c1

Please sign in to comment.