protected Dispose ( bool disposing ) : void | ||
disposing | bool | |
Résultat | void |
public override void Dispose() { if (instance != null) { instance.Dispose(); instance = null; } }
public void Dispose() { if (directInput != null) { directInput.Dispose(); } if (joystick != null) { joystick.Dispose(); } }
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(); }
private void PollProcedure() { try { FindJoystick(); PollJoystick(); } catch (SharpDXException) { if (_joystick != null && !_joystick.IsDisposed) { _joystick.Dispose(); } } }
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(); } }
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)); } }
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); } }
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(); }
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(); } }
/// <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 !; }
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); }
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); }
/// <inheritdoc /> /// <summary> /// clean up /// </summary> public void Dispose() { Release(); _settingsDict = null; joystick.Dispose(); directInput.Dispose(); }
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; } }
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"; }
public void Dispose() { if (joystick != null) { joystick.Dispose(); } }
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(); }
public void Dispose() { if (device != null) { device.Unacquire(); device.Dispose(); } }
private void ConfigEditDialog_FormClosing(object sender, FormClosingEventArgs e) { directInput?.Dispose(); directInput = null; inputDevice?.Dispose(); inputDevice = null; }
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); } } }
/// <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 } } }
public static void disconnectJoystick() { if (joystick != null) { joystick.Unacquire(); joystick.Dispose(); } joystick = null; }
public void Dispose() { if (joystick != null) { joystick.Unacquire(); joystick.Dispose(); } joystick = null; }
/// <summary> /// Releases the FFB device and cleans up. /// </summary> public void ReleaseAll() { if (ffbDevice != null) { ffbDevice.Unacquire(); ffbDevice.Dispose(); ffbDevice = null; } }
/// <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; }
/// <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; }
public void Dispose() { if (_Joystick != null) { _Joystick.Dispose(); } _State = null; _DInput.Dispose(); }
/// /// Release joystick /// public void Release() { if (Joystick != null) { Joystick.Unacquire(); Joystick.Dispose(); } Joystick = null; }
void ReleaseDevice(Joystick j) { timerJoystickRead.Stop(); if (j != null) { try { j.Unacquire(); j.Dispose(); } catch { } } j = null; }