public void AddFakeCamera() { FakeCameraDevice device = new FakeCameraDevice(); ConnectedDevices.Add(device); SelectedCameraDevice = device; }
public void AddFakeCamera() { FakeCameraDevice device = new FakeCameraDevice(); ConnectedDevices.Add(device); NewCameraConnected(device); }
private async void DeviceFound(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs btAdv) { if (!ConnectedDevices.Contains(btAdv.Advertisement.LocalName) && _devices.Contains(btAdv.Advertisement.LocalName)) { await Dispatcher.RunAsync(CoreDispatcherPriority.Low, async() => { var device = await BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress); if (device.GattServices.Any()) { ConnectedDevices.Add(device.Name); device.ConnectionStatusChanged += async(sender, args) => { if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected) { await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ConnectedDevices .Remove( sender .Name); }); } }; SetupWaxStream(device); } else if (device.DeviceInformation.Pairing.CanPair && !device.DeviceInformation.Pairing.IsPaired) { await device.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.None); } }); } }
private async Task Enumerate() { try { var enumerator = new Enumerator(); Logger.Log(LogSeverity.Info, $"Starting enumeration, targeting any compatible devices."); while (enumerator.Devices.Count == 0) { await enumerator.Run(Target); await Task.Delay(10); } Logger.Log(LogSeverity.Info, $"Enumeration complete for target, found {enumerator.Devices.Count} devices."); var i = 1; enumerator.Devices.ForEach(_dev => { ConnectedDevices.Add(new Device((int)_dev.Info.ProductId, _dev.FriendlyName, _dev.Target)); Logger.Log(LogSeverity.Info, $"{i} - {_dev.FriendlyName} | {_dev.Info.DeviceId} | {_dev.Target}."); i++; }); } catch (Exception e) { Logger.Log(LogSeverity.Error, e.Message); Step = FlashingStep.Error; } }
protected BluetoothLEManager() { CentralManager = new CBCentralManager(DispatchQueue.CurrentQueue); CentralManager.DiscoveredPeripheral += (object sender, CBDiscoveredPeripheralEventArgs e) => { Console.WriteLine("DiscoveredPeripheral: " + e.Peripheral.Name); DiscoveredDevices.Add(e.Peripheral); DeviceDiscovered(this, e); }; CentralManager.UpdatedState += (object sender, EventArgs e) => { Console.WriteLine("UpdatedState: " + CentralManager.State); }; CentralManager.ConnectedPeripheral += (object sender, CBPeripheralEventArgs e) => { Console.WriteLine("ConnectedPeripheral: " + e.Peripheral.Name); // When a peripheral gets connected, add that peripheral to our running list of // connected peripherals if (!ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Add(e.Peripheral); } // raise our connected event DeviceConnected(sender, e); }; CentralManager.DisconnectedPeripheral += (object sender, CBPeripheralErrorEventArgs e) => { Console.WriteLine("DisconnectedPeripheral: " + e.Peripheral.Name); // When a peripheral disconnects, remove it from our running list. if (ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Remove(e.Peripheral); } // Raise our disconnected event DeviceDisconnected(sender, e); }; }
protected BluetoothLeManager() { CentralBleManager = new CBCentralManager(DispatchQueue.CurrentQueue); DiscoveredDevices = new List <CBPeripheral>(); CentralBleManager.DiscoveredPeripheral += (sender, e) => { Mvx.Trace("DiscoveredPeripheral: {0}", e.Peripheral.Name); DiscoveredDevices.Add(e.Peripheral); DeviceDiscovered(this, e); }; CentralBleManager.UpdatedState += (sender, e) => { Mvx.Trace("UpdatedState: {0}", CentralBleManager.State); }; CentralBleManager.ConnectedPeripheral += (sender, e) => { Mvx.Trace("ConnectedPeripheral: " + e.Peripheral.Name); // when a peripheral gets connected, add that peripheral to our running list of connected peripherals if (!ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Add(e.Peripheral); } // raise our connected event DeviceConnected(sender, e); }; CentralBleManager.DisconnectedPeripheral += (sender, e) => { Mvx.Trace("DisconnectedPeripheral: " + e.Peripheral.Name); // when a peripheral disconnects, remove it from our running list. if (ConnectedDevices.Contains(e.Peripheral)) { ConnectedDevices.Remove(e.Peripheral); } // raise our disconnected event DeviceDisconnected(sender, e); }; }
protected Adapter() { CentralManager = new CBCentralManager(DispatchQueue.CurrentQueue); CentralManager.DiscoveredPeripheral += (object sender, CBDiscoveredPeripheralEventArgs e) => { Console.WriteLine("DiscoveredPeripheral: " + e.Peripheral.Name); Device d = new Device(e.Peripheral); if (!ContainsDevice(DiscoveredDevices, e.Peripheral)) { DiscoveredDevices.Add(d); DeviceDiscovered(this, new DeviceDiscoveredEventArgs() { Device = d }); } }; CentralManager.UpdatedState += (object sender, EventArgs e) => { Console.WriteLine("UpdatedState: " + CentralManager.State); _stateChanged.Set(); }; CentralManager.ConnectedPeripheral += (object sender, CBPeripheralEventArgs e) => { Console.WriteLine("ConnectedPeripheral: " + e.Peripheral.Name); // When a peripheral gets connected, add that peripheral to our running list of // connected peripherals if (!ContainsDevice(ConnectedDevices, e.Peripheral)) { Device d = new Device(e.Peripheral); ConnectedDevices.Add(new Device(e.Peripheral)); // raise our connected event DeviceConnected(sender, new DeviceConnectionEventArgs() { Device = d }); } }; CentralManager.DisconnectedPeripheral += (object sender, CBPeripheralErrorEventArgs e) => { Console.WriteLine("DisconnectedPeripheral: " + e.Peripheral.Name); // when a peripheral disconnects, remove it from our running list. IDevice foundDevice = null; foreach (var d in ConnectedDevices) { if (d.ID == Guid.ParseExact(e.Peripheral.Identifier.AsString(), "d")) { foundDevice = d; } } if (foundDevice != null) { ConnectedDevices.Remove(foundDevice); } // raise our disconnected event DeviceDisconnected(sender, new DeviceConnectionEventArgs() { Device = new Device(e.Peripheral) }); }; CentralManager.FailedToConnectPeripheral += (object sender, CBPeripheralErrorEventArgs e) => { // raise the failed to connect event DeviceFailedToConnect(this, new DeviceConnectionEventArgs() { Device = new Device(e.Peripheral), ErrorMessage = e.Error.Description }); }; }
public IDevice Connect(IDeviceInfo deviceInfo) { int result; MsBluetoothDeviceInfo bluetoothDeviceInfo = deviceInfo as MsBluetoothDeviceInfo; if (bluetoothDeviceInfo == null) { throw new ArgumentException("The specified IDeviceInfo does not belong to this DeviceProvider.", "deviceInfo"); } NativeMethods.BluetoothDeviceInfo bluetoothDevice = bluetoothDeviceInfo.Device; result = NativeMethods.BluetoothUpdateDeviceRecord(ref bluetoothDevice); NativeMethods.HandleError(result); if (bluetoothDevice.connected) { throw new NotImplementedException("The device is already connected."); } if (bluetoothDevice.remembered) { // Remove non-connected devices from MsBluetooth's device list. // This has to be done because: // MsBluetooth can't connect to Hid devices without also pairing to them. // If you think that sounds crazy, you're on the right track. NativeMethods.RemoveDevice(bluetoothDevice.address); } Guid hidGuid = BluetoothServices.HumanInterfaceDeviceServiceClass_UUID; result = NativeMethods.BluetoothSetServiceState(IntPtr.Zero, ref bluetoothDevice, ref hidGuid, 0x0001); NativeMethods.HandleError(result); if (WaitTillConnected(bluetoothDevice.address, TimeSpan.FromSeconds(30))) { Thread.Sleep(2000); ReportDevice device = null; foreach (KeyValuePair <string, SafeFileHandle> pair in MsHidDeviceProviderHelper.GetWiiDeviceHandles()) { string devicePath = pair.Key; SafeFileHandle fileHandle = pair.Value; Stream communicationStream = new MsHidSetOutputReportStream(fileHandle); // determine the device type if (bluetoothDeviceInfo.Name == "Nintendo RVL-WBC-01") { device = new ReportBalanceBoard(deviceInfo, communicationStream); } else if (bluetoothDeviceInfo.Name == "Nintendo RVL-CNT-01") { device = new ReportWiimote(deviceInfo, communicationStream); } else { throw new ArgumentException("The specified deviceInfo with name '" + bluetoothDeviceInfo.Name + "' is not supported.", "deviceInfo"); } if (MsHidDeviceProviderHelper.TryConnect(device, communicationStream, devicePath, fileHandle)) { break; } device = null; } if (device != null) { lookupFoundDevices.Remove(bluetoothDeviceInfo.Address); foundDevices.Remove(bluetoothDeviceInfo); OnDeviceLost(new DeviceInfoEventArgs(bluetoothDeviceInfo)); device.Disconnected += device_Disconnected; ConnectedDevices.Add(device); lookupConnectedDevices.Add(bluetoothDeviceInfo, device); OnDeviceConnected(new DeviceEventArgs(device)); return(device); } else { throw new DeviceConnectException("No working HID device found."); } } else { throw new TimeoutException("Timeout while trying to connect to the bluetooth device."); } }