Beispiel #1
0
            protected override Java.Lang.Void RunInBackground(params WeakReference<Activity>[] @params)
            {
                
                Activity param1;
                @params[0].TryGetTarget(out param1); //to replace params[0].get() as it was in Java
                ConsentListener param2 = new ConsentListener(o_);

                try
                {
                    if (o_.getConnectedBandClient()) {
                        if (param1 != null) {
                            o_.client.SensorManager.RequestHeartRateConsent(param1, param2); 
                        }
                    } else {
                        o_.appendToUI("Band isn't connected. Please make sure bluetooth is on and the band is in range.\n");
                        o_.setVisibility(true);
                    }
                } catch (BandException e) {
                    string exceptionMessage = "Band Exception: Either Microsoft Health BandService is not available or \n" +
                        "Microsoft Health BandService doesn't support your SDK Version. Please update to latest SDK\n"
                        + e.Message.ToString();
                    o_.appendToUI(exceptionMessage);
                
                    }
                    catch (System.Exception e) {
                        o_.appendToUI(e.Message.ToString());
                    }
                    return null;
            } //end of RunInBackground
Beispiel #2
0
 protected override Java.Lang.Void RunInBackground(params Java.Lang.Void[] @params)
 {
     try
     {
         if (o_.getConnectedBandClient())
         {
             if (o_.client.SensorManager.CurrentHeartRateConsent == UserConsent.Granted)
             {
                 o_.client.SensorManager.RegisterHeartRateEventListener(o_.mHeartRateEventListener);
                 o_.setVisibility(false); 
             }
         }
     } catch (System.Exception e) {
         o_.appendToUI(e.Message.ToString());
     }
         return null;
 }
Beispiel #3
0
            public void OnBandHeartRateChanged(IBandHeartRateEvent p0)
            {
                try {                                   
                    System.Diagnostics.Debug.WriteLine("#########################################");
                    System.Diagnostics.Debug.WriteLine(p0.HeartRate.ToString() + " Band quality Status: " + p0.Quality);
                    int x = p0.HeartRate;
                    if (o_.cloud_stats_recieved && o_.variance != none && o_.avg != none && o_.total_n != none)
                    {
                        if (o_.ArrayHeartRate.Count == NumberOfSamplesPerEntry) //we got enough samples to send to cloud:
                        {   
                            string date_hr = DateTime.Now.ToString(dateFormat_hr); //get date for RowKey
                            string date_day = DateTime.Now.ToString(dateFormat_day); //get date for PartitionKey 
                            new AddBandReading().Execute(current_user, string.Join(",",  o_.ArrayHeartRate.ToArray()), date_day, date_hr, storageConnectionString); //send data to cloud table
                            new AddBandReading().Execute(current_user, o_.variance.ToString(), Variance, Variance, storageConnectionString); //send data to cloud table
                            new AddBandReading().Execute(current_user, o_.avg.ToString(), Average, Average, storageConnectionString); //send data to cloud table
                            new AddBandReading().Execute(current_user, o_.total_n.ToString(), Total_count, Total_count, storageConnectionString); //send data to cloud table
                            o_.ArrayHeartRate.Clear();
                        }

                        if (p0.Quality == HeartRateQuality.Locked)
                        {   //we let the application learn about the user for 1000 "good" band observations before notifying about abnormal bpm
                            if (o_.total_n > 1000)  
                                NotificationHandler.CheckAndCreateNotification(o_.BaseContext, o_, x);
                            o_.ArrayHeartRate.Add(x);
                            o_.variance = o_.Welford_Variance(x, o_.avg, o_.total_n, o_.variance);
                            o_.avg = o_.Welford_Avg(x, o_.avg, o_.total_n);
                            o_.total_n += 1;
                            System.Diagnostics.Debug.WriteLine("variance = " + o_.variance.ToString() + " avg= "+ o_.avg);
                            o_.UpdateChart(x);
                        }
                        else
                        {
                            o_.appendToUI("Band not locked on Heart Rate, try to stay still");    
                        }
                    }
                }
                catch (System.Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("HeartRateEventListener ->  OnBandHeartRateChanged exception:/n" + e.Message);
                }
            }