コード例 #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
        protected override void OnLookup()
        {
            var instanceId = 0;

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

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

                var host = new AirBenderHost(path);

                host.HostDeviceDisconnected += (sender, args) =>
                {
                    var device = (AirBenderHost)sender;
                    _hosts.Remove(device);
                    device.Dispose();
                };

                host.ChildDeviceAttached += (sender, args) => ChildDevices.Add((DualShockDevice)args.Device);
                host.ChildDeviceRemoved  += (sender, args) => ChildDevices.Remove((DualShockDevice)args.Device);
                host.InputReportReceived += (sender, args) =>
                                            OnInputReportReceived((DualShockDevice)args.Device, args.Report);

                _hosts.Add(host);
            }
        }
コード例 #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);
            }
        }
コード例 #4
0
        protected override void OnLookup()
        {
            var instanceId = 0;

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

                Log.Information("Found SIXAXIS 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 = BthPS3Device.CreateSixaxisDevice(path, newIndex);

                //
                // Subscribe to device removal event
                //
                device.DeviceDisconnected += (sender, args) =>
                {
                    var dev = (BthPS3Device)sender;
                    Log.Information("Device {Device} disconnected", dev);
                    ChildDevices.Remove(dev);
                    reclaimedDeviceIndices.Add(dev.DeviceIndex);
                    dev.Dispose();
                };

                ChildDevices.Add(device);

                //
                // Route incoming input reports through to master hub
                //
                device.InputReportReceived += (sender, args) =>
                                              OnInputReportReceived((IDualShockDevice)sender, args.Report);
            }

            instanceId = 0;

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

                Log.Information("Found Navigation 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 = BthPS3Device.CreateNavigationDevice(path, newIndex);

                //
                // Subscribe to device removal event
                //
                device.DeviceDisconnected += (sender, args) =>
                {
                    var dev = (BthPS3Device)sender;
                    Log.Information("Device {Device} disconnected", dev);
                    ChildDevices.Remove(dev);
                    reclaimedDeviceIndices.Add(dev.DeviceIndex);
                    dev.Dispose();
                };

                ChildDevices.Add(device);

                //
                // Route incoming input reports through to master hub
                //
                device.InputReportReceived += (sender, args) =>
                                              OnInputReportReceived((IDualShockDevice)sender, args.Report);
            }
        }