Dispose() защищенный Метод

Clean up any resources being used.
protected Dispose ( bool disposing ) : void
disposing bool
Результат void
Пример #1
0
 public override void Dispose()
 {
     if (instance != null)
     {
         instance.Dispose();
         instance = null;
     }
 }
Пример #2
0
 public void Dispose()
 {
     if (directInput != null)
     {
         directInput.Dispose();
     }
     if (joystick != null)
     {
         joystick.Dispose();
     }
 }
Пример #3
0
 private IInputDevice CreateDevice(DeviceInstance deviceInstance, List <string> uniqueIds)
 {
     try
     {
         if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid))
         {
             return(null);
         }
         var joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
         if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1)
         {
             joystick.Dispose();
             return(null);
         }
         bool   isHid         = deviceInstance.IsHumanInterfaceDevice;
         string interfacePath = null;
         string uniqueIdBase;
         string hardwareId = null;
         if (isHid)
         {
             if (ignoredDeviceService.IsIgnored(joystick.Properties.InterfacePath))
             {
                 joystick.Dispose();
                 return(null);
             }
             interfacePath = joystick.Properties.InterfacePath;
             uniqueIdBase  = interfacePath;
             hardwareId    = IdHelper.GetHardwareId(interfacePath);
         }
         else
         {
             uniqueIdBase = string.Join(":", deviceInstance.ProductGuid.ToString(), deviceInstance.InstanceGuid.ToString());
         }
         string uniqueId = IdHelper.GetUniqueId(uniqueIdBase);
         if (uniqueIds.Any(uid => uid == uniqueId))
         {
             notificationService.Add(Notifications.DirectInputInstanceIdDuplication, new[] { uniqueId }, NotificationTypes.Warning);
         }
         uniqueIds.Add(uniqueId);
         if (currentDevices.Any(d => d.UniqueId == uniqueId))
         {
             joystick.Dispose();
             return(null);
         }
         joystick.Properties.BufferSize = 128;
         return(new DirectInputDevice(inputConfigManager, joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName,
                                      deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, uniqueId, hardwareId, interfacePath));
     }
     catch (Exception ex)
     {
         logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString());
         return(null);
     }
 }
 public override void Stop()
 {
     if (joystick != null)
     {
         joystick.Dispose();
     }
     LogDebug("Stopping MCTelemetryProvider");
     isStopped = true;
     if (t != null)
     {
         t.Join();
     }
     controllerForm.Hide();
 }
Пример #5
0
 private void PollProcedure()
 {
     try
     {
         FindJoystick();
         PollJoystick();
     }
     catch (SharpDXException)
     {
         if (_joystick != null && !_joystick.IsDisposed)
         {
             _joystick.Dispose();
         }
     }
 }
Пример #6
0
        public void InitJoystick()
        {
            var inputDevice = directInput.GetDevices().SingleOrDefault(x => x.InstanceGuid == Properties.Settings.Default.InputDeviceGuid);

            if (inputDevice != null)
            {
                if (joystick != null)
                {
                    joystick.Unacquire();
                    joystick.Dispose();
                }
                joystick = new Joystick(directInput, inputDevice.InstanceGuid);
                joystick.Acquire();
            }
        }
Пример #7
0
        private void CheckPttDevice()
        {
            bool isPressed = false;

            switch (mPttConfiguration.DeviceType)
            {
            case PTTDeviceType.None:
                isPressed = false;
                break;

            case PTTDeviceType.Keyboard:
                isPressed = ((GetAsyncKeyState(mPttConfiguration.ButtonOrKey) & 32768) > 0);
                break;

            case PTTDeviceType.Joystick:
                if (mJoystick != null && mPttConfiguration.JoystickAcquired && mPttConfiguration.ButtonOrKey >= 0)
                {
                    try
                    {
                        JoystickState currentState = mJoystick.GetCurrentState();
                        bool[]        buttons      = currentState.Buttons;
                        try
                        {
                            isPressed = buttons[mPttConfiguration.ButtonOrKey];
                        }
                        catch (IndexOutOfRangeException)
                        {
                        }
                    }
                    catch (SharpDXException)
                    {
                        mPttConfiguration.JoystickAcquired = false;
                        if (mJoystick != null)
                        {
                            mJoystick.Unacquire();
                            mJoystick.Dispose();
                        }
                        mJoystick = null;
                    }
                }
                break;
            }
            if (isPressed != mPttStatus)
            {
                mPttStatus = isPressed;
                PushToTalkStateChanged?.Invoke(this, new PushToTalkStateChangedEventArgs(mPttStatus));
            }
        }
Пример #8
0
 private IInputDevice CreateDevice(DeviceInstance deviceInstance)
 {
     try
     {
         if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid))
         {
             return(null);
         }
         var joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
         if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1)
         {
             joystick.Dispose();
             return(null);
         }
         joystick.Properties.BufferSize = 128;
         var device = new DirectInputDevice(joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName,
                                            deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, deviceInstance.IsHumanInterfaceDevice);
         return(device);
     }
     catch (Exception ex)
     {
         logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString());
         return(null);
     }
 }
Пример #9
0
        private void GetControllers()
        {
            foreach (TextBox tbox in controllerGuids)
            {
                tbox.Clear();
            }

            foreach (TextBox tbox in controllerNicks)
            {
                tbox.Clear();
            }

            dinput = new DirectInput();
            IList <DeviceInstance> devices = dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);

            for (int i = 0; i < devices.Count; i++)
            {
                DeviceInstance device  = devices[i];
                Joystick       gamePad = new Joystick(dinput, device.InstanceGuid);
                string         hid     = gamePad.Properties.InterfacePath;
                int            start   = hid.IndexOf("hid#");
                int            end     = hid.LastIndexOf("#{");
                string         fhid    = hid.Substring(start, end - start).Replace('#', '\\').ToUpper();
                controllerGuids[i].Text = fhid;
                if (ini.IniReadValue("ControllerMapping", fhid) != "")
                {
                    controllerNicks[i].Text = ini.IniReadValue("ControllerMapping", fhid);
                }
                gamePad.Dispose();
            }
            dinput.Dispose();
        }
Пример #10
0
 private void AcquireJoystick()
 {
     if (mDirectInput.IsDeviceAttached(mPtmConfiguration.JoystickGuid))
     {
         try
         {
             mJoystick = new Joystick(mDirectInput, mPtmConfiguration.JoystickGuid);
             mJoystick.Acquire();
             mPtmConfiguration.JoystickAcquired = true;
             return;
         }
         catch (SharpDXException)
         {
             if (mJoystick != null)
             {
                 mJoystick.Unacquire();
                 mJoystick.Dispose();
             }
             mJoystick = null;
             return;
         }
     }
     mPtmConfiguration.JoystickAcquired = false;
     if (mJoystick != null)
     {
         mJoystick.Unacquire();
         mJoystick.Dispose();
     }
     mJoystick = null;
 }
 public void Dispose()
 {
     if (null != joystick)
     {
         joystick.Dispose();
     }
 }
Пример #12
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (_shouldDispose)
            {
                _i2cBus?.Dispose();
            }
            else
            {
                LedMatrix?.Dispose();
                LedMatrix = null !;

                Joystick?.Dispose();
                Joystick = null !;

                Gyroscope?.Dispose();
                Gyroscope = null !;

                Magnetometer?.Dispose();
                Magnetometer = null !;

                TemperatureAndHumidity?.Dispose();
                TemperatureAndHumidity = null !;

                PressureAndTemperature?.Dispose();
                PressureAndTemperature = null !;
            }

            _i2cBus = null !;
        }
Пример #13
0
        private void JoystickStop()
        {
            if (!IsEnabled)
            {
                return;
            }

            if (pollTimer != null)
            {
                pollTimer.Dispose();
            }

            // Joystick
            if (joystick != null)
            {
                joystick.Unacquire();
                joystick.Dispose();
                joystick      = null;
                joystickState = null;
            }

            inputSim = null;

            IsEnabled = false;
            if (componentsInitialized)
            {
                ///OLD CODE
                //enableExtensionButton.Text = "Enable Extension";
            }

            extension.SetIsRunning(false);
        }
Пример #14
0
 public void Acquire(Guid deviceGuid)
 {
     _joystick?.Dispose();
     _joystick = new Joystick(_input, deviceGuid);
     _joystick.Acquire();
     Log.InfoFormat("Acquired {0} with GUID {1}", _joystick.Information.ProductName, deviceGuid);
 }
Пример #15
0
 /// <inheritdoc />
 /// <summary>
 /// clean up
 /// </summary>
 public void Dispose()
 {
     Release();
     _settingsDict = null;
     joystick.Dispose();
     directInput.Dispose();
 }
Пример #16
0
        private bool disposedValue = false; // For Redundant Calls.

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (joystick != null)
                    {
                        StopCapture();
                        joystick.Dispose();
                    }

                    if (directInput != null)
                    {
                        directInput.Dispose();
                    }
                }

                joystick            = null;
                directInput         = null;
                pollingTask         = null;
                scanningDevicesTask = null;

                disposedValue = true;
            }
        }
Пример #17
0
        private void PopulateControllers()
        {
            if (_controllers != null)
            {
                ClearJoysticks();
            }

            _controllers = new Dictionary <string, Joystick>();
            DirectInput directInput = new DirectInput();

            int index = 1;

            foreach (DeviceInstance deviceInstance in directInput.GetDevices())
            {
                Joystick device = new Joystick(directInput, deviceInstance.InstanceGuid);
                if ((device.Information.ProductGuid.ToString() == "028e045e-0000-0000-0000-504944564944") ||                            // Emulated controller
                    (device.Capabilities.ButtonCount < 1 || device.Capabilities.AxesCount < 1) ||                                       // No axes or buttons
                    (device.Information.Type != DeviceType.Gamepad && device.Information.UsageId != SlimDX.Multimedia.UsageId.Gamepad)) // Not a gamepad
                {
                    device.Dispose();
                    continue;
                }

                _controllers.Add("[" + index + "] " + device.Information.ProductName, device);
            }
            directInput.Dispose();

            cboControllers.DataSource    = new BindingSource(_controllers, null);
            cboControllers.DisplayMember = "Key";
            cboControllers.ValueMember   = "Value";
        }
Пример #18
0
 public void Dispose()
 {
     if (joystick != null)
     {
         joystick.Dispose();
     }
 }
Пример #19
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (comboBoxInputList.SelectedIndex < 0)
            {
                labelConnectedDevice.Text = "None";
                return;
            }


            // If its already running, kill it and reattach
            if (pollThread != null && pollThread.IsAlive)
            {
                pollThread.Abort();
                joystick.Unacquire();
                joystick.Dispose();
            }

            joystick = new Joystick(directInput, devices.FirstOrDefault(x => x.Value == comboBoxInputList.SelectedItem.ToString()).Key);

            var allEffects = joystick.GetEffects();

            foreach (var effectInfo in allEffects)
            {
                Console.WriteLine("Effect available {0}", effectInfo.Name);
            }

            joystick.Properties.BufferSize = 128;
            joystick.Acquire();

            labelConnectedDevice.Text = comboBoxInputList.SelectedItem.ToString();

            pollThread = new Thread(joystickPoll);
            pollThread.IsBackground = true;
            pollThread.Start();
        }
Пример #20
0
 public void Dispose()
 {
     if (device != null)
     {
         device.Unacquire();
         device.Dispose();
     }
 }
Пример #21
0
        private void ConfigEditDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            directInput?.Dispose();
            directInput = null;

            inputDevice?.Dispose();
            inputDevice = null;
        }
Пример #22
0
        private void GetControllers()
        {
            foreach (TextBox tbox in controllerGuids)
            {
                tbox.Clear();
            }

            foreach (TextBox tbox in controllerNicks)
            {
                tbox.Clear();
            }


            dinput = new DirectInput();
            IList <DeviceInstance> devices = dinput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly);
            int gcDevicesCnt = devices.Count;

            for (int i = 0; i < devices.Count; i++)
            {
                DeviceInstance device  = devices[i];
                Joystick       gamePad = new Joystick(dinput, device.InstanceGuid);
                string         hid     = gamePad.Properties.InterfacePath;
                int            start   = hid.IndexOf("hid#");
                int            end     = hid.LastIndexOf("#{");
                string         fhid    = hid.Substring(start, end - start).Replace('#', '\\').ToUpper();
                controllerGuids[i].Text = fhid;
                if (ini.IniReadValue("ControllerMapping", fhid) != "")
                {
                    controllerNicks[i].Text = ini.IniReadValue("ControllerMapping", fhid);
                }
                gamePad.Dispose();
            }
            dinput.Dispose();


            foreach (var device in RawInputManager.GetDeviceList().Where(x => x.deviceInfo.dwType <= 1))
            {
                //string hid = device.deviceInfo.hid.ToString();
                //int start = hid.IndexOf("hid#");
                //int end = hid.LastIndexOf("#{");
                //string fhid = hid.Substring(start, end - start).Replace('#', '\\').ToUpper();

                //controllerGuids[gcDevicesCnt].Text = fhid;
                string did = string.Empty;
                if (device.deviceInfo.dwType == 0)
                {
                    did = "T" + device.deviceInfo.dwType + "PID" + device.deviceInfo.hid.dwProductId + "VID" + device.deviceInfo.hid.dwVendorId + "VN" + device.deviceInfo.hid.dwVersionNumber;
                    controllerGuids[gcDevicesCnt].Text = did;
                    gcDevicesCnt++;
                }


                if (ini.IniReadValue("ControllerMapping", did) != "")
                {
                    controllerNicks[gcDevicesCnt].Text = ini.IniReadValue("ControllerMapping", did);
                }
            }
        }
Пример #23
0
        /// <summary>
        /// Rescan for new controllers
        /// </summary>
        public void getMoreControllers(Game game)
        {
            Joystick temp = null;

            bool alreadyAquired = false;

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                alreadyAquired = false;

                // create the device
                try
                {
                    temp = new Joystick(dinput, device.InstanceGuid);

                    //Check to see if the controller is already set
                    foreach (Joystick joyS in joysitcks)
                    {
                        if (joyS == null)
                        {
                            break;
                        }

                        if (joyS.Equals(temp))
                        {
                            alreadyAquired = true;
                        }
                    }

                    if (alreadyAquired)
                    {
                        temp.Dispose();
                        continue;
                    }

                    temp.SetCooperativeLevel(game.Window.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);

                    foreach (DeviceObjectInstance deviceObject in temp.GetObjects())
                    {
                        if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                        {
                            temp.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                        }
                    }

                    // acquire the device

                    temp.Acquire();

                    joysitcks.Add(temp);
                }
                catch (DirectInputException)
                {
                    //Error not handled
                }
            }
        }
Пример #24
0
 public static void disconnectJoystick()
 {
     if (joystick != null)
     {
         joystick.Unacquire();
         joystick.Dispose();
     }
     joystick = null;
 }
Пример #25
0
 public void Dispose()
 {
     if (joystick != null)
     {
         joystick.Unacquire();
         joystick.Dispose();
     }
     joystick = null;
 }
Пример #26
0
 /// <summary>
 /// Releases the FFB device and cleans up.
 /// </summary>
 public void ReleaseAll()
 {
     if (ffbDevice != null)
     {
         ffbDevice.Unacquire();
         ffbDevice.Dispose();
         ffbDevice = null;
     }
 }
Пример #27
0
 /// <summary>
 /// If the input device is no longer available, it is released.
 /// </summary>
 public void Release()
 {
     if (_joystick != null)
     {
         _joystick.Unacquire();
         _joystick.Dispose();
     }
     _joystick = null;
 }
Пример #28
0
 /// <summary>
 /// Method called when the joystick polling method eithor is done, cancled, or exception
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void OnWorkerStop(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         Logging.LogConsole("Joystick thread was stopped", true);
     }
     Joystick.Dispose();
     Joystick = null;
 }
Пример #29
0
        public void Dispose()
        {
            if (_Joystick != null)
            {
                _Joystick.Dispose();
            }

            _State = null;
            _DInput.Dispose();
        }
Пример #30
0
        ///
        /// Release joystick
        ///
        public void Release()
        {
            if (Joystick != null)
            {
                Joystick.Unacquire();
                Joystick.Dispose();
            }

            Joystick = null;
        }
Пример #31
0
 void ReleaseDevice(Joystick j)
 {
     timerJoystickRead.Stop();
     if (j != null)
     {
         try
         {
             j.Unacquire();
             j.Dispose();
         }
         catch { }
     }
     j = null;
 }