コード例 #1
0
        /// <summary>
        /// Implement reccomended best practice dispose pattern
        /// http://msdn.microsoft.com/en-us/library/b1yfkh5e%28v=vs.110%29.aspx
        /// </summary>
        /// <param name="disposing"></param>
        virtual protected void Dispose(bool disposing)
        {
            try
            {
                //not sure if this is a problem from the finalizer?
                if (disposing && joystick != null && joystick.Properties != null)
                {
                    joystick.Unacquire();
                }
            }
            catch
            {
            }

            try
            {
                if (disposing && joystick != null)
                {
                    joystick.Dispose();
                }
            }
            catch
            {
            }

            //tell gc not to call finalize, this object will be GC'd quicker now.
            GC.SuppressFinalize(this);
        }
コード例 #2
0
 public void Dispose()
 {
     if (stick != null)
     {
         stick.Unacquire();
         stick.Dispose();
         stick = null;
     }
 }
コード例 #3
0
        void Joystick_Poll(object Sender, EventArgs e)
        {
            if (joystickGuid != Guid.Empty)
            {
                if (!directInput.IsDeviceAttached(joystickGuid))
                {
                    joystick.Dispose();
                    joystick     = null;
                    joystickGuid = Guid.Empty;
                    joystickEnable.Dispatcher.Invoke(() =>
                    {
                        joystickEnable.IsChecked = false;
                        joystickEnable.IsEnabled = false;
                    });
                }
            }

            JoystickState state = null;

            if (joystick != null)
            {
                joystick.Poll();
                state = joystick.GetCurrentState();
            }
            if (state != null)
            {
                if (joystic_enabled)
                {
                    if (state.Buttons[6])
                    {
                        btnZoomIn_Click(null, null);
                    }
                    else if (state.Buttons[4])
                    {
                        btnZoomOut_Click(null, null);
                    }

                    if (state.Buttons[2] && !prevCamSwitchState)
                    {
                        prevCamSwitchState = true;
                        if (currentCamera == CameraSource.RGB_CAMERA_SOURCE)
                        {
                            setCameraVideoSource(CameraSource.IR_CAMERA_SOURCE);
                        }
                        else if (currentCamera == CameraSource.IR_CAMERA_SOURCE)
                        {
                            setCameraVideoSource(CameraSource.RGB_CAMERA_SOURCE);
                        }
                    }
                    else if (!state.Buttons[2])
                    {
                        prevCamSwitchState = false;
                    }

                    if (currentMode == GimbalMode.MODE_RATE)
                    {
                        double pitch_cmd = 0.0;
                        double yaw_cmd   = 0.0;
                        if (Math.Abs(state.Y - 32768) > 30)
                        {
                            pitch_cmd = ((state.Y - 32768.0) / 65536.0 * -2.0) * 3.14 / 2;
                        }
                        else
                        {
                            pitch_cmd = 0.0;
                        }
                        if (Math.Abs(state.X - 32768) > 30)
                        {
                            yaw_cmd = ((state.X - 32768.0) / 65536.0 * -2.0) * 3.14 / 2;
                        }
                        else
                        {
                            yaw_cmd = 0.0;
                        }
                        sendGimbalCommand(pitch_cmd, 0.0, yaw_cmd);
                    }
                }
            }
        }
コード例 #4
0
 public bool Close()
 {
     dxJoystick.Dispose();
     dxJoystick = null;
     return(true);
 }