Beispiel #1
0
        protected void OnInputReport(IInputReport report)
        {
            if (report == null)
            {
                return;
            }

            InputReportReceived?.Invoke(this, new InputReportEventArgs(report));
        }
Beispiel #2
0
        private void ChildDeviceArrivalWorker(object cancellationToken)
        {
            var token         = (CancellationToken)cancellationToken;
            var requestSize   = Marshal.SizeOf <AirbenderGetClientArrival>();
            var requestBuffer = Marshal.AllocHGlobal(requestSize);

            try
            {
                while (!token.IsCancellationRequested)
                {
                    //
                    // This call blocks until the driver supplies new data.
                    //
                    var ret = DeviceHandle.OverlappedDeviceIoControl(
                        IoctlAirbenderGetClientArrival,
                        IntPtr.Zero, 0, requestBuffer, requestSize,
                        out _);

                    if (!ret)
                    {
                        throw new AirbenderGetClientArrivalFailedException(
                                  "Failed to receive device arrival event.",
                                  new Win32Exception(Marshal.GetLastWin32Error()));
                    }

                    var resp = Marshal.PtrToStructure <AirbenderGetClientArrival>(requestBuffer);

                    switch (resp.DeviceType)
                    {
                    case DualShockDeviceType.DualShock3:
                        var device = new AirBenderDualShock3(
                            this,
                            new PhysicalAddress(resp.ClientAddress.Address.Reverse().ToArray()),
                            Children.Count);

                        device.InputReportReceived +=
                            (sender, args) => InputReportReceived?.Invoke(this,
                                                                          new InputReportReceivedEventArgs((IDualShockDevice)sender, args.Report));

                        Children.Add(device);

                        break;

                    case DualShockDeviceType.DualShock4:
                        throw new NotImplementedException();

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(requestBuffer);
            }
        }
Beispiel #3
0
        protected void OnInputReport(IInputReport report)
        {
            if (report == null)
            {
                return;
            }

            // Pull battery state from report
            DualShock3InputReport ds3_report = (DualShock3InputReport)report;

            BatteryState = ds3_report.BatteryState;

            InputReportReceived?.Invoke(this, new InputReportEventArgs(report));
        }
Beispiel #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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
 protected void OnInputReportReceived(IDualShockDevice sender, IInputReport report)
 {
     InputReportReceived?.Invoke(this,
                                 new InputReportReceivedEventArgs(sender, report));
 }
Beispiel #7
0
 protected void OnInputReport(IInputReport report)
 {
     InputReportReceived?.Invoke(this, new InputReportEventArgs(report));
 }