Пример #1
0
        /// <summary>
        /// Populates the device list and initializes all the various models.
        ///
        /// Waiting for the async calls to complete takes a while, so we want to call this
        /// function somewhat sparingly.
        /// </summary>
        /// <returns></returns>
        public static async Task PopulateDeviceListAsync()
        {
            // Remove all devices and start from scratch
            PairedDevices.Clear();

            // Asynchronously get all paired/connected bluetooth devices.
            var infoCollection = await DeviceInformation.FindAllAsync(BluetoothLeDevice.GetDeviceSelector());

            // Re-add devices
            foreach (var info in infoCollection)
            {
                // Make sure we don't initialize duplicates
                if (PairedDevices.FindIndex(device => device.DeviceId == info.Id) >= 0)
                {
                    continue;
                }
                var wrtDevice = await BluetoothLeDevice.FromIdAsync(info.Id);

                var deviceM = new BeDeviceModel();
                deviceM.Initialize(wrtDevice, info);
                PairedDevices.Add(deviceM);
            }

            /*
             * FUTURE
             *
             * Consider reading one characteristic from each device uncached to trigger a connection to the
             * device, in case the device does not have notifiable characteristics.
             *
             * Also consider registering for DeviceConnectionChangeTrigger, in case a device does not have
             * notifiable characteristics.  But that may be overkill - what's the likelihood that a device
             * won't have notifiable characteristics?
             *
             */
        }
Пример #2
0
        /// <summary> 
        /// Populates the device list and initializes all the various models.
        /// 
        /// Waiting for the async calls to complete takes a while, so we want to call this
        /// function somewhat sparingly.
        /// </summary>
        /// <returns></returns>
        public static async Task PopulateDeviceListAsync()
        {
            // Remove all devices and start from scratch
            PairedDevices.Clear();

            // Asynchronously get all paired/connected bluetooth devices. 
            var infoCollection = await DeviceInformation.FindAllAsync(BluetoothLeDevice.GetDeviceSelector());

            // Re-add devices
            foreach (var info in infoCollection)
            {
                // Make sure we don't initialize duplicates
                if (PairedDevices.FindIndex(device => device.DeviceId == info.Id) >= 0)
                {
                    continue;
                }
                var wrtDevice = await BluetoothLeDevice.FromIdAsync(info.Id);
                var deviceM = new BeDeviceModel();
                deviceM.Initialize(wrtDevice, info);
                PairedDevices.Add(deviceM);
            }

            /*
             * FUTURE
             * 
             * Consider reading one characteristic from each device uncached to trigger a connection to the
             * device, in case the device does not have notifiable characteristics.
             * 
             * Also consider registering for DeviceConnectionChangeTrigger, in case a device does not have
             * notifiable characteristics.  But that may be overkill - what's the likelihood that a device
             * won't have notifiable characteristics?
             *
             */
        }
Пример #3
0
 public void Initialize(BeDeviceModel deviceM)
 {
     Model   = deviceM;
     DeviceM = deviceM;
     DeviceM.Register(this);
 }