public void SendPTZCommand(Enums.PtzCommand command, bool wait) { if (_cameraControl.Camera == null) { return; } PTZSettings2Camera ptz = MainForm.PTZs.SingleOrDefault(q => q.id == _cameraControl.Camobject.ptz); bool d = (ptz == null || ptz.Commands == null); if (!d) { if (command == Enums.PtzCommand.ZoomIn) { if (String.IsNullOrEmpty(ptz.Commands.ZoomIn)) { d = true; } } if (command == Enums.PtzCommand.ZoomOut) { if (String.IsNullOrEmpty(ptz.Commands.ZoomOut)) { d = true; } } } if (!d) { _cameraControl.CalibrateCount = 0; _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI / 4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3 * Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; case Enums.PtzCommand.ZoomIn: SendPTZCommand(ptz.Commands.ZoomIn, wait); break; case Enums.PtzCommand.ZoomOut: SendPTZCommand(ptz.Commands.ZoomOut, wait); break; case Enums.PtzCommand.Center: SendPTZCommand(ptz.Commands.Center, wait); break; case Enums.PtzCommand.Stop: SendPTZCommand(ptz.Commands.Stop, wait); break; } } else { Rectangle r = _cameraControl.Camera.ViewRectangle; if (r != Rectangle.Empty) { if (command == Enums.PtzCommand.ZoomOut || command == Enums.PtzCommand.ZoomIn) { _cameraControl.Camera.ZPoint = new Point(r.Left + r.Width / 2, r.Top + r.Height / 2); } double angle = 0; bool isangle = true; switch (command) { case Enums.PtzCommand.Left: angle = 0; break; case Enums.PtzCommand.Upleft: angle = Math.PI / 4; break; case Enums.PtzCommand.Up: angle = Math.PI / 2; break; case Enums.PtzCommand.UpRight: angle = 3 * Math.PI / 4; break; case Enums.PtzCommand.Right: angle = Math.PI; break; case Enums.PtzCommand.DownRight: angle = -3 * Math.PI / 4; break; case Enums.PtzCommand.Down: angle = -Math.PI / 2; break; case Enums.PtzCommand.DownLeft: angle = -Math.PI / 4; break; case Enums.PtzCommand.ZoomIn: isangle = false; _cameraControl.Camera.ZFactor += 0.2f; break; case Enums.PtzCommand.ZoomOut: isangle = false; _cameraControl.Camera.ZFactor -= 0.2f; if (_cameraControl.Camera.ZFactor < 1) { _cameraControl.Camera.ZFactor = 1; } break; case Enums.PtzCommand.Center: isangle = false; _cameraControl.Camera.ZFactor = 1; break; } if (isangle) { _cameraControl.Camera.ZPoint.X -= Convert.ToInt32(15 * Math.Cos(angle)); _cameraControl.Camera.ZPoint.Y -= Convert.ToInt32(15 * Math.Sin(angle)); } } } }
private void ProcessPtzInput(Point p) { if (CameraControl.Camera == null) { return; } bool d = MainForm.PTZs.SingleOrDefault(q => q.id == CameraControl.Camobject.ptz) == null; Enums.PtzCommand comm = Enums.PtzCommand.Center; if (p.X < 60 && p.Y > 60 && p.Y < 106) { comm = Enums.PtzCommand.Left; } if (p.X < 60 && p.Y < 60) { comm = Enums.PtzCommand.Upleft; } if (p.X > 60 && p.X < 104 && p.Y < 60) { comm = Enums.PtzCommand.Up; } if (p.X > 104 && p.X < 164 && p.Y < 60) { comm = Enums.PtzCommand.UpRight; } if (p.X > 104 && p.X < 170 && p.Y > 60 && p.Y < 104) { comm = Enums.PtzCommand.Right; } if (p.X > 104 && p.X < 170 && p.Y > 104) { comm = Enums.PtzCommand.DownRight; } if (p.X > 60 && p.X < 104 && p.Y > 104) { comm = Enums.PtzCommand.Down; } if (p.X < 60 && p.Y > 104) { comm = Enums.PtzCommand.DownLeft; } if (p.X > 170 && p.Y < 45) { comm = Enums.PtzCommand.ZoomIn; if (!d) { PTZSettings2Camera ptz = MainForm.PTZs.SingleOrDefault(q => q.id == CameraControl.Camobject.ptz); if (ptz == null || String.IsNullOrEmpty(ptz.Commands.ZoomIn)) { d = true; } } } if (p.X > 170 && p.Y > 45 && p.Y < 90) { comm = Enums.PtzCommand.ZoomOut; if (!d) { PTZSettings2Camera ptz = MainForm.PTZs.SingleOrDefault(q => q.id == CameraControl.Camobject.ptz); if (ptz == null || String.IsNullOrEmpty(ptz.Commands.ZoomIn)) //use zoomin just in case zoomout is defined and zoomin isn't { d = true; } } } if (d) { Rectangle r = CameraControl.Camera.ViewRectangle; if (r != Rectangle.Empty) { if (comm == Enums.PtzCommand.ZoomOut || comm == Enums.PtzCommand.ZoomIn) { CameraControl.Camera.ZPoint = new Point(r.Left + r.Width / 2, r.Top + r.Height / 2); } double angle = 0; bool isangle = true; switch (comm) { case Enums.PtzCommand.Left: angle = 0; break; case Enums.PtzCommand.Upleft: angle = Math.PI / 4; break; case Enums.PtzCommand.Up: angle = Math.PI / 2; break; case Enums.PtzCommand.UpRight: angle = 3 * Math.PI / 4; break; case Enums.PtzCommand.Right: angle = Math.PI; break; case Enums.PtzCommand.DownRight: angle = -3 * Math.PI / 4; break; case Enums.PtzCommand.Down: angle = -Math.PI / 2; break; case Enums.PtzCommand.DownLeft: angle = -Math.PI / 4; break; case Enums.PtzCommand.ZoomIn: isangle = false; CameraControl.Camera.ZFactor += 0.2f; break; case Enums.PtzCommand.ZoomOut: isangle = false; CameraControl.Camera.ZFactor -= 0.2f; if (CameraControl.Camera.ZFactor < 1) { CameraControl.Camera.ZFactor = 1; } break; case Enums.PtzCommand.Center: isangle = false; CameraControl.Camera.ZFactor = 1; break; } if (isangle) { CameraControl.Camera.ZPoint.X -= Convert.ToInt32(15 * Math.Cos(angle)); CameraControl.Camera.ZPoint.Y -= Convert.ToInt32(15 * Math.Sin(angle)); } } } else { CameraControl.PTZ.SendPTZCommand(comm, false); } }
public void SendPTZCommand(Enums.PtzCommand command) { SendPTZCommand(command, false); }
public void SendPTZCommand(Enums.PtzCommand command, bool wait) { if (_cameraControl.Camera == null) return; PTZSettings2Camera ptz = null; switch (_cameraControl.Camobject.ptz) { case -1://digital only break; case -2://IAM _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0d); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI / 4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3 * Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; default: ProcessIAM(command); break; } return; case -3://PELCO-P _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0d); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI / 4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3 * Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; default: ProcessPelco(command, true); break; } return; case -4://PELCO-D _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0d); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI / 4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3 * Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; default: ProcessPelco(command, false); break; } return; case -5://ONVIF _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0d); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI / 4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3 * Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; default: ProcessOnvif(command); break; } return; case -6: return; default: //IP CAMERA ptz = MainForm.PTZs.SingleOrDefault(q => q.id == _cameraControl.Camobject.ptz); break; } bool d = (ptz?.Commands == null); if (!d) { if (command == Enums.PtzCommand.ZoomIn) { if (string.IsNullOrEmpty(ptz.Commands.ZoomIn)) d = true; } if (command == Enums.PtzCommand.ZoomOut) { if (string.IsNullOrEmpty(ptz.Commands.ZoomOut)) d = true; } } if (!d) { _cameraControl.Calibrating = true; switch (command) { case Enums.PtzCommand.Left: SendPTZDirection(0d); break; case Enums.PtzCommand.Upleft: SendPTZDirection(Math.PI/4); break; case Enums.PtzCommand.Up: SendPTZDirection(Math.PI / 2); break; case Enums.PtzCommand.UpRight: SendPTZDirection(3 * Math.PI / 4); break; case Enums.PtzCommand.Right: SendPTZDirection(Math.PI); break; case Enums.PtzCommand.DownRight: SendPTZDirection(-3*Math.PI / 4); break; case Enums.PtzCommand.Down: SendPTZDirection(-Math.PI / 2); break; case Enums.PtzCommand.DownLeft: SendPTZDirection(-Math.PI / 4); break; case Enums.PtzCommand.ZoomIn: SendPTZCommand(ptz.Commands.ZoomIn, wait); break; case Enums.PtzCommand.ZoomOut: SendPTZCommand(ptz.Commands.ZoomOut, wait); break; case Enums.PtzCommand.Center: SendPTZCommand(ptz.Commands.Center, wait); break; case Enums.PtzCommand.Stop: if (_previousCommand == Enums.PtzCommand.ZoomIn) { if (!string.IsNullOrEmpty(ptz.Commands.ZoomInStop)) { SendPTZCommand(ptz.Commands.ZoomInStop, wait); break; } } if (_previousCommand == Enums.PtzCommand.ZoomOut) { if (!string.IsNullOrEmpty(ptz.Commands.ZoomOutStop)) { SendPTZCommand(ptz.Commands.ZoomOutStop, wait); break; } } SendPTZCommand(ptz.Commands.Stop, wait); break; } _previousCommand = command; } else { Rectangle r = _cameraControl.Camera.ViewRectangle; if (r != Rectangle.Empty) { double angle = 0; bool isangle = true; switch (command) { case Enums.PtzCommand.Left: angle = 0; break; case Enums.PtzCommand.Upleft: angle = Math.PI / 4; break; case Enums.PtzCommand.Up: angle = Math.PI / 2; break; case Enums.PtzCommand.UpRight: angle = 3 * Math.PI / 4; break; case Enums.PtzCommand.Right: angle = Math.PI; break; case Enums.PtzCommand.DownRight: angle = -3 * Math.PI / 4; break; case Enums.PtzCommand.Down: angle = -Math.PI / 2; break; case Enums.PtzCommand.DownLeft: angle = -Math.PI / 4; break; case Enums.PtzCommand.ZoomIn: isangle = false; _cameraControl.Camera.ZFactor += 0.2f; break; case Enums.PtzCommand.ZoomOut: isangle = false; var f = _cameraControl.Camera.ZFactor; f -= 0.2f; if (f < 1) f = 1; _cameraControl.Camera.ZFactor = f; break; case Enums.PtzCommand.Center: isangle = false; _cameraControl.Camera.ZFactor = 1; break; case Enums.PtzCommand.Stop: isangle = false; break; } if (isangle) { var p = _cameraControl.Camera.ZPoint; p.X -= Convert.ToInt32(15 * Math.Cos(angle)); p.Y -= Convert.ToInt32(15 * Math.Sin(angle)); _cameraControl.Camera.ZPoint = p; } } } }