Exemplo n.º 1
0
        /// <summary>
        ///     Begins the scanning for bluetooth LE devices. Automatically called after 10 seconds
        ///     to prevent battery drain.
        /// </summary>
        /// <returns>The scanning for devices.</returns>
        public async Task BeginScanningForDevices()
        {
            Mvx.Trace("BluetoothLEManager: Starting a scan for devices.");

            ConnectedDevices  = new List <CBPeripheral>();
            DiscoveredDevices = new List <CBPeripheral>();

            // start scanning
            IsScanning = true;
#if __UNIFIED__
            CentralBleManager.ScanForPeripherals(peripheralUuids: null);
#else
            _central.ScanForPeripherals(serviceUuids: null);
#endif

            // in 10 seconds, stop the scan
            await Task.Delay(10000).ConfigureAwait(false);

            // if we're still scanning
            if (IsScanning)
            {
                Mvx.Trace("BluetoothLEManager: Scan timeout has elapsed.");
                CentralBleManager.StopScan();
                ScanTimeoutElapsed(this, new EventArgs());
            }
        }
Exemplo n.º 2
0
 // ToDo: rename to DisconnectDevice
 public void DisconnectPeripheral(CBPeripheral peripheral)
 {
     CentralBleManager.CancelPeripheralConnection(peripheral);
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Stops the Central Bluetooth Manager from scanning for more devices. Automatically
 ///     called after 10 seconds to prevent battery drain.
 /// </summary>
 public void StopScanningForDevices()
 {
     Mvx.Trace("BluetoothLEManager: Stopping the scan for devices.");
     IsScanning = false;
     CentralBleManager.StopScan();
 }