Skip to content

Commit

Permalink
onvif: continuous movement support
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 4, 2024
1 parent e663f5d commit b492e89
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugins/onvif/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

{
"scrypted.debugHost": "127.0.0.1",
"scrypted.debugHost": "scrypted-nvr",
}
4 changes: 2 additions & 2 deletions plugins/onvif/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/onvif/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/onvif",
"version": "0.1.24",
"version": "0.1.25",
"description": "ONVIF Camera Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",
Expand Down
34 changes: 31 additions & 3 deletions plugins/onvif/src/onvif-ptz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
zoom: ptz.includes('Zoom'),
}
}
}
},
ptzMovementType: {
title: 'PTZ Movement Type',
description: 'The type of movement to use for PTZ commands by default.',
type: 'string',
choices: [
'Default',
PanTiltZoomMovement.Absolute,
PanTiltZoomMovement.Relative,
PanTiltZoomMovement.Continuous,
],
defaultValue: 'Default',
},
});

constructor(options: SettingsMixinDeviceOptions<Settings>) {
Expand Down Expand Up @@ -55,13 +67,29 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
};
}

if (command.movement === PanTiltZoomMovement.Absolute) {
let movement = command.movement || this.storageSettings.values.ptzMovementType;
if (movement === PanTiltZoomMovement.Absolute) {
return new Promise<void>((r, f) => {
client.cam.absoluteMove({
x: command.pan,
y: command.tilt,
zoom: command.zoom,
speed: speed
speed: speed,
}, (e, result, xml) => {
if (e)
return f(e);
r();
})
})
}
else if (movement === PanTiltZoomMovement.Continuous) {
return new Promise<void>((r, f) => {
client.cam.continuousMove({
x: command.pan,
y: command.tilt,
zoom: command.zoom,
speed: speed,
timeout: command.timeout || 1000,
}, (e, result, xml) => {
if (e)
return f(e);
Expand Down
2 changes: 2 additions & 0 deletions sdk/types/scrypted_python/scrypted_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MediaPlayerState(str, Enum):
class PanTiltZoomMovement(str, Enum):

Absolute = "Absolute"
Continuous = "Continuous"
Relative = "Relative"

class ScryptedDeviceType(str, Enum):
Expand Down Expand Up @@ -712,6 +713,7 @@ class PanTiltZoomCommand(TypedDict):
pan: float # Ranges between -1 and 1.
speed: Any # The speed of the movement.
tilt: float # Ranges between -1 and 1.
timeout: float # The duration of the movement in milliseconds.
zoom: float # Ranges between 0 and 1 for max zoom.

class Position(TypedDict):
Expand Down
9 changes: 7 additions & 2 deletions sdk/types/src/types.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ export interface VideoCameraMask {

export enum PanTiltZoomMovement {
Absolute = "Absolute",
Relative = "Relative"
Relative = "Relative",
Continuous = "Continuous",
}

export interface PanTiltZoomCommand {
Expand Down Expand Up @@ -985,7 +986,11 @@ export interface PanTiltZoomCommand {
* Ranges between 0 and 1 for max zoom.
*/
zoom?: number;
}
};
/**
* The duration of the movement in milliseconds.
*/
timeout?: number;
}

export interface PanTiltZoomCapabilities {
Expand Down

0 comments on commit b492e89

Please sign in to comment.