/// <summary> /// Class constructor. Instantiates a new <c>RelayConsolePageViewModel</c> object with the /// given Bluetooth device. /// </summary> /// <param name="device">Bluetooth device.</param> public RelayConsolePageViewModel(BleDevice device) { BleDevice = device; ReceivedMessages = new ObservableCollection <string>(); ClearLogCommand = new Command(ClearLog); }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } BleDevice dev = (BleDevice)obj; return(Id == dev.Id); }
public SendRelayMessagePage(BleDevice bleDevice) { this.bleDevice = bleDevice; InitializeComponent(); // Initialize the interface picker. interfacePicker.ItemsSource = new List <XBeeLocalInterface> { XBeeLocalInterface.SERIAL, XBeeLocalInterface.MICROPYTHON, XBeeLocalInterface.BLUETOOTH }; interfacePicker.SelectedIndex = 0; }
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 RelayConsolePage(BleDevice device) { InitializeComponent(); relayConsolePageViewModel = new RelayConsolePageViewModel(device); BindingContext = relayConsolePageViewModel; // 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")) { relayConsolePageViewModel.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."); }); }; }