Skip to content

Commit

Permalink
onvif: preset support
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 4, 2024
1 parent b492e89 commit b71f6e8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
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.25",
"version": "0.1.27",
"description": "ONVIF Camera Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",
Expand Down
38 changes: 34 additions & 4 deletions plugins/onvif/src/onvif-ptz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,53 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
if (e)
return f(e);
r();
})
});
})
}
else if (movement === PanTiltZoomMovement.Continuous) {
let x= command.pan;
let y = command.tilt;
let zoom = command.zoom;
if (command.speed?.pan)
x *= command.speed.pan;
if (command.speed?.tilt)
y *= command.speed.tilt;
if (command.speed?.zoom)
zoom *= command.speed.zoom;
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);
r();
})
})
});
}
else if (movement === PanTiltZoomMovement.Home) {
return new Promise<void>((r, f) => {
client.cam.gotoHomePosition({
speed: speed,
}, (e, result, xml) => {
if (e)
return f(e);
r();
})
});
}
else if (movement === PanTiltZoomMovement.Preset) {
return new Promise<void>((r, f) => {
client.cam.gotoPreset({
preset: command.preset,
}, (e, result, xml) => {
if (e)
return f(e);
r();
})
});
}
else {
// relative movement is default.
Expand All @@ -110,7 +140,7 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
return f(e);
r();
})
})
});
}
}

Expand Down
5 changes: 4 additions & 1 deletion sdk/types/scrypted_python/scrypted_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class PanTiltZoomMovement(str, Enum):

Absolute = "Absolute"
Continuous = "Continuous"
Home = "Home"
Preset = "Preset"
Relative = "Relative"

class ScryptedDeviceType(str, Enum):
Expand Down Expand Up @@ -709,8 +711,9 @@ class PanTiltZoomCapabilities(TypedDict):

class PanTiltZoomCommand(TypedDict):

movement: PanTiltZoomMovement # Specify the movement origin. If unspecified, the movement will be relative to the current position.
movement: PanTiltZoomMovement # Specify the movement type. If unspecified, the movement will be relative to the current position.
pan: float # Ranges between -1 and 1.
preset: str # The preset to move to.
speed: Any # The speed of the movement.
tilt: float # Ranges between -1 and 1.
timeout: float # The duration of the movement in milliseconds.
Expand Down
8 changes: 7 additions & 1 deletion sdk/types/src/types.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,11 +951,13 @@ export enum PanTiltZoomMovement {
Absolute = "Absolute",
Relative = "Relative",
Continuous = "Continuous",
Preset = "Preset",
Home = 'Home',
}

export interface PanTiltZoomCommand {
/**
* Specify the movement origin. If unspecified, the movement will be relative to the current position.
* Specify the movement type. If unspecified, the movement will be relative to the current position.
*/
movement?: PanTiltZoomMovement;
/**
Expand Down Expand Up @@ -991,6 +993,10 @@ export interface PanTiltZoomCommand {
* The duration of the movement in milliseconds.
*/
timeout?: number;
/**
* The preset to move to.
*/
preset?: string;
}

export interface PanTiltZoomCapabilities {
Expand Down

0 comments on commit b71f6e8

Please sign in to comment.