示例#1
0
        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();
                        }
                    }
                }
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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
                    }
                }
            }
        }