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); }
private async void OnToggleSensorSection(object sender, CompoundButton.CheckedChangeEventArgs e) { if (!Model.Instance.Connected) { return; } EnsureSensorsCreated(); Switch sw = (Switch)sender; TableLayout table = mSensorMap[sw]; if (e.IsChecked) { table.Visibility = ViewStates.Visible; if (table == mTableAccelerometer) { mRadioGroupAccelerometer.Enabled = false; SetChildrenEnabled(mRadioGroupAccelerometer, false); } else if (table == mTableGyro) { mRadioGroupGyro.Enabled = false; SetChildrenEnabled(mRadioGroupGyro, false); } // Turn on the appropriate sensor try { if (sw == mSwitchAccelerometer) { SampleRate rate; if (mRadioAcc16.Checked) { rate = SampleRate.Ms16; } else if (mRadioAcc32.Checked) { rate = SampleRate.Ms32; } else { rate = SampleRate.Ms128; } mTextAccX.Text = ""; mTextAccY.Text = ""; mTextAccZ.Text = ""; accelerometerSensor.StartReadings(rate); } else if (sw == mSwitchGyro) { SampleRate rate; if (mRadioGyro16.Checked) { rate = SampleRate.Ms16; } else if (mRadioGyro32.Checked) { rate = SampleRate.Ms32; } else { rate = SampleRate.Ms128; } mTextGyroAccX.Text = ""; mTextGyroAccY.Text = ""; mTextGyroAccZ.Text = ""; mTextGyroAngX.Text = ""; mTextGyroAngY.Text = ""; mTextGyroAngZ.Text = ""; gyroscopeSensor.StartReadings(rate); } else if (sw == mSwitchDistance) { mTextTotalDistance.Text = ""; mTextSpeed.Text = ""; mTextPace.Text = ""; mTextPedometerMode.Text = ""; distanceSensor.StartReadings(); } else if (sw == mSwitchHeartRate) { var sensorMngr = Model.Instance.Client.SensorManager; if (await sensorMngr.RequestHeartRateConsentTaskAsync(Activity)) { mTextHeartRate.Text = ""; mTextHeartRateQuality.Text = ""; heartRateSensor.StartReadings(); } else { Util.ShowExceptionAlert(Activity, "Start heart rate sensor", new Exception("User declined permission.")); mSwitchHeartRate.Checked = false; } } else if (sw == mSwitchContact) { mTextContact.Text = ""; contactSensor.StartReadings(); } else if (sw == mSwitchSkinTemperature) { mTextSkinTemperature.Text = ""; skinTemperatureSensor.StartReadings(); } else if (sw == mSwitchUltraviolet) { mTextUltraviolet.Text = ""; uvSensor.StartReadings(); } else if (sw == mSwitchPedometer) { mTextTotalSteps.Text = ""; pedometerSensor.StartReadings(); } else if (sw == mSwitchAltimeter) { mTextFlightsAscended.Text = ""; mTextFlightsDescended.Text = ""; mTextRate.Text = ""; mTextSteppingGain.Text = ""; mTextSteppingLoss.Text = ""; mTextStepsAscended.Text = ""; mTextStepsDescended.Text = ""; mTextTotalGain.Text = ""; mTextTotalLoss.Text = ""; altimeterSensor.StartReadings(); } else if (sw == mSwitchAmbientLight) { mTextBrightness.Text = ""; ambientLightSensor.StartReadings(); } else if (sw == mSwitchBarometer) { mTextAirPressure.Text = ""; mTextTemperature.Text = ""; barometerSensor.StartReadings(); } else if (sw == mSwitchCalories) { mTextCalories.Text = ""; caloriesSensor.StartReadings(); } else if (sw == mSwitchGsr) { mTextResistance.Text = ""; gsrSensor.StartReadings(); } else if (sw == mSwitchRRInterval) { var sensorMngr = Model.Instance.Client.SensorManager; if (await sensorMngr.RequestHeartRateConsentTaskAsync(Activity)) { mTextInterval.Text = ""; rrIntervalSensor.StartReadings(); } else { Util.ShowExceptionAlert(Activity, "Start rr interval sensor", new Exception("User declined permission.")); mSwitchRRInterval.Checked = false; } } } catch (BandException ex) { Util.ShowExceptionAlert(Activity, "Register sensor listener", ex); } } else { table.Visibility = ViewStates.Gone; if (table == mTableAccelerometer) { mRadioGroupAccelerometer.Enabled = true; SetChildrenEnabled(mRadioGroupAccelerometer, true); } else if (table == mTableGyro) { mRadioGroupGyro.Enabled = true; SetChildrenEnabled(mRadioGroupGyro, true); } // Turn off the appropriate sensor try { if (sw == mSwitchAccelerometer) { accelerometerSensor.StopReadings(); } else if (sw == mSwitchGyro) { gyroscopeSensor.StopReadings(); } else if (sw == mSwitchDistance) { distanceSensor.StopReadings(); } else if (sw == mSwitchHeartRate) { heartRateSensor.StopReadings(); } else if (sw == mSwitchContact) { contactSensor.StopReadings(); } else if (sw == mSwitchSkinTemperature) { skinTemperatureSensor.StopReadings(); } else if (sw == mSwitchUltraviolet) { uvSensor.StopReadings(); } else if (sw == mSwitchPedometer) { pedometerSensor.StopReadings(); } else if (sw == mSwitchAltimeter) { altimeterSensor.StopReadings(); } else if (sw == mSwitchAmbientLight) { ambientLightSensor.StopReadings(); } else if (sw == mSwitchBarometer) { barometerSensor.StopReadings(); } else if (sw == mSwitchCalories) { caloriesSensor.StopReadings(); } else if (sw == mSwitchGsr) { gsrSensor.StopReadings(); } else if (sw == mSwitchRRInterval) { rrIntervalSensor.StopReadings(); } } catch (BandException ex) { Util.ShowExceptionAlert(Activity, "Unregister sensor listener", ex); } } }