Ejemplo n.º 1
0
        /// <summary>
        /// Adds the steps.
        /// </summary>
        /// <param name="count">The count.</param>
        public void AddSteps(Int64 count)
        {
            //if service rebooted or rebound then this will null out to 0, but count will still be since last boot.
            if (_LastSteps == 0)
            {
                _LastSteps = count;
            }

            //calculate new steps
            _NewSteps = count - _LastSteps;

            //ensure we are never negative
            //if so, no worries as we are about to re-set the lastSteps to the
            //current count
            if (_NewSteps < 0)
            {
                _NewSteps = 1;
            }
            else if (_NewSteps > 100)
            {
                _NewSteps = 1;
            }

            _LastSteps = count;

            //save total steps!
            if (_IsOnTrail)
            {
                _StepsToday += _NewSteps;
                MessagingCenter.Send <IStepCounter, int>(this, "StepCount", (int)_StepsToday);
                MessagingCenter.Send <IStepCounter, double>(this, "Distance", StaticHelpers.ConvertStepsToMiles((int)_StepsToday));
            }

            Console.WriteLine("New step detected by STEP_COUNTER sensor. Total step count: " + _StepsToday);
#if DEBUG
            Android.Util.Log.Debug("STEPSERVICE", "New steps: " + _NewSteps + " total: " + _StepsToday);
#endif
        }