示例#1
0
文件: Converters.cs 项目: sorryb/UWP
        /// <summary>
        /// Factory that creates a StepCountData object from a Lumia StepCount
        /// </summary>
        /// <param name="stepCount"></param>
        /// <returns></returns>
        public static StepCountData FromLumiaStepCount(StepCount stepCount)
        {
            StepCountData steps = new StepCountData();

            steps.RunningCount = stepCount.RunningStepCount;
            steps.WalkingCount = stepCount.WalkingStepCount;
            steps.UnknownCount = 0;

            return(steps);
        }
示例#2
0
文件: Converters.cs 项目: sorryb/UWP
        /// <summary>
        /// Factory that creates a StepCountData object from PedometerReadings
        /// </summary>
        /// <param name="readings"></param>
        /// <returns></returns>
        public static StepCountData FromPedometerReadings(IReadOnlyList <PedometerReading> readings)
        {
            StepCountData steps = new StepCountData();

            // Get the most recent batch of 3 readings (one per StepKind)
            for (int i = 0; i < readings.Count && i < 3; i++)
            {
                var reading = readings[readings.Count - i - 1];
                switch (reading.StepKind)
                {
                case PedometerStepKind.Running:
                    steps.RunningCount = (uint)reading.CumulativeSteps;
                    break;

                case PedometerStepKind.Walking:
                    steps.WalkingCount = (uint)reading.CumulativeSteps;
                    break;

                case PedometerStepKind.Unknown:
                    steps.UnknownCount = (uint)reading.CumulativeSteps;
                    break;

                default:
                    break;
                }
            }

            // Subtract the counts from the earliest batch of 3 readings (one per StepKind)
            for (int i = 0; i < readings.Count && i < 3; i++)
            {
                var reading = readings[i];
                switch (reading.StepKind)
                {
                case PedometerStepKind.Running:
                    steps.RunningCount -= (uint)reading.CumulativeSteps;
                    break;

                case PedometerStepKind.Walking:
                    steps.WalkingCount -= (uint)reading.CumulativeSteps;
                    break;

                case PedometerStepKind.Unknown:
                    steps.UnknownCount -= (uint)reading.CumulativeSteps;
                    break;

                default:
                    break;
                }
            }

            return(steps);
        }
示例#3
0
        /// <summary>
        /// Factory that creates a StepCountData object from PedometerReadings
        /// </summary>
        /// <param name="readings"></param>
        /// <returns></returns>
        public static StepCountData FromPedometerReadings(IReadOnlyList<PedometerReading> readings)
        {
            StepCountData steps = new StepCountData();
            // Get the most recent batch of 3 readings (one per StepKind)
            for (int i = 0; i < readings.Count && i < 3; i++)
            {
                var reading = readings[readings.Count - i - 1];
                switch (reading.StepKind)
                {
                    case PedometerStepKind.Running:
                        steps.RunningCount = (uint)reading.CumulativeSteps;
                        break;
                    case PedometerStepKind.Walking:
                        steps.WalkingCount = (uint)reading.CumulativeSteps;
                        break;
                    case PedometerStepKind.Unknown:
                        steps.UnknownCount = (uint)reading.CumulativeSteps;
                        break;
                    default:
                        break;
                }
            }

            // Subtract the counts from the earliest batch of 3 readings (one per StepKind)
            for (int i = 0; i < readings.Count && i < 3; i++)
            {
                var reading = readings[i];
                switch (reading.StepKind)
                {
                    case PedometerStepKind.Running:
                        steps.RunningCount -= (uint)reading.CumulativeSteps;
                        break;
                    case PedometerStepKind.Walking:
                        steps.WalkingCount -= (uint)reading.CumulativeSteps;
                        break;
                    case PedometerStepKind.Unknown:
                        steps.UnknownCount -= (uint)reading.CumulativeSteps;
                        break;
                    default:
                        break;
                }
            }

            return steps;
        }
示例#4
0
        /// <summary>
        /// Factory that creates a StepCountData object from a Lumia StepCount
        /// </summary>
        /// <param name="stepCount"></param>
        /// <returns></returns>
        public static StepCountData FromLumiaStepCount(StepCount stepCount)
        {
            StepCountData steps = new StepCountData();

            steps.RunningCount = stepCount.RunningStepCount;
            steps.WalkingCount = stepCount.WalkingStepCount;
            steps.UnknownCount = 0;

            return steps;
        }
示例#5
0
文件: OEMTask.cs 项目: x01673/steps
        /// <summary>
        /// Gets number of steps for current day
        /// </summary>
        /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns>
        private async Task<bool> GetStepsAsync()
        {
            // First try the pedometer
            try
            {
                var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);
                _steps = StepCountData.FromPedometerReadings(readings);
                return true;
            }
            catch (Exception)
            {
                // Continue to the fallback
            }

            // Fall back to using Lumia Sensor Core.
            StepCounter stepCounter = null;
            try
            {
                stepCounter = await StepCounter.GetDefaultAsync();
                StepCount count = await stepCounter.GetStepCountForRangeAsync(
                    DateTime.Now.Date,
                    DateTime.Now - DateTime.Now.Date);
                _steps = StepCountData.FromLumiaStepCount(count);
            }
            catch (Exception e)
            {
                _lastError = SenseHelper.GetSenseError(e.HResult);
                return false;
            }
            finally
            {
                if (stepCounter != null)
                {
                    stepCounter.Dispose();
                }
            }
            return true;
        }