public static MetaWearBoard getMetaWearBoardInstance(BluetoothLEDevice btleDevice) { MetaWearBoard board; if (!instances.TryGetValue(btleDevice.BluetoothAddress, out board)) { board = new MetaWearBoard(btleDevice); instances.Add(btleDevice.BluetoothAddress, board); } return(board); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var mwBoard = MetaWearBoard.getMetaWearBoardInstance(e.Parameter as BluetoothLEDevice); board = mwBoard.cppBoard; deviceSetupPage = this; triggered_gpio_already = false; this.gyroCheckbox.IsChecked = useGyro; this.accelCheckbox.IsChecked = useAccel; this.spillCheckbox.IsChecked = useSpill; }
/// <summary> /// Callback for the devices list which navigates to the <see cref="DeviceSetup"/> page with the selected device /// </summary> private void pairedDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { var selectedDevice = ((ListView)sender).SelectedItem as BluetoothLEDevice; if (selectedDevice != null) { initFlyout.ShowAt(pairedDevices); var board = MetaWearBoard.getMetaWearBoardInstance(selectedDevice); board.Initialize(new FnVoid(async() => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { initFlyout.Hide(); this.Frame.Navigate(typeof(DeviceSetup), selectedDevice); }); })); } }
private async Task <bool> retrieveBoard() { DeviceInformationCollection set = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector()); foreach (var devInfo in set) { try { Debug.WriteLine("device = " + devInfo.Name + ", " + devInfo.Pairing); if (devInfo.Name.Contains("MetaWear")) { BluetoothLEDevice selectedDevice = await BluetoothLEDevice.FromIdAsync(devInfo.Id); if (selectedDevice != null) { var newBoard = MetaWearBoard.getMetaWearBoardInstance(selectedDevice); var initResult = await newBoard.Initialize(); if (initResult == 0) { board = newBoard.cppBoard; return(true); } } else { Debug.WriteLine("windows is confused; found a BLE device-info (" + devInfo.Name + ") but could not find it"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return(false); }