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); } }
private async Task UpdateStepsAsync() { if (_stepCounter != null) { StepCounterReading reading = null; bool res = await CallSensorCoreApiAsync(async() => { reading = await _stepCounter.GetCurrentReadingAsync(); }); if (reading != null && res) { _mainModel.StepsToday = reading.WalkingStepCount + reading.RunningStepCount - _firstRunningSteps - _firstWalkingSteps; _mainModel.WalkingSteps = reading.WalkingStepCount - _firstWalkingSteps; _mainModel.RunningSteps = reading.RunningStepCount - _firstRunningSteps; } } }
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); } }