No I don't have /sys/class/video4linux/video1/pan_tilt . I suspect some
old version of the UVC driver had this at some point . but it does not exist with the current driver . the pan/tilt control are "custom controls" that
are accessible with some special v4l2 ioct calls ,they are created dynamically by a udev script . all this is handled by a library called libwebcam and a small utility program called uvcdynctrl . you can find all the explanations and documentation , and download this utility at the address i mentioned in my first post .
the ptz of the camera . some other people have gone that way .
with my script it is possible to control a local camera .
Code: Select all
# ==========================================================================
#
# ZoneMinder QuickcamSphere Control Protocol Module, $Date: 2009-02-08
# Copyright (C) 2009 Bokusouchi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ==========================================================================
#
# This module contains the implementation of the QuickcamSphere camera control
# protocol
#
package ZoneMinder::Control::QuickcamSphere;
use 5.006;
use strict;
use warnings;
use IO::Handle;
use File::Basename;
use File::Find;
#==========================================================================
#
# These are the elements you can edit to suit your installation
#
# ==========================================================================
use constant DBG_ID => "QuickcamSphere"; # Tag that appears in debug to identify source
use constant DBG_LEVEL => 1; # 0 is errors, warnings and info only, > 0 for debug
# ==========================================================================
require ZoneMinder::Base;
require ZoneMinder::Control;
our @ISA = qw(ZoneMinder::Control);
our $VERSION = $ZoneMinder::Base::VERSION;
# ==========================================================================
#
# QuickcamSphere Control Protocol
#
# ==========================================================================
use ZoneMinder::Debug qw(:all);
use Time::HiRes qw( usleep );
use constant SYNC => 0xff;
use constant COMMAND_GAP => 100000; # In ms
sub new
{
my $class = shift;
my $id = shift;
my $self = ZoneMinder::Control->new( $id );
bless( $self, $class );
srand( time() );
$self->loadMonitor();
$self->where_am_i();
return $self;
}
our $AUTOLOAD;
sub AUTOLOAD
{
my $self = shift;
my $class = ref($self) || croak( "$self not object" );
my $name = $AUTOLOAD;
$name =~ s/.*://;
if ( exists($self->{$name}) )
{
return( $self->{$name} );
}
Fatal( "Can't access $name member of object of class $class" );
}
sub open
{
my $self = shift;
$self->loadMonitor();
$self->{state} = 'open';
}
sub close
{
my $self = shift;
$self->{state} = 'closed';
}
sub printMsg
{
if ( zmDbgLevel() > 0 )
{
my $self = shift;
my $msg = shift;
my $prefix = shift || "";
$prefix = $prefix.": " if ( $prefix );
my $line_length = 16;
my $msg_len = int(@$msg);
my $msg_str = $prefix;
for ( my $i = 0; $i <msg_len> 0) && ($i%$line_length == 0) && ($i != ($msg_len-1)) )
{
$msg_str .= sprintf( "\n%*s", length($prefix), "" );
}
$msg_str .= sprintf( "%02x ", $msg->[$i] );
}
$msg_str .= "[".$msg_len."]";
Debug( $msg_str );
}
}
sub moveRelUp
{
my $self = shift;
my $params = shift;
$self->loadMonitor();
my $tiltstep = $self->getParam( $params, 'tiltstep' );
Debug( "Step Up" );
my $pan_min=$self->{Monitor}->{MinPanRange};
my $pan_max=$self->{Monitor}->{MaxPanRange};
my $tilt_min=$self->{Monitor}->{MinTiltRange};
my $tilt_max=$self->{Monitor}->{MaxTiltRange};
my $pan_cur=$self->{Monitor}->{pan_cur};
my $tilt_cur=$self->{Monitor}->{tilt_cur};
my $focus_cur=$self->{Monitor}->{focus_cur};
my $panstep=0;
$tiltstep = - $tiltstep ;
if ($tilt_cur + $tiltstep <tilt_min>{Monitor}->{uvcdynctrl_device}=~ /^([\w.</Debug>{Monitor}->{pan_cur}=$pan_cur;
$tilt_cur=$self->{Monitor}->{tilt_cur}=$tilt_cur;
my $device_temp_file=$self->{Monitor}->{device_temp_file};
my $fh=IO::Handle->new();
Debug( "device_temp_file=$device_temp_file");
CORE::open($fh,">","$device_temp_file") || die("Cannot open $device_temp_file");
CORE::print($fh "$pan_cur:$tilt_cur:$focus_cur");
CORE::close($fh);
Debug( "Moving to $pan_cur,$tilt_cur \n" );
$tiltstep = $tiltstep * 64 ;
$panstep = $panstep * 64 ;
Debug( "real_panstep = $panstep reial_tiltstep = $tiltstep\n" );
if ( $tiltstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
}
if ( $panstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
}
if ( $tiltstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
CORE:usleep (400);
}
if ( $panstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
CORE:usleep (400);
}
}
sub moveRelDown
{
my $self = shift;
my $params = shift;
$self->loadMonitor();
my $tiltstep = $self->getParam( $params, 'tiltstep' );
Debug( "Step Down" );
my $pan_min=$self->{Monitor}->{MinPanRange};
my $pan_max=$self->{Monitor}->{MaxPanRange};
my $tilt_min=$self->{Monitor}->{MinTiltRange};
my $tilt_max=$self->{Monitor}->{MaxTiltRange};
my $pan_cur=$self->{Monitor}->{pan_cur};
my $tilt_cur=$self->{Monitor}->{tilt_cur};
my $focus_cur=$self->{Monitor}->{focus_cur};
my $panstep=0;
if ($tilt_cur + $tiltstep > $tilt_max) {
$tiltstep = $tilt_max - $tilt_cur;
}
Debug( "panstep=$panstep tiltstep=$tiltstep ,before untaint" );
my $untaint1="0";
my $untaint2="0";
($untaint1)="$panstep"=~ /^(-?[0-9]+)$/;
Debug ("untaint1= $untaint1");
($untaint2)="$tiltstep"=~ /^(-?[0-9]+)$/;
Debug ("untaint2= $untaint2");
$panstep=$untaint1;
$tiltstep=$untaint2;
my $untainted_device="grr";
($untainted_device) =$self->{Monitor}->{uvcdynctrl_device}=~ /^([\w.</Debug>{Monitor}->{pan_cur}=$pan_cur;
$tilt_cur=$self->{Monitor}->{tilt_cur}=$tilt_cur;
my $device_temp_file=$self->{Monitor}->{device_temp_file};
my $fh=IO::Handle->new();
Debug( "device_temp_file=$device_temp_file");
CORE::open($fh,">","$device_temp_file") || die("Cannot open $device_temp_file");
CORE::print($fh "$pan_cur:$tilt_cur:$focus_cur");
CORE::close($fh);
Debug( "Moving to $pan_cur,$tilt_cur \n" );
$tiltstep = $tiltstep * 64 ;
$panstep = $panstep * 64 ;
Debug( "real_panstep = $panstep real_tiltstep = $tiltstep\n" );
if ( $tiltstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
}
if ( $panstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
}
if ( $tiltstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
CORE:usleep (400);
}
if ( $panstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
CORE:usleep (400);
}
}
sub moveRelLeft
{
my $self = shift;
my $params = shift;
$self->loadMonitor();
my $tiltstep=0;
my $panstep = $self->getParam( $params, 'panstep' );
Debug( "panstep=$panstep" );
Debug( "Step Left" );
my $pan_max=$self->{Monitor}->{MaxPanRange};
Debug("pan_max=$pan_max");
my $pan_min=$self->{Monitor}->{MinPanRange};
Debug("pan_min=$pan_min");
my $tilt_min=$self->{Monitor}->{MinTiltRange};
my $tilt_max=$self->{Monitor}->{MaxTiltRange};
my $pan_cur=$self->{Monitor}->{pan_cur};
my $tilt_cur=$self->{Monitor}->{tilt_cur};
my $focus_cur=$self->{Monitor}->{focus_cur};
if ($pan_cur + $panstep > $pan_max) {
$panstep = $pan_max - $pan_cur;
Debug( "Hitting the limite --> recalculating panstep" );
}
Debug( "panstep=$panstep tiltstep=$tiltstep ,before untaint" );
my $untaint1="0";
my $untaint2="0";
($untaint1)="$panstep"=~ /^(-?[0-9]+)$/;
Debug ("untaint1= $untaint1");
($untaint2)="$tiltstep"=~ /^(-?[0-9]+)$/;
Debug ("untaint2= $untaint2");
$panstep=$untaint1;
$tiltstep=$untaint2;
my $untainted_device="grr";
($untainted_device) =$self->{Monitor}->{uvcdynctrl_device}=~ /^([\w.</Debug>{Monitor}->{pan_cur}=$pan_cur;
$tilt_cur=$self->{Monitor}->{tilt_cur}=$tilt_cur;
my $device_temp_file=$self->{Monitor}->{device_temp_file};
my $fh=IO::Handle->new();
Debug( "device_temp_file=$device_temp_file");
CORE::open($fh,">","$device_temp_file") || die("Cannot open $device_temp_file");
CORE::print($fh "$pan_cur:$tilt_cur:$focus_cur");
CORE::close($fh);
Debug( "Moving to $pan_cur,$tilt_cur \n" );
$tiltstep = $tiltstep * 64 ;
$panstep = $panstep * 64 ;
Debug( "real_panstep = $panstep reial_tiltstep = $tiltstep\n" );
if ( $tiltstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
}
if ( $panstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
}
if ( $tiltstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
CORE:usleep (400);
}
if ( $panstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
CORE:usleep (400);
}
}
sub moveRelRight
{
my $self = shift;
my $params = shift;
$self->loadMonitor();
my $tiltstep=0;
my $panstep = - $self->getParam( $params, 'panstep' );
Debug( "panstep=$panstep" );
Debug( "Step Right" );
my $pan_min=$self->{Monitor}->{MinPanRange};
my $pan_max=$self->{Monitor}->{MaxPanRange};
my $tilt_min=$self->{Monitor}->{MinTiltRange};
my $tilt_max=$self->{Monitor}->{MaxTiltRange};
my $pan_cur=$self->{Monitor}->{pan_cur};
my $tilt_cur=$self->{Monitor}->{tilt_cur};
my $focus_cur=$self->{Monitor}->{focus_cur};
if ($pan_cur + $panstep <pan_min>{Monitor}->{uvcdynctrl_device}=~ /^([\w.</Debug>{Monitor}->{device_temp_file};
my $fh=IO::Handle->new();
Debug( "device_temp_file=$device_temp_file");
CORE::open($fh,">","$device_temp_file") || die("Cannot open $device_temp_file");
CORE::print($fh "$pan_cur:$tilt_cur:$focus_cur");
CORE::close($fh);
Debug( "Moving to $pan_cur,$tilt_cur \n" );
$pan_cur=$self->{Monitor}->{pan_cur}=$pan_cur;
$tilt_cur=$self->{Monitor}->{tilt_cur}=$tilt_cur;
$tiltstep = $tiltstep * 64 ;
$panstep = $panstep * 64 ;
Debug( "real_panstep = $panstep reial_tiltstep = $tiltstep\n" );
if ( $tiltstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
}
if ( $panstep == 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
}
if ( $tiltstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d", $untainted_device ,"-s","Tilt (relative)" ,"--","$tiltstep") ;
CORE:usleep (400);
}
if ( $panstep != 0 )
{
CORE:system("/usr/bin/uvcdynctrl" ,"-d",$untainted_device ,"-s","Pan (relative)" ,"--","$panstep") ;
CORE:usleep (400);
}
}
sub moveRelUpLeft
{
my $self = shift;
my $params = shift;
}
sub moveRelUpRight
{
my $self = shift;
my $params = shift;
}
sub moveRelDownLeft
{
my $self = shift;
my $params = shift;
}
sub moveRelDownRight
{
my $self = shift;
my $params = shift;
}
sub focusConNear
{
my $self = shift;
my $params = shift;
Debug( "Focus Near" );
}
sub focusConFar
{
my $self = shift;
my $params = shift;
Debug( "Focus Far" );
}
sub presetClear
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset', 1 );
Debug( "Clear Preset $preset" );
}
sub presetSet
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset', 1 );
}
sub presetGoto
{
my $self = shift;
my $params = shift;
my $preset = $self->getParam( $params, 'preset', 1 );
Debug( "Goto Preset $preset" );
}
sub presetHome
{
my $self = shift;
my $params = shift;
# Debug("device= $self->{Monitor}->{ControlDevice}");
# Debug("device= $self->{Monitor}->{ControlDevice}");
# Debug("device= $self->{Monitor}->{ControlDevice}");
# Debug("device= $self->{Monitor}->{ControlDevice}");
# Debug("device= $self->{Monitor}->{ControlDevice}");
# Debug("device= $self->{Monitor}->{ControlDevice}");
# $self->where_am_i();
# my @msg = ( 0x80|$self->{Monitor}->{ControlAddress}, 0x01, 0x06, 0x04, SYNC );
# $self->sendCmd( \@msg );
}
sub where_am_i
{
my $self = shift;
my $params = shift;
# We have a device ... where is it now?
Debug("n ::where_am_i:: ");
$self->loadMonitor();
Debug("device= $self->{Monitor}->{ControlDevice}");
$self->{Monitor}->{MinPanRange}=-55,
$self->{Monitor}->{MaxPanRange}= 55,
$self->{Monitor}->{MinTiltRange}=-28,
$self->{Monitor}->{MaxTiltRange}= 24,
Debug("MinPanRange= $self->{Monitor}->{MinPanRange}");
Debug("MaxPanRange= $self->{Monitor}->{MaxPanRange}");
Debug("MinTiltRange= $self->{Monitor}->{MinTiltRange}");
Debug("MaxTiltRange= $self->{Monitor}->{MaxTiltRange}");
my $sym_device_basename=File::Basename::basename($self->{Monitor}->{ControlDevice});
Debug("sym_device_basename= $sym_device_basename");
my $device_temp_file="/tmp/"."$sym_device_basename".".current";
Debug ( "grrr device_temp_file= $device_temp_file \n" );
$self->{Monitor}->{device_temp_file}=$device_temp_file;
my $fh=IO::Handle->new();
CORE::open($fh, "$device_temp_file") || Debug ("Could not open $device_temp_file");
my $diamond_handle=<fh>;
my ($pan_cur,$tilt_cur,$focus_cur)=CORE::split(/:/,$diamond_handle);
CORE::close($fh);
Debug ( "Currently at $pan_cur,$tilt_cur,$focus_cur" );
$self->{Monitor}->{pan_cur}=$pan_cur;
$self->{Monitor}->{tilt_cur}=$tilt_cur;
$self->{Monitor}->{focus_cur}=$focus_cur;
Debug ( "Currently(monitor object) at $self->{Monitor}->{pan_cur}, $self->{Monitor}->{tilt_cur},$self->{Monitor}->{focus_cur}" );
#first we deduce the real device name
my $real_device="glop";
#$real_device=File::find::readlink("$sym_device");
$real_device=CORE::readlink("$self->{Monitor}->{ControlDevice}");
Debug ( "real_device= $real_device" );
my $tainted_device=File::Basename::basename($real_device);
Debug ( "tainted_device= $tainted_device" );
$self->{Monitor}->{uvcdynctrl_device}=$tainted_device ;
#my uvcdynctrl_device="glop";
#$uvcdynctrl_device) = $tainted_device=~ /^([\w.<>\/,"=]+)$/;
#Debug ( "uvcdynctrl_device= $uvcdynctrl_device \n" );
#srand( time() );
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
ZoneMinder::Database - Perl extension for blah blah blah
=head1 SYNOPSIS
use ZoneMinder::Database;
blah blah blah
=head1 DESCRIPTION
Stub documentation for ZoneMinder, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.
Blah blah blah.
=head2 EXPORT
None by default.
=head1 SEE ALSO
Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.
If you have a mailing list set up for your module, mention it here.
If you have a web site set up for your module, mention it here.
=head1 AUTHOR
Bokusouchi
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2009 bokusouchi
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
=cut