示例#1
0
        public bool playPauseWorkout()
        {
            if (workoutCountDown > 0)
            {
                if (_countDownTimer.Enabled)
                {
                    _countDownTimer.Enabled = false;
                }
                else
                {
                    _countDownTimer.Enabled = true;
                }
                return(true);
            }
            if (workoutTime == null)
            {
                return(false);
            }
            if (workoutTime.ElapsedMilliseconds <= 0)
            {
                return(false);
            }

            if (!bIsPaused)
            {
                bIsPaused = true;
                workoutTime.Stop();
                if (null != workoutEventStartStop)
                {
                    workoutStatusArgs e = new workoutStatusArgs();
                    e.running = false;
                    workoutEventStartStop(this, e);
                }
                bIsRunning = false;
            }
            else
            {
                bIsPaused = false;
                workoutTime.Start();
                if (null != workoutEventStartStop)
                {
                    workoutStatusArgs e = new workoutStatusArgs();
                    e.running = true;
                    workoutEventStartStop(this, e);
                }
                bIsRunning = true;
            }
            return(true);
        }
示例#2
0
        void _countDownTimerElapsed(object sender, ElapsedEventArgs e)
        {
            workoutCountDown--;

            workoutEventArgs wEA = getDefaultEventData();

            if (workoutCountDown > 0)
            {
                wEA.message        = "Starting " + activeWorkout.title + " in " + workoutCountDown.ToString() + " Seconds";
                wEA.segmentTotalMS = activeWorkout.segments[0].length * 1000;
                wEA.workoutTotalMS = activeWorkout.length * 1000;
            }
            else
            {
                _countDownTimer.Stop();
                activeSegment      = 0;
                wEA.currentSegment = activeSegment;
                wEA.message        = "GGGGOOOOOO!!!";
                wEA.segmentTotalMS = activeWorkout.segments[0].length * 1000;
                wEA.workoutTotalMS = activeWorkout.length * 1000;

                workoutTime = new Stopwatch();
                workoutTime.Start();
                if (null != workoutEventStartStop)
                {
                    workoutStatusArgs wSA = new workoutStatusArgs();
                    wSA.running = true;
                    workoutEventStartStop(this, wSA);
                }
                bIsRunning            = true;
                _updateTimer          = new Timer(500);
                _updateTimer.Elapsed += new ElapsedEventHandler(_updateTimerElapsed);
                _updateTimer.Enabled  = true;
            }
            if (null != workoutEventHandler)
            {
                workoutEventHandler(this, wEA);
            }
        }
示例#3
0
 public void updateWorkoutEvent(object sender, workoutStatusArgs e)
 {
     if (b_hasVid)
     {
         if (e.running && !b_vidPlaying)
         {
             b_vidPlaying = true;
             this.Dispatcher.Invoke((Action)(() =>
             {
                 mediaElement1.Play();
             }));
         }
         else if (!e.running && b_vidPlaying)
         {
             b_vidPlaying = false;
             this.Dispatcher.Invoke((Action)(() =>
             {
                 mediaElement1.Pause();
             }));
         }
     }
 }
示例#4
0
        void _updateTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (workoutEventHandler == null)
            {
                return;
            }

            workOutSeconds = (int)(workoutTime.ElapsedMilliseconds / 1000);

            workoutEventArgs wEA = getDefaultEventData();

            if (workoutTime.ElapsedMilliseconds > msTimeForNextSegment &&
                workoutTime.ElapsedMilliseconds / 1000 < activeWorkout.length &&
                activeSegment < activeWorkout.segments.Count - 1)
            {
                //New Segment!!
                activeSegment++;
                msTimeForNextSegment += activeWorkout.segments[activeSegment].length * 1000;
                wEA.message           = activeWorkout.segments[activeSegment].segmentName;
            }
            if (workoutTime.ElapsedMilliseconds / 1000 < activeWorkout.length && !forceFinish)
            {
                long segTimeLeft = (msTimeForNextSegment - workoutTime.ElapsedMilliseconds);
                //active workout ... send a normal update
                if (segTimeLeft < 1000)
                {
                    wEA.message = "1s to Go!";
                }
                else if (segTimeLeft < 2000)
                {
                    wEA.message = "2s to Go!";
                }
                else if (segTimeLeft < 3000)
                {
                    wEA.message = "3s to Go!";
                }

                wEA.workoutCurrentMS = workoutTime.ElapsedMilliseconds;
                wEA.workoutTotalMS   = activeWorkout.length * 1000;
                wEA.segmentCurrentMS = activeWorkout.segments[activeSegment].length * 1000 - (msTimeForNextSegment - workoutTime.ElapsedMilliseconds);
                wEA.segmentTotalMS   = activeWorkout.segments[activeSegment].length * 1000;

                switch (activeWorkout.segments[activeSegment].type)
                {
                case "steady":
                    break;

                case "ramp":
                    wEA.alternateTarget = activeWorkout.segments[activeSegment].effort +
                                          ((double)wEA.segmentCurrentMS / wEA.segmentTotalMS) * (activeWorkout.segments[activeSegment].effortFinish - activeWorkout.segments[activeSegment].effort);
                    break;

                case "overunder":
                    long timeLeft = (msTimeForNextSegment - workoutTime.ElapsedMilliseconds) / 1000;
                    while (timeLeft > 0)
                    {
                        if (timeLeft <= activeWorkout.segments[activeSegment].overTime)
                        {
                            wEA.alternateTarget = activeWorkout.segments[activeSegment].effortFinish;
                            timeLeft            = 0;
                        }
                        else
                        {
                            timeLeft -= activeWorkout.segments[activeSegment].overTime;
                        }

                        if (timeLeft > 0 && timeLeft <= activeWorkout.segments[activeSegment].underTime)
                        {
                            wEA.alternateTarget = activeWorkout.segments[activeSegment].effort;
                            timeLeft            = 0;
                        }
                        else
                        {
                            timeLeft -= activeWorkout.segments[activeSegment].underTime;
                        }
                    }
                    break;

                default:
                    wEA.alternateTarget = 0;
                    break;
                }
            }
            else
            {
                // Workout is over!!
                if (!forceFinish)
                {
                    bIsFinished = true;
                }
                forceFinish = false;

                workoutTime.Stop();
                if (null != workoutEventStartStop)
                {
                    workoutStatusArgs wSA = new workoutStatusArgs();
                    wSA.running = false;
                    workoutEventStartStop(this, wSA);
                }

                bIsRunning   = false;
                wEA.message  = "Done!!!";
                wEA.finished = true;
                _updateTimer.Stop();
            }

            if (workoutEventHandler != null)
            {
                workoutEventHandler(this, wEA);
            }
        }