Ejemplo n.º 1
0
        private void HeartRate_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandHeartRateReading> e)
        {
            IBandHeartRateReading heartRateRead = e.SensorReading;

            data.heartRate  = heartRateRead.HeartRate;
            HeartRateLocked = heartRateRead.Quality;
        }
        public async void GetHeartRate()
        {
            IEnumerable <TimeSpan> supportedHeartBeatReportingIntervals = bandClient.SensorManager.HeartRate.SupportedReportingIntervals;

            bandClient.SensorManager.HeartRate.ReportingInterval = supportedHeartBeatReportingIntervals.First <TimeSpan>();

            // hook up to the HeartRate sensor ReadingChanged event
            bandClient.SensorManager.HeartRate.ReadingChanged += async(sender, args) =>
            {
                heartreading = args.SensorReading;
                await heartrate_value.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                {
                    heartrate_value.Text = heartreading.HeartRate.ToString();
                });
            };

            try
            {
                await bandClient.SensorManager.HeartRate.StartReadingsAsync();
            }
            catch (BandException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public BandHeartRateSensorReadingChangedEventArgs(IBandHeartRateReading sensorReading)
        {
            if (sensorReading == null)
            {
                throw new ArgumentNullException("sensorReading");
            }

            this.SensorReading = sensorReading;
        }
        private async void HeartRate_ReadingChanged(object sender, Microsoft.Band.Sensors.BandSensorReadingEventArgs <Microsoft.Band.Sensors.IBandHeartRateReading> e)
        {
            var span = (DateTime.Now - start).TotalSeconds;
            IBandHeartRateReading reading = e.SensorReading;
            string text = string.Format("Heartrate = {0}\nQuality = {1}\nTime Stamp = {2}\nTime Span = {3}\n", reading.HeartRate, reading.Quality, reading.Timestamp, span);
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.sensorTextBlock.Text = text; }).AsTask();

            start = DateTime.Now;

            lock (hrLock)
            {
                heartRate = reading.HeartRate;
            }
        }
        public static async Task SendAccelerometerReading(IBandHeartRateReading reading)
        {
            try
            {
                var sas = "";

                // Namespace info.
                var serviceNamespace = "codecamphub2-ns";
                var hubName          = "codecamphub2";
                var deviceName       = "band1";

                // Create client.
                var httpClient = new HttpClient
                {
                    BaseAddress = new Uri(string.Format("https://{0}.servicebus.windows.net/", serviceNamespace))
                };

                var payload = JsonConvert.SerializeObject(reading);

                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", sas);

                var content = new StringContent(payload, Encoding.UTF8, "application/json");
                content.Headers.Add("ContentType", "application/atom+xml;type=entry;charset=utf-8");

                var url = string.Format("{0}/publishers/{1}/messages", hubName, deviceName);

                var postResult = await httpClient.PostAsync(url, content);

                var resultContent = postResult.Content.ToString();
                var resultStatus  = (int)postResult.StatusCode;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error sending telemetry to event hubs: " + ex.ToString());
            }
        }
Ejemplo n.º 6
0
        private async void ButtonRun_Click(object sender, RoutedEventArgs e)
        {
            if (IsRunning)
            {
                return;
            }
            else
            {
                IsRunning = true;
            }

            try
            {
                this.ButtonRun.IsEnabled = false;
                this.StatusMessage.Text  = "";

                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.StatusMessage.Text = "Connect To Microsoft Band Please";
                    return;
                }

                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted)
                    {
                        await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
                    }

                    int samplesReceivedHR = 0; // the number of HeartRate samples received
                    int samplesReceivedST = 0; // the number of SkinTemperature samples received
                    int samplesReceivedUV = 0; // the number of UV samples received


                    // Subscribe to HeartRate data.
                    bandClient.SensorManager.HeartRate.ReadingChanged += (s, args) =>
                    {
                        samplesReceivedHR++;
                        IBandHeartRateReading readings = args.SensorReading;
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.txtHR.Text = readings.HeartRate.ToString() + " [" + readings.Quality.ToString() + "]";
                        });
                    };
                    await bandClient.SensorManager.HeartRate.StartReadingsAsync();



                    // Subscribe to SkinTemperature data.
                    bandClient.SensorManager.SkinTemperature.ReadingChanged += (s, args) =>
                    {
                        samplesReceivedST++;
                        IBandSkinTemperatureReading readings = args.SensorReading;
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.txtSkinTemp.Text = readings.Temperature.ToString();
                        });
                    };
                    await bandClient.SensorManager.SkinTemperature.StartReadingsAsync();

                    // Subscribe to UV data.
                    bandClient.SensorManager.UV.ReadingChanged += (s, args) =>
                    {
                        samplesReceivedUV++;
                        IBandUVReading readings = args.SensorReading;
                        CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.txtUV.Text = readings.IndexLevel.ToString();
                        });
                    };
                    await bandClient.SensorManager.UV.StartReadingsAsync();

                    // Receive sensor data for a while
                    await Task.Delay(TimeSpan.FromSeconds(10));

                    // Stop the sensor subscriptions
                    await bandClient.SensorManager.Accelerometer.StopReadingsAsync();

                    await bandClient.SensorManager.Calories.StopReadingsAsync();

                    await bandClient.SensorManager.Contact.StopReadingsAsync();

                    await bandClient.SensorManager.Distance.StopReadingsAsync();

                    await bandClient.SensorManager.Gyroscope.StopReadingsAsync();

                    await bandClient.SensorManager.HeartRate.StopReadingsAsync();

                    await bandClient.SensorManager.Pedometer.StopReadingsAsync();

                    await bandClient.SensorManager.SkinTemperature.StopReadingsAsync();

                    await bandClient.SensorManager.UV.StopReadingsAsync();

                    this.StatusMessage.Text = string.Format("Done.\n {0} HeartRate samples received.\n {1} SkinTemperature samples received.\n {2} UV samples received.", samplesReceivedHR, samplesReceivedST, samplesReceivedUV);
                }
            }
            catch (Exception ex)
            {
                this.StatusMessage.Text = ex.ToString();
            }
            IsRunning = false;
            this.ButtonRun.IsEnabled = true;
        }
Ejemplo n.º 7
0
 private async void SendHeartRate(IBandHeartRateReading reading)
 {
     await EventHubsInterface.SendAccelerometerReading(reading);
 }
 private async void HeartRate_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandHeartRateReading> e)
 {
     IBandHeartRateReading heartRateReading = e.SensorReading;
     string text = string.Format("HR: {0}bpm", heartRateReading.HeartRate);
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.heartRate.Text = text; }).AsTask();
 }
        public async void GetHr(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.warnings.Text = "This sample app requires a Microsoft Band paired to your phone. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    // normally wouldn't do it this way obviously
                    bandClientCopy = bandClient;

                    tilesRemaining = await bandClient.TileManager.GetRemainingTileCapacityAsync();

                    if (tilesRemaining > 0)
                    {
                        Guid     myTileId = new Guid(tileId);
                        BandTile myTile   = new BandTile(myTileId)
                        {
                            Name             = "My Tile",
                            IsBadgingEnabled = true,
                            TileIcon         = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                            SmallIcon        = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                        };
                        //await bandClient.TileManager.AddTileAsync(myTile);
                    }
                    IEnumerable <TimeSpan> supportedHeartBeatReportingIntervals = bandClient.SensorManager.HeartRate.SupportedReportingIntervals;
                    //foreach (var ri in supportedHeartBeatReportingIntervals)
                    //{
                    //   Debug.WriteLine(ri.ToString());
                    //}
                    bandClient.SensorManager.HeartRate.ReportingInterval = supportedHeartBeatReportingIntervals.First <TimeSpan>();

                    await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();

                    bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
                    bandClient.SensorManager.HeartRate.ReadingChanged += async(senderino, args) =>
                    {
                        heartReading = args.SensorReading;
                        await warnings.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            this.warnings.Text = heartReading.HeartRate.ToString();
                        });
                    };
                    try
                    {
                        await bandClient.SensorManager.HeartRate.StartReadingsAsync();
                    }
                    catch (BandException ex)
                    {
                        throw ex;
                    }
                    await Task.Delay(TimeSpan.FromMinutes(1));

                    await bandClient.SensorManager.HeartRate.StopReadingsAsync();
                }
            }
            catch (Exception ex)
            {
                this.warnings.Text = ex.ToString();
            }
        }
Ejemplo n.º 10
0
 public static HeartRateReading FromBandSensor(IBandHeartRateReading reading)
 {
     return new HeartRateReading
     {
         HeartRate = reading.HeartRate,
         Quality = reading.Quality,
         Timestamp = reading.Timestamp
     };
 }
        public async void GetHeartRate()
        {
            IEnumerable<TimeSpan> supportedHeartBeatReportingIntervals = bandClient.SensorManager.HeartRate.SupportedReportingIntervals;
            bandClient.SensorManager.HeartRate.ReportingInterval = supportedHeartBeatReportingIntervals.First<TimeSpan>();

            // hook up to the HeartRate sensor ReadingChanged event
            bandClient.SensorManager.HeartRate.ReadingChanged += async (sender, args) =>
            {
                heartreading = args.SensorReading;
                await heartrate_value.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                {
                    heartrate_value.Text = heartreading.HeartRate.ToString();
                });
            };

            try
            {
                await bandClient.SensorManager.HeartRate.StartReadingsAsync();
            }
            catch (BandException ex)
            {
                throw ex;
            }


        }
Ejemplo n.º 12
0
 string FormatHeartRate(IBandHeartRateReading reading) =>
 $"Rate:{reading.HeartRate}, Quality:{reading.Quality}";