Exemplo n.º 1
0
        private async void AddBandSensor <T>(IBandSensor <T> sensor,
                                             string measurename,
                                             string unitofmeasure,
                                             EventHandler <BandSensorReadingEventArgs <T> > ValueChangedEventHandler) where T : IBandSensorReading
        {
            // check current user consent for accessing Band sensor
            if (sensor.GetCurrentUserConsent() != UserConsent.Granted)
            {
                // user hasn’t consented, request consent
                await sensor.RequestUserConsentAsync();

                if (sensor.GetCurrentUserConsent() != UserConsent.Granted)
                {
                    return;
                }
            }
            // User granted consent
            // Add Sensor to ConnectTheDots Helper
            CTD.AddSensor(measurename, unitofmeasure);

            // hook up to the Sensor ReadingChanged event
            IEnumerable <TimeSpan> supportedHeartRateReportingIntervals = sensor.SupportedReportingIntervals;

            sensor.ReportingInterval = supportedHeartRateReportingIntervals.First <TimeSpan>();
            sensor.ReadingChanged   += ValueChangedEventHandler;

            // start reading from the sensor
            await sensor.StartReadingsAsync();
        }
Exemplo n.º 2
0
        public async Task <IObservable <BandSensorReadingEventArgs <T> > > GetSensorStream <T>(IBandSensor <T> manager) where T : IBandSensorReading
        {
            var consent = manager.GetCurrentUserConsent();

            if (consent != UserConsent.Granted)
            {
                await manager.RequestUserConsentAsync();
            }

            var supportedIntervals = manager.SupportedReportingIntervals;

            manager.ReportingInterval = supportedIntervals.First();

            var stream = CreateObservableFromSensorEvent <T>(manager);

            return(stream);
        }
Exemplo n.º 3
0
        public static async Task SetupSensorReadingAsync <T>(IBandSensor <T> bandSensor,
                                                             EventHandler <BandSensorReadingEventArgs <T> > cb)
            where T : IBandSensorReading
        {
            var  uc          = bandSensor.GetCurrentUserConsent();
            bool isConsented = false;

            if (uc == UserConsent.NotSpecified)
            {
                isConsented = await bandSensor.RequestUserConsentAsync();
            }

            if (isConsented || uc == UserConsent.Granted)
            {
                bandSensor.ReadingChanged += cb;
                await bandSensor.StartReadingsAsync();
            }
        }
Exemplo n.º 4
0
        public async Task StartSensor <T>(IBandClient bandClient, IBandSensor <T> sensor,
                                          Action <BandSensorReadingEventArgs <T> > action) where T : IBandSensorReading
        {
            var  uc          = sensor.GetCurrentUserConsent();
            bool isConsented = false;

            if (uc == UserConsent.NotSpecified)
            {
                isConsented = await sensor.RequestUserConsentAsync();
            }

            if (isConsented || uc == UserConsent.Granted)
            {
                sensor.ReadingChanged += async(obj, ev) =>
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action(ev));
                };

                await sensor.StartReadingsAsync();
            }
        }
Exemplo n.º 5
0
        private async Task <bool> GetUserConsentAsync <T>(IBandSensor <T> sensor) where T : IBandSensorReading
        {
            bool granted = false;

            switch (sensor.GetCurrentUserConsent())
            {
            case UserConsent.NotSpecified:
                granted = await sensor.RequestUserConsentAsync();

                break;

            case UserConsent.Granted:
                granted = true;
                break;

            case UserConsent.Declined:
                granted = false;
                break;
            }

            return(granted);
        }
Exemplo n.º 6
0
        public async Task <int> SetupSensor <T>(IBandSensor <T> sensor, int timeout, int value) where T : IBandSensorReading
        {
            var bandClient = await TestUtils.GetBandClientAsync();

            var  uc          = sensor.GetCurrentUserConsent();
            bool isConsented = false;

            if (uc == UserConsent.NotSpecified)
            {
                isConsented = await sensor.RequestUserConsentAsync();
            }

            var tcs = new TaskCompletionSource <int>();

            if (isConsented || uc == UserConsent.Granted)
            {
                sensor.ReadingChanged += (obj, ev) =>
                {
                    // Set arbitrary result value
                    if (tcs.Task.Status != TaskStatus.RanToCompletion && tcs.Task.Status != TaskStatus.Faulted)
                    {
                        tcs.SetResult(5858);
                    }
                };
                await sensor.StartReadingsAsync();
            }

            try
            {
                await tcs.Task.TimeoutAfter(timeout);
            }
            finally
            {
                await sensor.StopReadingsAsync();
            }

            return(tcs.Task.Result);
        }
Exemplo n.º 7
0
        private async Task <IObservable <BandSensorReadingEventArgs <T> > > GetSensorStream <T>(IBandSensor <T> bandSensor)
            where T : IBandSensorReading
        {
            if (!this.IsConnected || !bandSensor.IsSupported)
            {
                return(null);
            }

            var consent = bandSensor.GetCurrentUserConsent();

            if (consent != UserConsent.Granted)
            {
                await bandSensor.RequestUserConsentAsync();
            }

            var supportedIntervals = bandSensor.SupportedReportingIntervals;

            bandSensor.ReportingInterval = supportedIntervals.First();

            var stream = CreateObservableFromSensorEvent(bandSensor);

            return(stream);
        }