mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Adds SpeedTimer implmentation to CameraVisca
This commit is contained in:
@@ -92,8 +92,6 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IHasCameraPanControl : IHasCameraControls
|
public interface IHasCameraPanControl : IHasCameraControls
|
||||||
{
|
{
|
||||||
// void PanLeft(bool pressRelease);
|
|
||||||
// void PanRight(bool pressRelease);
|
|
||||||
void PanLeft();
|
void PanLeft();
|
||||||
void PanRight();
|
void PanRight();
|
||||||
void PanStop();
|
void PanStop();
|
||||||
@@ -104,8 +102,6 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IHasCameraTiltControl : IHasCameraControls
|
public interface IHasCameraTiltControl : IHasCameraControls
|
||||||
{
|
{
|
||||||
// void TiltDown(bool pressRelease);
|
|
||||||
// void TildUp(bool pressRelease);
|
|
||||||
void TiltDown();
|
void TiltDown();
|
||||||
void TiltUp();
|
void TiltUp();
|
||||||
void TiltStop();
|
void TiltStop();
|
||||||
@@ -116,8 +112,6 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IHasCameraZoomControl : IHasCameraControls
|
public interface IHasCameraZoomControl : IHasCameraControls
|
||||||
{
|
{
|
||||||
// void ZoomIn(bool pressRelease);
|
|
||||||
// void ZoomOut(bool pressRelease);
|
|
||||||
void ZoomIn();
|
void ZoomIn();
|
||||||
void ZoomOut();
|
void ZoomOut();
|
||||||
void ZoomStop();
|
void ZoomStop();
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
/// Used to determine when to move the camera at a faster speed if a direction is held
|
/// Used to determine when to move the camera at a faster speed if a direction is held
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer SpeedTimer;
|
CTimer SpeedTimer;
|
||||||
|
// TODO: Implment speed timer for PTZ controls
|
||||||
|
|
||||||
long FastSpeedHoldTimeMs = 2000;
|
long FastSpeedHoldTimeMs = 2000;
|
||||||
|
|
||||||
@@ -342,18 +343,72 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendPanTiltCommand (byte[] cmd)
|
/// <summary>
|
||||||
|
/// Sends a pan/tilt command. If the command is not for fastSpeed then it starts a timer to initiate fast speed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
/// <param name="fastSpeed"></param>
|
||||||
|
private void SendPanTiltCommand (byte[] cmd, bool fastSpeedEnabled)
|
||||||
{
|
{
|
||||||
var temp = new byte[] { ID, 0x01, 0x06, 0x01, PanSpeedSlow, TiltSpeedSlow };
|
SendBytes(GetPanTiltCommand(cmd, fastSpeedEnabled));
|
||||||
int length = temp.Length + cmd.Length + 1;
|
|
||||||
|
if (!fastSpeedEnabled)
|
||||||
|
{
|
||||||
|
if (SpeedTimer != null)
|
||||||
|
{
|
||||||
|
StopSpeedTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the timer to send fast speed if still moving after FastSpeedHoldTime elapses
|
||||||
|
SpeedTimer = new CTimer((o) => SendPanTiltCommand(GetPanTiltCommand(cmd, true), true), FastSpeedHoldTimeMs);
|
||||||
|
}
|
||||||
|
|
||||||
byte[] sum = new byte[length];
|
|
||||||
temp.CopyTo(sum, 0);
|
|
||||||
cmd.CopyTo(sum, temp.Length);
|
|
||||||
sum[length - 1] = 0xFF;
|
|
||||||
SendBytes(sum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void StopSpeedTimer()
|
||||||
|
{
|
||||||
|
if (SpeedTimer != null)
|
||||||
|
{
|
||||||
|
SpeedTimer.Stop();
|
||||||
|
SpeedTimer.Dispose();
|
||||||
|
SpeedTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the pan/tilt command with either slow or fast speed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
/// <param name="fastSpeed"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private byte[] GetPanTiltCommand(byte[] cmd, bool fastSpeed)
|
||||||
|
{
|
||||||
|
byte panSpeed;
|
||||||
|
byte tiltSpeed;
|
||||||
|
|
||||||
|
if (!fastSpeed)
|
||||||
|
{
|
||||||
|
panSpeed = PanSpeedSlow;
|
||||||
|
tiltSpeed = TiltSpeedSlow;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panSpeed = PanSpeedFast;
|
||||||
|
tiltSpeed = TiltSpeedFast;
|
||||||
|
}
|
||||||
|
|
||||||
|
var temp = new byte[] { ID, 0x01, 0x06, 0x01, panSpeed, tiltSpeed };
|
||||||
|
int length = temp.Length + cmd.Length + 1;
|
||||||
|
|
||||||
|
byte[] sum = new byte[length];
|
||||||
|
temp.CopyTo(sum, 0);
|
||||||
|
cmd.CopyTo(sum, temp.Length);
|
||||||
|
sum[length - 1] = 0xFF;
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SendPowerQuery()
|
void SendPowerQuery()
|
||||||
{
|
{
|
||||||
SendBytes(new byte[] { ID, 0x09, 0x04, 0x00, 0xFF });
|
SendBytes(new byte[] { ID, 0x09, 0x04, 0x00, 0xFF });
|
||||||
@@ -397,16 +452,14 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
PowerOn();
|
PowerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void PanLeft()
|
public void PanLeft()
|
||||||
{
|
{
|
||||||
SendPanTiltCommand(new byte[] {0x01, 0x03});
|
SendPanTiltCommand(new byte[] {0x01, 0x03}, false);
|
||||||
IsMoving = true;
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
public void PanRight()
|
public void PanRight()
|
||||||
{
|
{
|
||||||
SendPanTiltCommand(new byte[] { 0x02, 0x03 });
|
SendPanTiltCommand(new byte[] { 0x02, 0x03 }, false);
|
||||||
IsMoving = true;
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
public void PanStop()
|
public void PanStop()
|
||||||
@@ -415,12 +468,12 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
}
|
}
|
||||||
public void TiltDown()
|
public void TiltDown()
|
||||||
{
|
{
|
||||||
SendPanTiltCommand(new byte[] { 0x03, 0x02 });
|
SendPanTiltCommand(new byte[] { 0x03, 0x02 }, false);
|
||||||
IsMoving = true;
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
public void TiltUp()
|
public void TiltUp()
|
||||||
{
|
{
|
||||||
SendPanTiltCommand(new byte[] { 0x03, 0x01 });
|
SendPanTiltCommand(new byte[] { 0x03, 0x01 }, false);
|
||||||
IsMoving = true;
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
public void TiltStop()
|
public void TiltStop()
|
||||||
@@ -432,6 +485,8 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
{
|
{
|
||||||
SendBytes(new byte[] {ID, 0x01, 0x04, 0x07, cmd, 0xFF} );
|
SendBytes(new byte[] {ID, 0x01, 0x04, 0x07, cmd, 0xFF} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ZoomIn()
|
public void ZoomIn()
|
||||||
{
|
{
|
||||||
SendZoomCommand(ZoomInCmd);
|
SendZoomCommand(ZoomInCmd);
|
||||||
@@ -456,7 +511,8 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SendPanTiltCommand(new byte[] {0x03, 0x03});
|
StopSpeedTimer();
|
||||||
|
SendPanTiltCommand(new byte[] { 0x03, 0x03 }, false);
|
||||||
IsMoving = false;
|
IsMoving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user