Exemple #1
0
        public BtHrpBundle()
        {
            logger.Debug("Retrieving heart rate capable devices");

            var task = DeviceInformation.FindAllAsync(
                GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate),
                new string[] { "System.Devices.ContainerId" });

            try
            {
                while (true)
                {
                    logger.Debug("Attempting to retrieve async result...");

                    Thread.Sleep(100);

                    var status = task.Status;

                    if (status == Windows.Foundation.AsyncStatus.Canceled || task.Status == Windows.Foundation.AsyncStatus.Error)
                    {
                        break;
                    }

                    if (status == Windows.Foundation.AsyncStatus.Completed)
                    {
                        BtSmartDevices = task.GetResults();
                        break;
                    }
                }
            }
            finally
            {
                task.Close();
            }

            logger.Debug($"Found {BtSmartDevices.Count} heart rate capable deices");
            foreach (DeviceInformation device in BtSmartDevices.ToList())
            {
                logger.Debug($"{device.Name}: " +
                             $"id = {device.Id}, " +
                             $"default = {device.IsDefault}, " +
                             $"enabled = {device.IsEnabled},  " +
                             $"paired = {device.Pairing.IsPaired}");
            }

            if (BtSmartDevices.Count > 0)
            {
                btHrp.Device = BtSmartDevices[0];
            }

            btHrpFrm = new BtHrpFrm(this);
        }
Exemple #2
0
        public BtHrpBundle()
        {
            var task = DeviceInformation.FindAllAsync(
                GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate),
                new string[] { "System.Devices.ContainerId" });

            try
            {
                while (true)
                {
                    Thread.Sleep(100);

                    var status = task.Status;

                    if (status == Windows.Foundation.AsyncStatus.Canceled || task.Status == Windows.Foundation.AsyncStatus.Error)
                    {
                        break;
                    }

                    if (status == Windows.Foundation.AsyncStatus.Completed)
                    {
                        BtSmartDevices = task.GetResults();
                        break;
                    }
                }
            }
            finally
            {
                task.Close();
            }

            if (BtSmartDevices.Count > 0)
            {
                btHrp.Device = BtSmartDevices[0];
            }

            btHrpFrm = new BtHrpFrm(this);
        }