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; }
public void RemoveShadowDevice(DeviceViewModel device) { if (ShadowDevices.Remove(device)) { device.Checked = false; AvailableDevices.Add(device); } }
private void RendererDiscovererItemAdded(object sender, DeviceAddedArgs e) { var item = e.Receiver; _logger.LogInformation( $"{nameof(RendererDiscovererItemAdded)}: New item discovered: " + $"{e.Receiver.FriendlyName} - Ip = {item.Host}:{item.Port}"); AvailableDevices.Add(item); OnCastableDeviceAdded?.Invoke(item.Id, item.FriendlyName, item.Type, item.Host, item.Port); }
public Task SetCastRenderer(string host, int port) { if (!AvailableDevices.Any(d => d.Host == host && d.Port == port)) { AvailableDevices.Add(Receiver.Default(host, port)); } var renderer = AvailableDevices.Find(d => d.Host == host && d.Port == port); return(SetCastRenderer(renderer)); }
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); } }
private void CallBackForUserDetails(User user) { Device.BeginInvokeOnMainThread(() => { var record = AvailableDevices.Where(a => a.IPAddress == user.IPAddress); if (record.Any()) { AvailableDevices.Remove(record.First()); } AvailableDevices.Add(new User() { IPAddress = user.IPAddress, Name = user.Name }); }); }
private void UpdateDisplayIndices(LinuxDisplay display, DisplayDevice device) { if (!DisplayIds.ContainsKey(display.Id)) { Debug.Print("[KMS] Adding display {0} as {1}", display.Id, AvailableDevices.Count); DisplayIds.Add(display.Id, AvailableDevices.Count); } int index = DisplayIds[display.Id]; if (index >= AvailableDevices.Count) { AvailableDevices.Add(device); } else { AvailableDevices[index] = device; } }
public Sdl2DisplayDeviceDriver() { int displays = SDL.GetNumVideoDisplays(); for (int d = 0; d < displays; d++) { Rect bounds; SDL.GetDisplayBounds(d, out bounds); DisplayMode current_mode; SDL.GetCurrentDisplayMode(d, out current_mode); var mode_list = new List <DisplayResolution>(); int num_modes = SDL.GetNumDisplayModes(d); for (int m = 0; m < num_modes; m++) { DisplayMode sdl_mode; SDL.GetDisplayMode(d, m, out sdl_mode); mode_list.Add(new DisplayResolution( bounds.X, bounds.Y, sdl_mode.Width, sdl_mode.Height, TranslateFormat(sdl_mode.Format), sdl_mode.RefreshRate)); } var current_resolution = new DisplayResolution( bounds.X, bounds.Y, current_mode.Width, current_mode.Height, TranslateFormat(current_mode.Format), current_mode.RefreshRate); var device = new DisplayDevice( current_resolution, d == 0, mode_list, TranslateBounds(bounds), d); AvailableDevices.Add(device); if (d == 0) { Primary = device; } } }
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(); } }
public CameraSnapshot() { InitializeComponent(); if (AvailableDevices.Count == 0) { foreach (var devices in WebcamDevice.VideoDevices) { AvailableDevices.Add(devices); } } SelectedDevice = AvailableDevices.LastOrDefault(id => SelectedDeviceId == id.UsbId) ?? AvailableDevices.LastOrDefault(); Unloaded += delegate { SelectedDeviceId = SelectedDevice?.UsbId; Webcam.VideoSourceId = ""; }; }
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"); } } }
private void OnLoadDevicesCommand() { IsBusy = true; try { if (BluetoothAdapter.DefaultAdapter != null && BluetoothAdapter.DefaultAdapter.IsEnabled) { foreach (var pairedDevice in BluetoothAdapter.DefaultAdapter.BondedDevices) { AvailableDevices.Add(pairedDevice); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
async Task LoadAvailableDevicesAsync() { try { IsLoadingDevices = true; var availableNetworks = await DeviceDriveManager.Current.GetAvailableDevicesAsync(null); foreach (var network in availableNetworks) { AvailableDevices.Add(network); } // We have a list of devices, do nothing, just wait for a device selection IsWaitingForNetwork = false; WaitingLabel = string.Empty; IsLoadingDevices = false; NoDevicesFoundVisible = !AvailableDevices.Any(); } catch (TaskCanceledException) { // Swallow } }
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 QuartzDisplayDeviceDriver() { lock (display_lock) { // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice // we only allow settings to be set through its constructor. // Thus, 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. const int maxDisplayCount = 20; IntPtr[] displays = new IntPtr[maxDisplayCount]; int displayCount; unsafe { fixed(IntPtr *displayPtr = displays) { CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount); } } Debug.Print("CoreGraphics reported {0} display(s).", displayCount); Debug.Indent(); for (int i = 0; i < displayCount; i++) { IntPtr currentDisplay = displays[i]; // according to docs, first element in the array is always the // main display. bool primary = (i == 0); // gets current settings int currentWidth = CG.DisplayPixelsWide(currentDisplay); int currentHeight = CG.DisplayPixelsHigh(currentDisplay); Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight); IntPtr displayModesPtr = CG.DisplayAvailableModes(currentDisplay); CFArray displayModes = new CFArray(displayModesPtr); Debug.Print("Supports {0} display modes.", displayModes.Count); DisplayResolution opentk_dev_current_res = null; List <DisplayResolution> opentk_dev_available_res = new List <DisplayResolution>(); IntPtr currentModePtr = CG.DisplayCurrentMode(currentDisplay); CFDictionary currentMode = new CFDictionary(currentModePtr); for (int j = 0; j < displayModes.Count; j++) { CFDictionary dict = new CFDictionary(displayModes[j]); int width = (int)dict.GetNumberValue("Width"); int height = (int)dict.GetNumberValue("Height"); int bpp = (int)dict.GetNumberValue("BitsPerPixel"); double freq = dict.GetNumberValue("RefreshRate"); bool current = currentMode.Ref == dict.Ref; //if (current) Debug.Write(" * "); //else Debug.Write(" "); //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq); DisplayResolution thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq); opentk_dev_available_res.Add(thisRes); if (current) { opentk_dev_current_res = thisRes; } } HIRect bounds = CG.DisplayBounds(currentDisplay); Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height); Debug.Print("Display {0} bounds: {1}", i, newRect); DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect, currentDisplay); AvailableDevices.Add(opentk_dev); if (primary) { Primary = opentk_dev; } } Debug.Unindent(); } }
public QuartzDisplayDeviceDriver() { lock (display_lock) { // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice // we only allow settings to be set through its constructor. // Thus, 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. const int maxDisplayCount = 20; var displays = new IntPtr[maxDisplayCount]; int displayCount; unsafe { fixed(IntPtr *displayPtr = displays) { CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount); } } Debug.Print("CoreGraphics reported {0} display(s).", displayCount); Debug.Indent(); for (var i = 0; i < displayCount; i++) { var currentDisplay = displays[i]; // according to docs, first element in the array is always the // main display. var primary = i == 0; // gets current settings var currentWidth = CG.DisplayPixelsWide(currentDisplay); var currentHeight = CG.DisplayPixelsHigh(currentDisplay); Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight); var displayModesPtr = CG.DisplayAvailableModes(currentDisplay); var displayModes = new CFArray(displayModesPtr); Debug.Print("Supports {0} display modes.", displayModes.Count); DisplayResolution opentk_dev_current_res = null; var opentk_dev_available_res = new List <DisplayResolution>(); var currentModePtr = CG.DisplayCurrentMode(currentDisplay); var currentMode = new CFDictionary(currentModePtr); for (var j = 0; j < displayModes.Count; j++) { var dict = new CFDictionary(displayModes[j]); var width = (int)dict.GetNumberValue("Width"); var height = (int)dict.GetNumberValue("Height"); var bpp = (int)dict.GetNumberValue("BitsPerPixel"); var freq = dict.GetNumberValue("RefreshRate"); var current = currentMode.Ref == dict.Ref; if (freq <= 0) { IntPtr displayLink; CV.DisplayLinkCreateWithCGDisplay(currentDisplay, out displayLink); var t = CV.DisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); if ((t.flags & (int)CV.TimeFlags.TimeIsIndefinite) != (int)CV.TimeFlags.TimeIsIndefinite) { freq = (double)t.timeScale / t.timeValue; } CV.DisplayLinkRelease(displayLink); } //if (current) Debug.Write(" * "); //else Debug.Write(" "); //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq); var thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq); opentk_dev_available_res.Add(thisRes); if (current) { opentk_dev_current_res = thisRes; } } var bounds = CG.DisplayBounds(currentDisplay); var newRect = new Rectangle((int)bounds.Location.X, (int)bounds.Location.Y, (int)bounds.Size.Width, (int)bounds.Size.Height); Debug.Print("Display {0} bounds: {1}", i, newRect); var opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect, currentDisplay); AvailableDevices.Add(opentk_dev); if (primary) { Primary = opentk_dev; } } Debug.Unindent(); } }
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); } } }
/// <summary> /// Операция добавления устройства /// </summary> /// <param name="parDevice">Физическое устройство OpenTK</param> private void DeviceAdd(MDeviceOpenTk parDevice) { AvailableDevices.Add(parDevice); OnDeviceAdded?.Invoke(parDevice); }