Beispiel #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _defferal = taskInstance.GetDeferral();

            if (await band.ConnectAsync())
            {
                await band.HeartRate.SubscribeToHeartRateNotificationsAsync();

                /*
                 * // You will receive heart rate measurements from the band
                 * await band.HeartRate.SubscribeToHeartRateNotificationsAsync((sender, args) =>
                 * {
                 *  int currentHeartRate = args.CharacteristicValue.ToArray()[1];
                 *  System.Diagnostics.Debug.WriteLine($"Current heartrate from background task is {currentHeartRate} bpm ");
                 * });
                 */
            }
        }
        async void StartReadProc()
        {
            if (await band.ConnectAsync() && band.Identity.IsAuthenticated())
            {
                Debug.WriteLine($"{await band.Device.GetDeviceName()} connected -----------------------");

                // You will receive heart rate measurements from the band
                await band.HeartRate.SubscribeToHeartRateNotificationsAsync(async (sender, args) => {
                    int currentHeartRate = args.CharacteristicValue.ToArray()[1];
                    Debug.WriteLine($"Current heartrate from background task is {currentHeartRate} bpm ");

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                        Windows.UI.Core.CoreDispatcherPriority.High, () => {
                        Home.GetCurrent().AddLog($"BPM: {currentHeartRate}", Models.AppLog.LogCategory.Info);
                    });
                });
            }
        }
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     btnConn.IsEnabled = false;
     band = new MiBand2SDK.MiBand2();
     // Check if already authentified
     if (band.IsConnected())
     {
         txtStat.Text = "Connected";
     }
     else
     {
         // Trying to connect to band and authenticate first time.
         // While authentication process started, you need to touch you band, when you see the message.
         if (await band.ConnectAsync() && await band.Identity.AuthenticateAsync())
         {
             txtStat.Text = "Connected";
         }
         else//didnt connect :(
         {
             btnConn.IsEnabled = true;
         }
     }
 }