public DriverDaemon() { Log.Output += (sender, message) => { LogMessages.Add(message); Console.WriteLine(Log.GetStringFormat(message)); Message?.Invoke(sender, message); }; Driver.Reading += async(_, isReading) => TabletChanged?.Invoke(this, isReading ? await GetTablet() : null); LoadUserSettings(); HidSharp.DeviceList.Local.Changed += async(sender, e) => { var newDevices = from device in DeviceList.Local.GetHidDevices() where !CurrentDevices.Any(d => d == device) select device; if (newDevices.Count() > 0) { if (await GetTablet() == null) { await DetectTablets(); } } CurrentDevices = DeviceList.Local.GetHidDevices(); }; }
public void DetectTablet() { lock (detectLock) { cancellationSource?.Cancel(); var cancellationToken = (cancellationSource = new CancellationTokenSource()).Token; Task.Run(async() => { // wait a small delay as multiple devices may appear over a very short interval. await Task.Delay(50, cancellationToken).ConfigureAwait(false); var foundVendor = CurrentDevices.Select(d => d.VendorID).Intersect(known_vendors).FirstOrDefault(); if (foundVendor > 0) { Logger.Log($"Tablet detected (vid{foundVendor}), searching for usable configuration..."); foreach (var config in getConfigurations()) { if (TryMatch(config)) { break; } } } }, cancellationToken); } }
void ButtonWizard_Click(object sender, RoutedEventArgs e) { int outputStreamId = Convert.ToInt32(((Button)sender).Tag.ToString()); string acronym = ToolTipService.GetToolTip((Button)sender).ToString(); CurrentDevices currentDevices = new CurrentDevices(outputStreamId, acronym); #if SILVERLIGHT currentDevices.Show(); #else currentDevices.Owner = Window.GetWindow(this); currentDevices.WindowStartupLocation = WindowStartupLocation.CenterOwner; currentDevices.ShowDialog(); #endif }
public DriverDaemon() { Driver = new Driver(); Log.Output += (sender, message) => LogMessages.Add(message); Log.Output += (sender, message) => Console.WriteLine(Log.GetStringFormat(message)); LoadUserSettings(); HidSharp.DeviceList.Local.Changed += (sender, e) => { var newDevices = from device in DeviceList.Local.GetHidDevices() where !CurrentDevices.Any(d => d == device) select device; if (newDevices.Count() > 0) { if (GetTablet() == null) { DetectTablets(); } } CurrentDevices = DeviceList.Local.GetHidDevices().ToList(); }; }