Ejemplo n.º 1
0
        public async Task <bool> readRRSensor(TestMeViewModel b, int sec)
        {
            Activity activity = Droid.MainActivity.instance;

            _contactSensor.StartReadings();
            while (_bandState == null)
            {
            }                              //get the band state
            if (_bandState != BandContactState.Worn)
            {
                _bandState = null;
                //TODO: notify the user by sending a notification
                return(false);
            }
            _distancerSensor.StartReadings();
            while (currentMotionTyp == null)
            {
            }
            if (currentMotionTyp == MotionType.Walking || currentMotionTyp == MotionType.Jogging || currentMotionTyp == MotionType.Running)
            {
                b.StressResult = "Error: can't measure during sports activity";
                Log.Error("motion", "user is " + currentMotionTyp.ToString());
                return(false);
            }
            _rrIntervalsReadings.Clear();
            //RequestConsent();
            _rrSensor.StartReadings();
            await Task.Delay(sec * 1000);

            _rrSensor.StopReadings();
            _contactSensor.StopReadings();
            return(true);
        }
 /// <summary>
 /// 着用状態変更イベントハンドラ
 /// </summary>
 /// <param name="sender">イベント発行者</param>
 /// <param name="e">イベント引数</param>
 private void OnContactReadingChanged(object sender, BandSensorReadingEventArgs <IBandContactReading> e)
 {
     if (e == null)
     {
         return;
     }
     this.ContactState = e.SensorReading.State;
 }
Ejemplo n.º 3
0
        public async Task InitAsync()
        {
            _state = BandContactState.NotWorn;

            if (BandModel.IsConnected)
            {
                if (BandModel.BandClient.SensorManager.Contact.GetCurrentUserConsent() != UserConsent.Granted)
                {
                    await BandModel.BandClient.SensorManager.Contact.RequestUserConsentAsync();
                }
                BandModel.BandClient.SensorManager.Contact.ReadingChanged += Contact_ReadingChanged;
            }
        }
Ejemplo n.º 4
0
 async void Contact_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandContactReading> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         ContactSensorReading reading = new ContactSensorReading {
             Contact = e.SensorReading.State
         };
         if (Changed != null)
         {
             AppDebug.Line("Contact_ReadingChanged value<" + reading.Value.ToString() + ">");
             Changed(reading.Value);
             State = reading.Value;
         }
     });
 }
Ejemplo n.º 5
0
        public async Task <int> getHR(TestMeViewModel b)
        {
            await ConnectToBand(b);

            InitSensors(b);
            Activity activity = Droid.MainActivity.instance;

            _contactSensor.StartReadings();
            while (_bandState == null)
            {
            }
            if (_bandState != BandContactState.Worn)
            {
                _bandState = null;
                return(-1);
            }
            _hrSensor.StartReadings();
            return(0);
        }
Ejemplo n.º 6
0
        //assumes the band is connected
        public async Task <int> getGSR(TestMeViewModel b, int sec)
        {
            Activity activity = Droid.MainActivity.instance;

            _contactSensor.StartReadings();
            while (_bandState == null)
            {
            }
            if (_bandState != BandContactState.Worn)
            {
                _bandState = null;
                return(-1);
            }
            _gsrDone = false;
            _gsrReadings.Clear();
            b.GsrList = "#";

            _gsrSensor.StartReadings();
            await Task.Delay(sec * 1000);

            _gsrDone = true;
            _contactSensor.StopReadings();
            return(0);
        }
Ejemplo n.º 7
0
 public FakeBandDeviceContactReading(BandContactState bandContactState)
 {
     State = bandContactState;
 }
 public FakeBandDeviceContactReading(BandContactState bandContactState)
 {
     State = bandContactState;
 }
        async void Contact_ReadingChanged(object sender, BandSensorReadingEventArgs<IBandContactReading> e)
        {
            bandState = e.SensorReading.State;
            String text = "";
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (bandState == BandContactState.Worn)
                {
                    text = "Status: band connected";
                    lblBand.Text = text;
                    lblBand.Foreground = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    text = "Status: no contact";
                    lblBand.Text = text;
                    lblBand.Foreground = new SolidColorBrush(Colors.Yellow);

                    rectHeartGreen.Visibility = Visibility.Collapsed;
                    rectHeartGrey.Visibility = Visibility.Visible;
                    rectHeartRed.Visibility = Visibility.Collapsed;

                    rectTempGreen.Visibility = Visibility.Collapsed;
                    rectTempGrey.Visibility = Visibility.Visible;
                    rectTempRed.Visibility = Visibility.Collapsed;

                    lblHeart.Text = "-";
                    lblTemp.Text = "-";

                    return;
                }
            }).AsTask();



            if (bandState == BandContactState.Worn)
            {
                //only support 1 minute
                #region bandClient.SensorManager.SkinTemperature
                bandClient.SensorManager.SkinTemperature.ReadingChanged += SkinTemperature_ReadingChanged;
                
                if (bandClient.SensorManager.SkinTemperature.GetCurrentUserConsent() != UserConsent.Granted)
                {
                    // user has not consented, request it
                    await bandClient.SensorManager.SkinTemperature.RequestUserConsentAsync();
                }

                bandClient.SensorManager.SkinTemperature.StartReadingsAsync();

                #endregion

                #region bandClient.SensorManager.HeartRate
                bandClient.SensorManager.HeartRate.ReportingInterval = TimeSpan.FromSeconds(1);
                bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;

                if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted)
                {
                    // user has not consented, request it
                    await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
                }


                bandClient.SensorManager.HeartRate.StartReadingsAsync();


                #endregion
            }
            else
            {
                bandClient.SensorManager.SkinTemperature.ReadingChanged -= SkinTemperature_ReadingChanged;
                await bandClient.SensorManager.SkinTemperature.StopReadingsAsync();

                bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
                await bandClient.SensorManager.HeartRate.StopReadingsAsync();



            }
        }
 internal BandContactReading(BandContactState state)
 {
     State = state;
 }
Ejemplo n.º 11
0
        public void InitSensors(TestMeViewModel b)
        {
            if (!_client.IsConnected)
            {
                return;
            }
            _hrSensor        = _hrSensor ?? _client.SensorManager.CreateHeartRateSensor();
            _gsrSensor       = _gsrSensor ?? _client.SensorManager.CreateGsrSensor();
            _rrSensor        = _rrSensor ?? _client.SensorManager.CreateRRIntervalSensor();
            _contactSensor   = _contactSensor ?? _client.SensorManager.CreateContactSensor();
            _distancerSensor = _distancerSensor ?? _client.SensorManager.CreateDistanceSensor();

            if (_contactSensor == null || _hrSensor == null || _gsrSensor == null || _rrSensor == null || _distancerSensor == null)
            {
                return;
            }
            Activity activity = Droid.MainActivity.instance;

            //register contact listener
            _contactSensor.ReadingChanged += (sender, e) =>
            {
                var contactEvent = e.SensorReading;
                _bandState = contactEvent.ContactState;
            };
            //register heart rate listener
            _hrSensor.ReadingChanged += (sender, e) =>
            {
                activity.RunOnUiThread(() =>
                {
                    var heartRateEvent = e.SensorReading;
                    //_hrReadings.Add(heartRateEvent.HeartRate);
                    if (heartRateEvent.Quality == HeartRateQuality.Locked)
                    {
                        _hrSensor.StopReadings();
                        _contactSensor.StopReadings();
                        // if (b != null) { b.HR = _hrReadings[_hrReadings.Count - 1]; } //update ViewModel
                    }
                    if (_bandState != BandContactState.Worn) //user took off the band while reading
                    {
                        _hrSensor.StopReadings();
                        _contactSensor.StopReadings();
                        _bandState = null;
                        return;
                    }
                });
            };
            //register gsr listener
            _gsrSensor.ReadingChanged += (sender, e) =>
            {
                activity.RunOnUiThread(() =>
                {
                    var gsrEvent = e.SensorReading;
                    _gsrReadings.Add(gsrEvent.Resistance);
                    if (b != null)
                    {
                        b.GsrList = gsrEvent.Resistance.ToString();
                    }

                    if (_gsrDone)
                    {
                        _gsrSensor.StopReadings();
                        _contactSensor.StopReadings();
                        return;
                    }
                });
            };
            //register RR Intervals listener
            _rrSensor.ReadingChanged += (sender, e) =>
            {
                if (_bandState != BandContactState.Worn) //user took off the band while reading
                {
                    _rrSensor.StopReadings();
                    _contactSensor.StopReadings();
                    _bandState     = null;
                    b.StressResult = "Error: band is not worn.";
                    return;
                }
                var rrEvent = e.SensorReading;
                _rrIntervalsReadings.Add(rrEvent.Interval);
            };
            _distancerSensor.ReadingChanged += (sender, e) =>
            {
                currentMotionTyp = e.SensorReading.MotionType;
                _distancerSensor.StopReadings();
            };
        }
        /// <summary>
        /// センサー監視切替
        /// </summary>
        /// <param name="detecting">センサー監視フラグ</param>
        /// <returns>Task</returns>
        private async Task ChangeDetectSensors(bool detecting)
        {
            if (detecting)
            {
                // 加速度センサーの検知開始
                if (this.client.SensorManager.Accelerometer.IsSupported)
                {
                    await this.client.SensorManager.Accelerometer.StartReadingsAsync();

                    this.client.SensorManager.Accelerometer.ReadingChanged += this.OnAccelerometerReadingChanged;
                }
                // ジャイロセンサーの検知開始
                if (this.client.SensorManager.Gyroscope.IsSupported)
                {
                    await this.client.SensorManager.Gyroscope.StartReadingsAsync();

                    this.client.SensorManager.Gyroscope.ReadingChanged += this.OnGyroscopeReadingChanged;
                }
                // 心拍数の検知開始
                if (this.client.SensorManager.HeartRate.IsSupported)
                {
                    await this.client.SensorManager.HeartRate.StartReadingsAsync();

                    this.client.SensorManager.HeartRate.ReadingChanged += this.OnHeartRateReadingChanged;
                }
                // 歩数の検知開始
                if (this.client.SensorManager.Pedometer.IsSupported)
                {
                    await this.client.SensorManager.Pedometer.StartReadingsAsync();

                    this.client.SensorManager.Pedometer.ReadingChanged += this.OnPedometerReadingChanged;
                }
                // 移動距離の検知開始
                if (this.client.SensorManager.Distance.IsSupported)
                {
                    await this.client.SensorManager.Distance.StartReadingsAsync();

                    this.client.SensorManager.Distance.ReadingChanged += this.OnDistanceReadingChanged;
                }
                // 肌温度の検知開始
                if (this.client.SensorManager.SkinTemperature.IsSupported)
                {
                    await this.client.SensorManager.SkinTemperature.StartReadingsAsync();

                    this.client.SensorManager.SkinTemperature.ReadingChanged += this.OnSkinTemperatureReadingChanged;
                }
                // 紫外線レベルの検知開始
                if (this.client.SensorManager.UV.IsSupported)
                {
                    await this.client.SensorManager.UV.StartReadingsAsync();

                    this.client.SensorManager.UV.ReadingChanged += this.OnUltravioletReadingChanged;
                }
                // 着用状態の検知開始
                if (this.client.SensorManager.Contact.IsSupported)
                {
                    await this.client.SensorManager.Contact.StartReadingsAsync();

                    this.client.SensorManager.Contact.ReadingChanged += this.OnContactReadingChanged;
                }
            }
            else
            {
                // 加速度センサーの検知終了
                if (this.client.SensorManager.Accelerometer.IsSupported)
                {
                    await this.client.SensorManager.Accelerometer.StopReadingsAsync();

                    this.client.SensorManager.Accelerometer.ReadingChanged -= this.OnAccelerometerReadingChanged;
                    this.AccelerationX = 0d;
                    this.AccelerationY = 0d;
                    this.AccelerationZ = 0d;
                }
                // ジャイロセンサーの検知終了
                if (this.client.SensorManager.Gyroscope.IsSupported)
                {
                    await this.client.SensorManager.Gyroscope.StopReadingsAsync();

                    this.client.SensorManager.Gyroscope.ReadingChanged -= this.OnGyroscopeReadingChanged;
                    this.AngularVelocityX  = 0d;
                    this.AngularVelocityY  = 0d;
                    this.AngularVelocityZ  = 0d;
                    this.GyroAccelerationX = 0d;
                    this.GyroAccelerationY = 0d;
                    this.GyroAccelerationZ = 0d;
                }
                // 心拍数の検知終了
                if (this.client.SensorManager.HeartRate.IsSupported)
                {
                    await this.client.SensorManager.HeartRate.StopReadingsAsync();

                    this.client.SensorManager.HeartRate.ReadingChanged -= this.OnHeartRateReadingChanged;
                    this.HeartRate        = 0;
                    this.HeartRateQuality = HeartRateQuality.Acquiring;
                }
                // 歩数の検知終了
                if (this.client.SensorManager.Pedometer.IsSupported)
                {
                    await this.client.SensorManager.Pedometer.StopReadingsAsync();

                    this.client.SensorManager.Pedometer.ReadingChanged -= this.OnPedometerReadingChanged;
                    this.TotalSteps = 0L;
                }
                // 移動距離の検知終了
                if (this.client.SensorManager.Distance.IsSupported)
                {
                    await this.client.SensorManager.Distance.StopReadingsAsync();

                    this.client.SensorManager.Distance.ReadingChanged -= this.OnDistanceReadingChanged;
                    this.CurrentMotion = MotionType.Unknown;
                    this.Pace          = 0d;
                    this.Speed         = 0d;
                    this.TotalDistance = 0L;
                }
                // 肌温度の検知開始
                if (this.client.SensorManager.SkinTemperature.IsSupported)
                {
                    await this.client.SensorManager.SkinTemperature.StopReadingsAsync();

                    this.client.SensorManager.SkinTemperature.ReadingChanged -= this.OnSkinTemperatureReadingChanged;
                    this.SkinTemperature = 0d;
                }
                // 紫外線レベルの検知終了
                if (this.client.SensorManager.UV.IsSupported)
                {
                    await this.client.SensorManager.UV.StopReadingsAsync();

                    this.client.SensorManager.UV.ReadingChanged -= this.OnUltravioletReadingChanged;
                    this.ExposureLevel = UVIndexLevel.None;
                }
                // 着用状態の検知終了
                if (this.client.SensorManager.Contact.IsSupported)
                {
                    await this.client.SensorManager.Contact.StopReadingsAsync();

                    this.client.SensorManager.Contact.ReadingChanged -= this.OnContactReadingChanged;
                    this.ContactState = BandContactState.NotWorn;
                }
            }
        }