public async void getCurrentReading(string options) { PluginResult result = new PluginResult(PluginResult.Status.OK); result.KeepCallback = true; try { PedometerReading reading = new PedometerReading(); if (!isReady) { DispatchCommandResult(new PluginResult(PluginResult.Status.OK, latestReading ?? reading)); return; } StepCounterReading current = await stepCounter.GetCurrentReadingAsync(); StepCounterReading today = await stepCounter.GetStepCountAtAsync(DateTimeOffset.Now.Date); if (null == current && null == today) { DispatchCommandResult(new PluginResult(PluginResult.Status.OK, latestReading ?? reading)); return; } if (null == today) { today = new StepCounterReading(0, TimeSpan.FromMilliseconds(0), 0, TimeSpan.FromMilliseconds(0), DateTimeOffset.Now.Date); } reading.todayWalkingSteps = Convert.ToInt32(current.WalkingStepCount - today.WalkingStepCount); reading.todayWalkingMinutes = Convert.ToInt32(current.WalkTime.TotalMinutes - today.WalkTime.TotalMinutes); reading.todayRunningSteps = Convert.ToInt32(current.RunningStepCount - today.RunningStepCount); reading.todayRunningMinutes = Convert.ToInt32(current.RunTime.TotalMinutes - today.RunTime.TotalMinutes); if (runStarted.HasValue) { StepCounterReading lastRun = await stepCounter.GetStepCountAtAsync(runStarted.Value); reading.lastRunSteps = Convert.ToInt32(current.WalkingStepCount - lastRun.WalkingStepCount); reading.lastRunMinutes = Convert.ToInt32(current.RunTime.TotalMinutes - lastRun.RunTime.TotalMinutes); } latestReading = reading; result.Message = JsonHelper.Serialize(reading); DispatchCommandResult(result); } catch (Exception ex) { result.Message = JsonHelper.Serialize(new { error = "getCurrentReading", message = ex.Message }); DispatchCommandResult(result); } }
/// <summary> /// Displays current step counter reading /// </summary> /// <returns>Asynchronous task</returns> private async Task ShowCurrentReading() { await CallSensorcoreApiAsync(async() => { // Get current reading from the sensor and display it in UI var reading = await _stepCounter.GetCurrentReadingAsync(); SensorcoreList.Items.Add("Current step counter reading"); if (reading != null) { SensorcoreList.Items.Add(reading.Timestamp.ToString()); SensorcoreList.Items.Add("Walk steps = " + reading.WalkingStepCount); SensorcoreList.Items.Add("Walk time = " + reading.WalkTime.ToString()); SensorcoreList.Items.Add("Run steps = " + reading.RunningStepCount); SensorcoreList.Items.Add("Run time = " + reading.RunTime.ToString()); } else { SensorcoreList.Items.Add("Data not available"); } }); }