Beispiel #1
0
        private async void CheckCaloriesCycle()
        {
            var Calstream = await bandHelper.GetTotalCal();

            long currCal = await Calstream.FirstAsync();

            long diff = currCal - totalCal;

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                CaloriesDisplay.Text = " Calories: " + diff;

                await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + CaloriesDisplay.Text);
            }).AsTask();
        }
Beispiel #2
0
        private async void ManageBand(BandReativeExtensionsWrapper bandHelper)
        {
            bandHelper.SendMessage("Testing Messages");

            var streamHR = await bandHelper.GetHeartRateStream();

            var streamCal = await bandHelper.GetCaloriesStream();

            var streamSkin = await bandHelper.GetSkinTemperatureStream();

            var streamUV = await bandHelper.GetUltravioletStream();

            var streamPed = await bandHelper.GetPedometerStream();

            var streamAcce = await bandHelper.GetAccelerometerStream();

            var currCalstream = await bandHelper.GetTotalCal();

            totalCal = await currCalstream.FirstAsync();

            await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + "Ciclo de trabalho iniciado. Calorias desde o ultimo factory reset: " + totalCal);



            var hrSubscription = streamHR
                                 .Where(x => x.SensorReading.Quality == Microsoft.Band.Sensors.HeartRateQuality.Locked)
                                 .Buffer(new TimeSpan(0, 0, interv))
                                 .Select(async x =>
            {
                var avg = x.Average(y => y.SensorReading.HeartRate);
                var min = x.Min(y => y.SensorReading.HeartRate);
                var max = x.Max(y => y.SensorReading.HeartRate);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    HeartRateDisplay.Text = " HeartRate Med: " + Math.Round(avg, 2) + " Min: " + min + " Max: " + max;

                    await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandHRLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + HeartRateDisplay.Text);
                }).AsTask();
                return(avg);
            })
                                 .Subscribe(x =>
            {
                Debug.WriteLine(x);
                if (x.IsFaulted)
                {
                    btrange = true;
                }
            });



            //var calSubscription = streamCal
            //                .Where(x => x.SensorReading.Calories != 0)
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var value = x.Select(y => y.SensorReading.Calories);
            //                   long cal = value.Last() - totalCal;

            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       CaloriesDisplay.Text = "Calories: " + cal;

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandCalLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + CaloriesDisplay.Text);
            //                   }).AsTask();
            //                   return cal;
            //               })
            //               .Subscribe(x =>
            //               {

            //                   Debug.WriteLine(x);

            //               });

            var skinSubscription = streamSkin
                                   .Buffer(new TimeSpan(0, 0, interv))
                                   .Select(async x =>
            {
                var avg = x.Average(y => y.SensorReading.Temperature);
                var min = x.Min(y => y.SensorReading.Temperature);
                var max = x.Max(y => y.SensorReading.Temperature);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    SkinTemperatureDisplay.Text = " Temperature Med: " + Math.Round(avg, 2) + " Min: " + min + " Max: " + max;

                    await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandTemperatureLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + SkinTemperatureDisplay.Text);
                }).AsTask();
                return(avg);
            })
                                   .Subscribe(x =>
            {
                Debug.WriteLine(x);
            });

            //var pedSubscription = streamPed
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var total = x.Select(y => y.SensorReading.TotalSteps);
            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       PedometerDisplay.Text = "Steps: " + total;

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandStepsLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + PedometerDisplay.Text);
            //                   }).AsTask();
            //                   return total;
            //               })
            //               .Subscribe(x =>
            //               {
            //                   Debug.WriteLine(x);

            //               });

            //var uvSubscription = streamUV
            //               .Buffer(new TimeSpan(0, 0, interv))
            //               .Select(async x =>
            //               {
            //                   var index = x.Select(y => y.SensorReading.IndexLevel);
            //                   await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                   {
            //                       UVDisplay.Text = " UV: " + index.Last().ToString();

            //                       await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandUVLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + UVDisplay.Text);
            //                   }).AsTask();
            //                   return index;
            //               })
            //               .Subscribe(x =>
            //               {
            //                   Debug.WriteLine(x);

            //               });

            //var accSubscription = streamAcce
            //              .Buffer(new TimeSpan(0, 0, interv))
            //              .Select(async x =>
            //              {
            //                  var pointX = x.Select(y => y.SensorReading.AccelerationX);
            //                  var pointY = x.Select(y => y.SensorReading.AccelerationY);
            //                  var pointZ = x.Select(y => y.SensorReading.AccelerationZ);


            //                  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            //                  {
            //                      AcceDisplay.Text = "Point X: " + pointX + "  Point Y: " + pointY + "  PointZ: " + pointZ;

            //                      await c.saveStringToLocalFile(BandController.CurrentDateForFile() + "-BandAccellLogs.txt", "TimeStamp: " + BandController.GetUnixTimeStamp() + AcceDisplay.Text);
            //                  }).AsTask();
            //                  return pointX;
            //              })
            //              .Subscribe(x =>
            //              {
            //                  Debug.WriteLine(x);

            //              });
            //var streamAcc

            //if (_bandClient != null)
            //    return;

            //var bands = await BandClientManager.Instance.GetBandsAsync();
            //_bandInfo = bands.First();

            //_bandClient = await BandClientManager.Instance.ConnectAsync(_bandInfo);

            //var uc = _bandClient.SensorManager.HeartRate.GetCurrentUserConsent();
            //bool isConsented = false;
            //if (uc == UserConsent.NotSpecified)
            //{
            //    isConsented = await _bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
            //}

            //if (isConsented || uc == UserConsent.Granted)
            //{

            //    IEnumerable<TimeSpan> supportedHeartBeatReportingIntervals = _bandClient.SensorManager.HeartRate.SupportedReportingIntervals;
            //    foreach(var ri in supportedHeartBeatReportingIntervals)
            //    {

            //    }



            //    _bandClient.SensorManager.HeartRate.ReadingChanged += async (obj, ev) =>
            //    {
            //        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            //                            {
            //                                HeartRateDisplay.Text = ev.SensorReading.HeartRate.ToString();
            //                                HeartRateState.Text = ev.SensorReading.Quality.ToString();
            //                                //await c.saveStringToLocalFile("BandHRLogs.txt", "HeartRate: " + ev.SensorReading.HeartRate);
            //                            }).AsTask();
            //    };
            //    await _bandClient.SensorManager.HeartRate.StartReadingsAsync();
            //}
        }