private async Task detectAsync(CancellationToken cancellationToken)
        {
            // wait a small delay as multiple devices may appear over a very short interval.
            await Task.Delay(50, cancellationToken).ConfigureAwait(false);

            int foundVendor = CompositeDeviceHub.GetDevices().Select(d => d.VendorID).Intersect(known_vendors).FirstOrDefault();

            if (foundVendor > 0)
            {
                Logger.Log($"Tablet detected (vid{foundVendor}), searching for usable configuration...");

                Detect();

                foreach (var device in InputDevices)
                {
                    foreach (var endpoint in device.InputDevices)
                    {
                        endpoint.Report += DeviceReported;
                        endpoint.ConnectionStateChanged += (sender, connected) =>
                        {
                            if (!connected)
                            {
                                endpoint.Report -= DeviceReported;
                            }
                        };
                    }
                }
            }
        }
Example #2
0
 private IEnumerable <IDeviceEndpoint> GetMatchingDevices(TabletConfiguration configuration, DeviceIdentifier identifier)
 {
     return(from device in CompositeDeviceHub.GetDevices()
            where identifier.VendorID == device.VendorID
            where identifier.ProductID == device.ProductID
            where device.CanOpen
            where identifier.InputReportLength == null || identifier.InputReportLength == device.InputReportLength
            where identifier.OutputReportLength == null || identifier.OutputReportLength == device.OutputReportLength
            where DeviceMatchesStrings(device, identifier.DeviceStrings)
            where DeviceMatchesAttribute(device, configuration.Attributes)
            select device);
 }