Bosch-RCPPlus
view release on metacpan or search on metacpan
lib/Bosch/RCPPlus/Commands.pm view on Meta::CPAN
package Bosch::RCPPlus::Commands;
use strict;
use POSIX qw(floor);
use Bosch::RCPPlus::Utils qw(bytes2int);
our %Type = (
flag => 'F_FLAG',
unicode => 'P_UNICODE',
octect => 'P_OCTET',
word => 'T_DWORD',
);
our %Direction = (
read => 'READ',
write => 'WRITE',
);
sub ptz_available
{
my ($num) = @_;
return (
command => '0x0a51',
type => $Type{flag},
drection => $Direction{read},
num => $num || 1,
);
}
sub name
{
my ($num) = @_;
return (
command => '0x0019',
type => $Type{unicode},
drection => $Direction{read},
num => $num || 1,
);
}
##*
# -1 <= evt.pan <= 1
# -1 <= evt.tilt <= 1
# Zoom: -1 / +1
#
# See code from Js UI:
# - function sendPTZCommand()
# - PTZControllerEventTransmitter::sendPTZ
sub ptz
{
my ($pan, $tilt, $zoom, $num) = @_;
# BicomPTZController.alignPTZ = function (evt) {
# // -1 <= evt.pan <= 1
# // -1 <= evt.tilt <= 1
# // Zoom: -1 / +1
# var p = (-1 * Math.round(evt.pan * 15));
# var t = Math.round(evt.tilt * 15);
# var z = -1 * Math.round(evt.zoom * 7);
# if (evt.zoom === -999) {
# z = -999;
# }
# return new PTZObject(p, t, z);
#};
$pan = int(sprintf("%.0f", $pan * 15));
$tilt = int(sprintf("%.0f", $tilt * 15));
$zoom = -1 * int(sprintf("%.0f", $zoom * 7));
# BicomPTZController.prototype.sendPTZ
$pan = abs($pan) + 0x80 if ($pan < 0);
$tilt = abs($tilt) + 0x80 if ($tilt < 0);
$zoom = abs($zoom) + 0x80 if ($zoom < 0);
return (
num => $num || 1,
direction => $Direction{write},
command => '0x09A5',
type => $Type{octect},
# nbrArrayToString
payload => '0x80' . '0006' . '0110' . '85' . sprintf("%02X%02X%02X", $pan, $tilt, $zoom),
);
}
sub zoom_in
{
my ($num) = @_;
return ptz(0, 0, 1, $num);
}
sub zoom_out
{
my ($num) = @_;
return ptz(0, 0, -1, $num);
}
( run in 1.318 second using v1.01-cache-2.11-cpan-39bf76dae61 )