private async void Button_Click(object sender, RoutedEventArgs e)
{
this.viewModel.StatusMessage = "Running ...";
try
{
// Get the list of Microsoft Bands paired to the phone.
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
{
this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
return;
}
// Connect to Microsoft Band.
using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
if (!bandClient.SensorManager.Altimeter.IsSupported)
{
this.viewModel.StatusMessage = "Altimeter sensor is not supported with your Band version. Microsoft Band 2 is required.";
return;
}
int samplesReceived = 0; // the number of Altimeter samples received
// Subscribe to Altimeter data.
bandClient.SensorManager.Altimeter.ReadingChanged += (s, args) => { samplesReceived++; };
await bandClient.SensorManager.Altimeter.StartReadingsAsync();
// Receive Altimeter data for a while, then stop the subscription.
await Task.Delay(TimeSpan.FromSeconds(5));
await bandClient.SensorManager.Altimeter.StopReadingsAsync();
this.viewModel.StatusMessage = string.Format("Done. {0} Altimeter samples were received.", samplesReceived);
}
}
catch (Exception ex)
{
this.viewModel.StatusMessage = ex.ToString();
}
}
}