public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } BleDevice dev = (BleDevice)obj; return(Id == dev.Id); }
public void OnItemSelected(object sender, SelectedItemChangedEventArgs e) { BleDevice selectedDevice = e.SelectedItem as BleDevice; // Clear selection. ((ListView)sender).SelectedItem = null; if (selectedDevice == null) { return; } mainPageViewModel.StopScan(); mainPageViewModel.SelectedDevice = selectedDevice; mainPageViewModel.AskForPassword(false); }
public ConfigurationPage(BleDevice device) { InitializeComponent(); configurationPageViewModel = new ConfigurationPageViewModel(device); BindingContext = configurationPageViewModel; // Initialize the AP values picker. List <string> apValues = new List <string> { "0 Transparent Mode", "1 API Mode Without Escapes", "2 API Mode With Escapes", "3 N/A", "4 MicroPython REPL", "5 Bypass Mode" }; apPicker.ItemsSource = apValues; // Initialize the D9 values picker. List <string> d9Values = new List <string> { "0 Disabled", "1 Awake/Asleep Indicator", "2 N/A", "3 Digital Input", "4 Digital Output, Low", "5 Digital Output, High" }; d9Picker.ItemsSource = d9Values; // Register the back button action. if (EnableBackButtonOverride) { CustomBackButtonAction = async() => { // Ask the user if wants to close the connection. if (await DisplayAlert("Disconnect device", "Do you want to disconnect the XBee device?", "Yes", "No")) { configurationPageViewModel.DisconnectDevice(); } }; } }
/// <summary> /// Class constructor. Instantiates a new <c>MainPageViewModel</c> object. /// </summary> public MainPageViewModel() { devices = new ObservableCollection <BleDevice>(); // Initialize Bluetooth stuff. adapter = CrossBluetoothLE.Current.Adapter; // Subscribe to device advertisements. adapter.DeviceAdvertised += (object sender, DeviceEventArgs e) => { BleDevice advertisedDevice = new BleDevice(e.Device); // If the device is not discovered, add it to the list. if (!Devices.Contains(advertisedDevice)) { Devices.Add(advertisedDevice); } }; // Subscribe to device connection lost. adapter.DeviceConnectionLost += (object sender, DeviceErrorEventArgs e) => { if (SelectedDevice == null || CrossBluetoothLE.Current.State != BluetoothState.On) { return; } // Close the connection with the device. SelectedDevice.XBeeDevice.Close(); // Return to main page and prompt the disconnection error. Device.BeginInvokeOnMainThread(async() => { await Application.Current.MainPage.Navigation.PopToRootAsync(); ShowErrorDialog("Device disconnected", "Bluetooth connection lost with the device."); }); }; }
/// <summary> /// Class constructor. Instantiates a new <c>ConfigurationPageViewModel</c> object with the /// given Bluetooth device. /// </summary> /// <param name="device">Bluetooth device.</param> public ConfigurationPageViewModel(BleDevice device) { BleDevice = device; }