Beispiel #1
0
        private void CheckJoystick()
        {
            if (_jst != null)
            {
                _jst.UpdateStatus();

                CameraWindow cw = null;
                VolumeLevel  vl = null;

                foreach (Control c in _pnlCameras.Controls)
                {
                    if (c.Focused)
                    {
                        cw = c as CameraWindow;
                        vl = c as VolumeLevel;
                        break;
                    }
                }

                for (int i = 0; i < _jst.Buttons.Length; i++)
                {
                    if (_jst.Buttons[i] != _buttonsLast[i] && _jst.Buttons[i])
                    {
                        int j = i + 1;

                        if (j == Conf.Joystick.Listen)
                        {
                            if (cw?.VolumeControl != null)
                            {
                                cw.VolumeControl.Listening = !cw.VolumeControl.Listening;
                            }
                            if (vl != null)
                            {
                                vl.Listening = !vl.Listening;
                            }
                        }

                        if (j == Conf.Joystick.Talk)
                        {
                            if (cw != null)
                            {
                                cw.Talking = !cw.Talking;
                                TalkTo(cw, cw.Talking);
                            }
                        }

                        if (j == Conf.Joystick.Previous)
                        {
                            ProcessKey("previous_control");
                        }

                        if (j == Conf.Joystick.Next)
                        {
                            ProcessKey("next_control");
                        }

                        if (j == Conf.Joystick.Play)
                        {
                            ProcessKey("play");
                        }

                        if (j == Conf.Joystick.Stop)
                        {
                            ProcessKey("stop");
                        }

                        if (j == Conf.Joystick.Record)
                        {
                            ProcessKey("record");
                        }

                        if (j == Conf.Joystick.Snapshot)
                        {
                            cw?.SaveFrame();
                        }

                        if (j == Conf.Joystick.MaxMin)
                        {
                            ProcessKey("maxmin");
                        }
                    }

                    _buttonsLast[i] = _jst.Buttons[i];
                }

                if (cw != null)
                {
                    _sentdirection = false;
                    int x = 0, y = 0;

                    double angle = -1000;

                    if (Conf.Joystick.XAxis < 0)
                    {
                        //dpad - handles x and y
                        int dpad = _jst.Dpads[(0 - Conf.Joystick.XAxis) - 1];
                        switch (dpad)
                        {
                        case 27000:
                            angle = 0;
                            break;

                        case 31500:
                            angle = Math.PI / 4;
                            break;

                        case 0:
                            angle = Math.PI / 2;
                            break;

                        case 4500:
                            angle = 3 * Math.PI / 4;
                            break;

                        case 9000:
                            angle = Math.PI;
                            break;

                        case 13500:
                            angle = -3 * Math.PI / 4;
                            break;

                        case 18000:
                            angle = -Math.PI / 2;
                            break;

                        case 22500:
                            angle = -Math.PI / 4;
                            break;
                        }
                    }
                    else
                    {
                        if (Conf.Joystick.XAxis > 0)
                        {
                            x = _jst.Axis[Conf.Joystick.XAxis - 1] - Conf.Joystick.CenterXAxis;
                        }

                        if (Conf.Joystick.YAxis > 0)
                        {
                            y = _jst.Axis[Conf.Joystick.YAxis - 1] - Conf.Joystick.CenterYAxis;
                        }

                        var d = Math.Sqrt((x * x) + (y * y));
                        if (d > 20)
                        {
                            angle = Math.Atan2(y, x);
                        }
                    }

                    if (angle > -1000)
                    {
                        if (Conf.Joystick.InvertYAxis)
                        {
                            angle = 0 - angle;
                        }
                        if (Conf.Joystick.InvertXAxis)
                        {
                            if (angle >= 0)
                            {
                                angle = Math.PI - angle;
                            }
                            else
                            {
                                angle = (0 - Math.PI) - angle;
                            }
                        }

                        cw.Calibrating = true;
                        cw.PTZ.SendPTZDirection(angle);
                        if (!cw.PTZ.DigitalPTZ)
                        {
                            _needstop = _sentdirection = true;
                        }
                    }

                    if (Conf.Joystick.ZAxis > 0)
                    {
                        var z = _jst.Axis[Conf.Joystick.ZAxis - 1] - Conf.Joystick.CenterZAxis;

                        if (Math.Abs(z) > 20)
                        {
                            if (Conf.Joystick.InvertZAxis)
                            {
                                z = 0 - z;
                            }
                            cw.Calibrating = true;
                            cw.PTZ.SendPTZCommand(z > 0 ? Enums.PtzCommand.ZoomIn : Enums.PtzCommand.ZoomOut);

                            if (!cw.PTZ.DigitalZoom)
                            {
                                _needstop = _sentdirection = true;
                            }
                        }
                    }

                    if (!_sentdirection && _needstop)
                    {
                        cw.PTZ.SendPTZCommand(Enums.PtzCommand.Stop);
                        _needstop = false;
                    }
                }
            }
        }