From 7489c3850dbd9f102e0819c71bdb69fdbdc4cbee Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 14 Apr 2021 17:19:01 -0400 Subject: [PATCH] Store last command for continuous moves so that moveStop can send the correct stop command --- .../lib/ZoneMinder/Control/Amcrest_HTTP.pm | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm index 59e4f7511..aa8d27b53 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm @@ -187,67 +187,74 @@ sub moveAbs ## Up, Down, Left, Right, etc. ??? Doesn't make sense here... sub moveConUp { my $self = shift; Debug('Move Up'); + $$self{LastMove} = 'code=Up&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=Up&channel=0&arg1=0&arg2=1&arg3=0'); - usleep(500); ##XXX Should this be passed in as a "speed" parameter? - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Up&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); ##XXX Should this be passed in as a "speed" parameter? + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Up&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConDown { my $self = shift; Debug('Move Down'); + $$self{LastMove} = 'code=Down&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=Down&channel=0&arg1=0&arg2=1&arg3=0'); - usleep(500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Down&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Down&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConLeft { my $self = shift; Debug('Move Left'); + $$self{LastMove} = 'code=Left&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=Left&channel=0&arg1=0&arg2=1&arg3=0'); - usleep(500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Left&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Left&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConRight { my $self = shift; Debug('Move Right'); - # $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1=270&arg2=5&arg3=0' ); + $$self{LastMove} = 'code=Right&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=Right&channel=0&arg1=0&arg2=1&arg3=0'); - usleep(500); - Debug('Move Right Stop'); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Right&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #Debug('Move Right Stop'); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=Right&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConUpRight { my $self = shift; Debug('Move Diagonally Up Right'); + $$self{LastMove} = 'code=RightUp&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=RightUp&channel=0&arg1=1&arg2=1&arg3=0'); - usleep(500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=RightUp&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=RightUp&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConDownRight { my $self = shift; Debug('Move Diagonally Down Right'); + $$self{LastMove} = 'code=RightDown&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=RightDown&channel=0&arg1=1&arg2=1&arg3=0'); - usleep(500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=RightDown&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=RightDown&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConUpLeft { my $self = shift; Debug('Move Diagonally Up Left'); + $$self{LastMove} = 'code=LeftUp&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=LeftUp&channel=0&arg1=1&arg2=1&arg3=0'); - usleep(500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=LeftUp&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep(500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=LeftUp&channel=0&arg1=0&arg2=1&arg3=0'); } sub moveConDownLeft { my $self = shift; Debug('Move Diagonally Down Left'); + $$self{LastMove} = 'code=LeftDown&channel=0&arg1=0&arg2=1&arg3=0'; $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=LeftDown&channel=0&arg1=1&arg2=1&arg3=0'); - usleep (500); - $self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=LeftDown&channel=0&arg1=0&arg2=1&arg3=0'); + #usleep (500); + #$self->sendCmd('cgi-bin/ptz.cgi?action=stop&code=LeftDown&channel=0&arg1=0&arg2=1&arg3=0'); } # Stop is not "correctly" implemented as control_functions.php translates this to "Center" @@ -256,8 +263,14 @@ sub moveConDownLeft { sub moveStop { my $self = shift; - Debug('Move Stop/Center'); - $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1=0&arg2=0&arg3=0&arg4=1'); + if ($$self{LastMove}) { + Debug('Move Stop '.$$self{LastMove}); + $self->sendCmd('cgi-bin/ptz.cgi?action=stop&'.$$self{LastMove}); + $$self{LastMove} = ''; + } else { + Debug('Move Stop/Center'); + $self->sendCmd('cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1=0&arg2=0&arg3=0&arg4=1'); + } } # Move Camera to Home Position