Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            BleDevice dev = (BleDevice)obj;

            return(Id == dev.Id);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public SendFilePage(BleDevice device)
        {
            InitializeComponent();
            sendFilePageViewModel = new SendFilePageViewModel(device);
            BindingContext        = sendFilePageViewModel;

            // 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"))
                    {
                        sendFilePageViewModel.DisconnectDevice();
                    }
                };
            }
        }
Ejemplo n.º 4
0
        /// <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.");
                });
            };
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Class constructor. Instantiates a new <c>SendFilePageViewModel</c> object with the
 /// given Bluetooth device.
 /// </summary>
 /// <param name="device">Bluetooth device.</param>
 public SendFilePageViewModel(BleDevice device)
 {
     BleDevice = device;
 }