public static void UpdateSerial(object sender, EventArgs e) { lock (Devices) { DS4Device device = (DS4Device)sender; if (device != null) { string devPath = device.HidDevice.DevicePath; string serial = device.MacAddress; if (Devices.ContainsKey(devPath)) { DeviceSerials.Remove(serial); device.UpdateSerial(); serial = device.MacAddress; if (DS4Device.IsValidSerial(serial)) { DeviceSerials.Add(serial); } if (device.ShouldRunCalib) { device.RefreshCalibration(); } } } } }
private static void OnAddSerial(HidDevice hDevice, VidPidInfo metainfo, string serial) { DS4Device ds4Device = new DS4Device(hDevice, metainfo.Name); //ds4Device.Removal += On_Removal; if (!ds4Device.ExitOutputThread) { Devices.Add(hDevice.DevicePath, ds4Device); DevicePaths.Add(hDevice.DevicePath); DeviceSerials.Add(serial); } }
public static void RemoveDevice(DS4Device device) { if (device is null) { return; } lock (Devices) { device.HidDevice.CloseDevice(); Devices.Remove(device.HidDevice.DevicePath); DevicePaths.Remove(device.HidDevice.DevicePath); DeviceSerials.Remove(device.MacAddress); } }
public static void StopControllers() { lock (Devices) { IEnumerable <DS4Device> devices = GetDS4Controllers(); foreach (DS4Device device in devices) { device.StopUpdate(); device.HidDevice.CloseDevice(); } Devices.Clear(); DevicePaths.Clear(); DeviceSerials.Clear(); DisabledDevices.Clear(); } }
private static void EvalHid(HidDevice hDevice) { if (IgnoreDevice(hDevice)) { return; } if (!hDevice.IsOpen) { OpenDevice(hDevice); } if (!hDevice.IsOpen) { return; } string serial = hDevice.ReadSerial(); if (DS4Device.IsValidSerial(serial)) { if (DeviceSerials.Contains(serial)) { OnSerialExists(hDevice); } else { try { VidPidInfo metainfo = KnownDevices.Single(x => x.Vid == hDevice.Attributes.VendorId && x.Pid == hDevice.Attributes.ProductId); if (metainfo != null) { OnAddSerial(hDevice, metainfo, serial); } } catch { // Single() may throw an exception } } } }