示例#1
0
        protected override void OnLookup()
        {
            var instanceId = 0;

            while (Devcon.Find(FireShockDevice.ClassGuid, out var path, out var instance, instanceId++))
            {
                if (ChildDevices.Any(h => h.DevicePath.Equals(path)))
                {
                    continue;
                }

                Log.Information("Found FireShock device {Path} ({Instance})", path, instance);

                var device = FireShockDevice.CreateDevice(path, ChildDevices.Count);

                device.DeviceDisconnected += (sender, args) =>
                {
                    var dev = (FireShockDevice)sender;
                    Log.Information("Device {Device} disconnected", dev);
                    ChildDevices.Remove(dev);
                    dev.Dispose();
                };

                ChildDevices.Add(device);

                device.InputReportReceived += (sender, args) =>
                                              OnInputReportReceived((IDualShockDevice)sender, args.Report);
            }
        }
示例#2
0
        private void OnLookup(long l)
        {
            if (!Monitor.TryEnter(_deviceLookupTask))
            {
                return;
            }

            try
            {
                var instanceId = 0;

                while (Devcon.Find(FireShockDevice.ClassGuid, out var path, out var instance, instanceId++))
                {
                    if (_devices.Any(h => h.DevicePath.Equals(path)))
                    {
                        continue;
                    }

                    Log.Information("Found FireShock device {Path} ({Instance})", path, instance);

                    var device = FireShockDevice.CreateDevice(path, _devices.Count);

                    device.DeviceDisconnected += (sender, args) =>
                    {
                        var dev = (FireShockDevice)sender;
                        Log.Information("Device {Device} disconnected", dev);
                        _devices.Remove(dev);
                        dev.Dispose();
                    };

                    _devices.Add(device);

                    device.InputReportReceived += (sender, args) =>
                                                  InputReportReceived?.Invoke(this,
                                                                              new InputReportReceivedEventArgs((IDualShockDevice)sender, args.Report));
                }
            }
            finally
            {
                Monitor.Exit(_deviceLookupTask);
            }
        }
示例#3
0
        protected override void OnLookup()
        {
            var instanceId = 0;

            while (Devcon.Find(FireShockDevice.ClassGuid, out var path, out var instance, instanceId++))
            {
                if (ChildDevices.Any(h => h.DevicePath.Equals(path)))
                {
                    continue;
                }

                Log.Information("Found FireShock device {Path} ({Instance})", path, instance);

                //
                // Find the lowest controller index that is currently unused
                //
                var newIndex = ChildDevices.Count;
                if (reclaimedDeviceIndices.Count > 0)
                {
                    reclaimedDeviceIndices.Sort();
                    newIndex = reclaimedDeviceIndices[0];
                    reclaimedDeviceIndices.RemoveAt(0);
                }

                var device = FireShockDevice.CreateDevice(path, newIndex);

                device.DeviceDisconnected += (sender, args) =>
                {
                    var dev = (FireShockDevice)sender;
                    Log.Information("Device {Device} disconnected", dev);
                    ChildDevices.Remove(dev);
                    reclaimedDeviceIndices.Add(dev.DeviceIndex);
                    dev.Dispose();
                };

                ChildDevices.Add(device);

                device.InputReportReceived += (sender, args) =>
                                              OnInputReportReceived((IDualShockDevice)sender, args.Report);
            }
        }