Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Creates a new child device.
 /// </summary>
 /// <param name="host">The host this child is connected to.</param>
 /// <param name="client">The client MAC address identifying this child.</param>
 /// <param name="index">The index this child is registered on the host device under.</param>
 protected AirBenderChildDevice(AirBenderHost host, PhysicalAddress client, int index) : base(
         DualShockConnectionType.Bluetooth, host.DeviceHandle, index)
 {
     HostDevice    = host;
     HostAddress   = host.HostAddress;
     ClientAddress = client;
 }
Exemplo n.º 3
0
        public AirBenderDualShock3(AirBenderHost host, PhysicalAddress client, int index) : base(host, client, index)
        {
            DeviceType = DualShockDeviceType.DualShock3;

            if (index >= 0 && index < 4)
            {
                HidOutputReport[11] = _ledOffsets[index];
            }
        }
Exemplo n.º 4
0
        private void OnLookup(long l)
        {
            if (!Monitor.TryEnter(_hostLookupTask))
            {
                return;
            }

            try
            {
                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 += (o, eventArgs) =>
                                                ChildDeviceAttached?.Invoke(this, new ChildDeviceAttachedEventArgs(eventArgs.Device));
                    host.ChildDeviceRemoved += (o, eventArgs) =>
                                               ChildDeviceRemoved?.Invoke(this, new ChildDeviceRemovedEventArgs(eventArgs.Device));
                    host.InputReportReceived += (sender, args) =>
                                                InputReportReceived?.Invoke(this, new InputReportReceivedEventArgs(args.Device, args.Report));

                    _hosts.Add(host);
                }
            }
            finally
            {
                Monitor.Exit(_hostLookupTask);
            }
        }