private async Task UpdateDeviceListAsync() { IsUpdatingDeviceList = true; AvailableDevices.Clear(); CurrentDevice = null; var devices = await BluetoothManager.GetDevicesAsync(); Task <IBluetoothService[]>[] tasks = devices.Select(d => d.GetServicesAsync()).ToArray(); await Task.WhenAll(tasks); for (int i = 0; i < tasks.Length; ++i) { if (tasks[i].Result.Any(s => s.Id == Bluetooth.TricorderServiceId)) { AvailableDevices.Add(devices[i]); } } if (AvailableDevices.Count > 0 && CurrentDevice == null) { CurrentDevice = AvailableDevices[0]; } IsUpdatingDeviceList = false; }
private void UpdateDisplays(int fd) { unsafe { lock (this) { AvailableDevices.Clear(); DisplayIds.Clear(); List <LinuxDisplay> displays = new List <LinuxDisplay>(); if (QueryDisplays(fd, displays)) { foreach (LinuxDisplay display in displays) { AddDisplay(display); } } if (AvailableDevices.Count == 0) { Debug.Print("[KMS] Failed to find any active displays"); } } } }
private void RefreshDisplayDevices() { using (new XLock(API.DefaultDisplay)) { var devices = new List <DisplayDevice>(); xinerama_supported = false; try { xinerama_supported = QueryXinerama(devices); } catch { Debug.Print("Xinerama query failed."); } if (!xinerama_supported) { // We assume that devices are equivalent to the number of available screens. // Note: this won't work correctly in the case of distinct X servers. for (var i = 0; i < API.ScreenCount; i++) { var dev = new DisplayDevice(); dev.IsPrimary = i == Functions.XDefaultScreen(API.DefaultDisplay); devices.Add(dev); deviceToScreen.Add(dev, i); } } try { xrandr_supported = QueryXRandR(devices); } catch { } if (!xrandr_supported) { Debug.Print("XRandR query failed, falling back to XF86."); try { xf86_supported = QueryXF86(devices); } catch { } if (!xf86_supported) { Debug.Print("XF86 query failed, no DisplayDevice support available."); } } AvailableDevices.Clear(); AvailableDevices.AddRange(devices); Primary = FindDefaultDevice(devices); } }
private async void OnDisconnectDeviceCommand() { if (!Disconnecting) { if (SelectedDevice != null) { if (CrossBleAdapter.Current.Status == AdapterStatus.PoweredOn || CrossBleAdapter.Current.Status == AdapterStatus.Unsupported) { try { Disconnecting = true; DisconnectDeviceCommand.RaiseCanExecuteChanged(); //BatteryToken?.Cancel(); //SystemToken?.Cancel(); //ProgramToken?.Cancel(); bleService.Disconnect(); var timeOut = 0; while (SelectedDevice.ConnectState != DeviceState.Disconnected && timeOut < 30) { await Task.Delay(TimeSpan.FromSeconds(1)); timeOut++; } Disconnecting = false; DisconnectDeviceCommand.RaiseCanExecuteChanged(); if (SelectedDevice.ConnectState != DeviceState.Disconnected) { await dialogService.DisplayAlertAsync("Bluetooth", "Device failed to disconnect", "Ok"); } else { foundDevices.Clear(); AvailableDevices.Clear(); SelectedDevice = null; // RaisePropertyChanged(nameof(SelectedDevice)); } } catch (Exception e) { // Crashes.TrackError(e); Disconnecting = false; DisconnectDeviceCommand.RaiseCanExecuteChanged(); } } else { await dialogService.DisplayAlertAsync("Bluetooth", "Please check your Bluetooth Settings", "Ok"); } } } }
public async Task OnDiscoverDevices() { WpfUtilities.RunOnUiThread(() => { AvailableDevices.Clear(); }, Application.Current.Dispatcher); CommunicationHandlerFactory.DiscoverDevices(); await Task.Delay(500); foreach (var device in CommunicationHandlerFactory.AvailableDevices) { var handler = CommunicationHandlerFactory.AvailableHandlers.First(h => h.IsDriverForDevice(device)); var driver = new DeviceDriver(device, handler.SupportsSetupDialog, new DelegateCommand((p) => OnRunDeviceHandlerSetup(handler, p))); WpfUtilities.RunOnUiThread(() => { AvailableDevices.Add(driver); }, Application.Current.Dispatcher); } }
/// <summary> /// Release all acquired devices /// </summary> static void ReleaseDevices() { Trace.WriteDebugLine("[GamePad] ReleaseDevices()"); foreach (GamePadState state in AvailableDevices) { if (state.Joystick == null) { continue; } //state.Joystick.Unacquire(); //state.Joystick.Dispose(); } AvailableDevices.Clear(); }
public async Task EnumerateDevicesAsync() { try { var DeviceInfos = await DeviceInformation.FindAllAsync(DeviceSelector); AvailableDevices.Clear(); if (DeviceInfos.Count > 0) { foreach (var deviceInfo in DeviceInfos) { AvailableDevices.Add(deviceInfo); } } } catch (Exception) { CloseDevice(); } }
private async void OnScanForDevicesCommand() { if (!ScanningForDevices) { ScanningForDevices = true; ScanForDevicesCommand.RaiseCanExecuteChanged(); if (CrossBleAdapter.Current.Status == AdapterStatus.PoweredOn || CrossBleAdapter.Current.Status == AdapterStatus.Unsupported) { AvailableDevices.Clear(); foundDevices.Clear(); try { bleService.ScanForDevicesCommand(TimeSpan.FromSeconds(10), device => { if (device != null) { foundDevices.Add(device.Name, device); AvailableDevices.Add(device.Name); } }); await Task.Delay(TimeSpan.FromSeconds(10)); ScanningForDevices = false; ScanForDevicesCommand.RaiseCanExecuteChanged(); } catch (Exception e) { // Crashes.TrackError(e); ScanningForDevices = false; ScanForDevicesCommand.RaiseCanExecuteChanged(); } } else { await dialogService.DisplayAlertAsync("Bluetooth", "Please check your Bluetooth Settings", "Ok"); } } }
public void RefreshDisplayDevices() { lock (display_lock) { // Store an array of the current available DisplayDevice objects. // This is needed to preserve the original resolution. var previousDevices = AvailableDevices.ToArray(); AvailableDevices.Clear(); // We save all necessary parameters in temporary variables // and construct the device when every needed detail is available. // The main DisplayDevice constructor adds the newly constructed device // to the list of available devices. DisplayDevice opentk_dev; DisplayResolution opentk_dev_current_res = null; var opentk_dev_available_res = new List <DisplayResolution>(); bool opentk_dev_primary = false; uint device_count = 0, mode_count = 0; // Get available video adapters and enumerate all monitors while (User32.DeviceContext.EnumDisplayDevices(null, device_count++, out var dev1, 0)) { if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0) { continue; } // The second function should only be executed when the first one fails // (e.g. when the monitor is disabled) if (User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSetting.CurrentSettings, out DeviceMode monitor_mode, 0) || User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, DisplayModeSetting.RegistrySettings, out monitor_mode, 0)) { VerifyMode(dev1, monitor_mode); var scale = GetScale(ref monitor_mode); opentk_dev_current_res = new DisplayResolution( (int)(monitor_mode.DisplayOptions.Position.X / scale), (int)(monitor_mode.DisplayOptions.Position.Y / scale), (int)(monitor_mode.WidthInPixels / scale), (int)(monitor_mode.HeightInPixels / scale), (int)monitor_mode.BitsPerPixel, monitor_mode.DisplayFrequency ); opentk_dev_primary = (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0; } opentk_dev_available_res.Clear(); mode_count = 0; while (User32.DeviceContext.EnumDisplaySettingsEx(dev1.DeviceName, (DisplayModeSetting)mode_count++, out monitor_mode, 0)) { VerifyMode(dev1, monitor_mode); var scale = GetScale(ref monitor_mode); var res = new DisplayResolution( (int)(monitor_mode.DisplayOptions.Position.X / scale), (int)(monitor_mode.DisplayOptions.Position.Y / scale), (int)(monitor_mode.WidthInPixels / scale), (int)(monitor_mode.HeightInPixels / scale), (int)monitor_mode.BitsPerPixel, monitor_mode.DisplayFrequency ); opentk_dev_available_res.Add(res); } // Construct the OpenTK DisplayDevice through the accumulated parameters. // The constructor will automatically add the DisplayDevice to the list // of available devices. #pragma warning disable 612,618 opentk_dev = new DisplayDevice( opentk_dev_current_res, opentk_dev_primary, opentk_dev_available_res, opentk_dev_current_res.Bounds, dev1.DeviceName ); #pragma warning restore 612,618 // Set the original resolution if the DisplayDevice was previously available. foreach (var existingDevice in previousDevices) { if ((string)existingDevice.Id == (string)opentk_dev.Id) { opentk_dev.OriginalResolution = existingDevice.OriginalResolution; } } AvailableDevices.Add(opentk_dev); if (opentk_dev_primary) { Primary = opentk_dev; } Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.", device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count); } } }
public void RefreshDisplayDevices() { lock (display_lock) { AvailableDevices.Clear(); // We save all necessary parameters in temporary variables // and construct the device when every needed detail is available. // The main DisplayDevice constructor adds the newly constructed device // to the list of available devices. DisplayDevice opentk_dev; DisplayResolution opentk_dev_current_res = null; List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>(); bool opentk_dev_primary = false; int device_count = 0, mode_count = 0; // Get available video adapters and enumerate all monitors WindowsDisplayDevice dev1 = new WindowsDisplayDevice(), dev2 = new WindowsDisplayDevice(); while (Functions.EnumDisplayDevices(null, device_count++, dev1, 0)) { if ((dev1.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.None) { continue; } DeviceMode monitor_mode = new DeviceMode(); // The second function should only be executed when the first one fails // (e.g. when the monitor is disabled) if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) || Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0)) { VerifyMode(dev1, monitor_mode); float scale = GetScale(ref monitor_mode); opentk_dev_current_res = new DisplayResolution( (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); opentk_dev_primary = (dev1.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != DisplayDeviceStateFlags.None; } opentk_dev_available_res.Clear(); mode_count = 0; while (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), mode_count++, monitor_mode, 0)) { VerifyMode(dev1, monitor_mode); float scale = GetScale(ref monitor_mode); DisplayResolution res = new DisplayResolution( (int)(monitor_mode.Position.X / scale), (int)(monitor_mode.Position.Y / scale), (int)(monitor_mode.PelsWidth / scale), (int)(monitor_mode.PelsHeight / scale), monitor_mode.BitsPerPel, monitor_mode.DisplayFrequency); opentk_dev_available_res.Add(res); } // Construct the OpenTK DisplayDevice through the accumulated parameters. // The constructor will automatically add the DisplayDevice to the list // of available devices. opentk_dev = new DisplayDevice( opentk_dev_current_res, opentk_dev_primary, opentk_dev_available_res, opentk_dev_current_res.Bounds, dev1.DeviceName); AvailableDevices.Add(opentk_dev); if (opentk_dev_primary) { Primary = opentk_dev; } Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.", device_count, opentk_dev.IsPrimary ? "primary" : "secondary", opentk_dev.AvailableResolutions.Count); } } }